|
@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
import redis.clients.jedis.JedisPool;
|
|
|
import redis.clients.jedis.JedisPoolConfig;
|
|
|
|
|
|
/**
|
|
|
* Created by Trick on 2017/8/7.
|
|
@ -19,7 +21,7 @@ public class RedisThread implements Runnable {
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(RedisThread.class);
|
|
|
@Value("${channel.redis.host}")
|
|
|
private String url;
|
|
|
private String host;
|
|
|
@Value("${channel.redis.port}")
|
|
|
private Integer port;
|
|
|
@Value("${channel.redis.password}")
|
|
@ -33,12 +35,20 @@ public class RedisThread implements Runnable {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
String key = SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title");
|
|
|
Jedis jedis = new Jedis(url,port);
|
|
|
if(StringUtils.isNotBlank(password)){
|
|
|
jedis.auth(password);
|
|
|
}
|
|
|
|
|
|
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
|
|
poolConfig.setMaxIdle(8);
|
|
|
poolConfig.setMaxTotal(8);
|
|
|
poolConfig.setMaxWaitMillis(-1);
|
|
|
poolConfig.setMinIdle(1);
|
|
|
JedisPool pool = new JedisPool(poolConfig,host,port,100000);
|
|
|
|
|
|
while (true){
|
|
|
try {
|
|
|
Jedis jedis = pool.getResource();
|
|
|
if(StringUtils.isNotBlank(password)){
|
|
|
jedis.auth(password);
|
|
|
}
|
|
|
String message = jedis.rpop(key);
|
|
|
if(StringUtils.isEmpty(message)){
|
|
|
Thread.sleep(1000L);//如果没有读取到记录,等待1秒
|