import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* 单服务缓存redis工具类(需要额外jar包jedis)
*/
public class RedisSingletonPool {
private static String ip = ConfigUtil.readConfigForObject("SINGLETONIP", String.class);
private static int port = ConfigUtil.readConfigForObject("SINGLETONPORT", Integer.class);
private static JedisPool jedispool = null;
/**
* 获取redis连接池
*
* @return
*/
public static JedisPool get_jedispool() {
if (jedispool == null) {
JedisPoolConfig jedispool_config = new JedisPoolConfig();
//最大活动对象个数
jedispool_config.setMaxActive(500);
//对象最大空闲时间
jedispool_config.setMaxIdle(10);
//获取对象时最大等待时间
jedispool_config.setMaxWait(3000L);
jedispool_config.setTestOnBorrow(true);
jedispool = new JedisPool(jedispool_config, ip, port);
}
return jedispool;
}
public static void main(String[] args) {
Jedis redis = (Jedis) get_jedispool().getResource();
System.out.println(redis.get("123"));
}
}
单服务缓存redis工具类
最新推荐文章于 2024-02-03 10:53:13 发布