package com.hzlq.fax.util;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* 单服务缓存redis工具类(需要额外jar包jedis)
*
* @author sj
* @date 2012-10-16 16:11:02
* @version 1.0
*/
public class RedisSingletonPool {
private static String ip = Configuration.readConfigString("SINGLETONIP",
"redis_config");
private static int port = Integer.parseInt(Configuration.readConfigString(
"SINGLETONPORT", "redis_config"));
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"));
}
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* 单服务缓存redis工具类(需要额外jar包jedis)
*
* @author sj
* @date 2012-10-16 16:11:02
* @version 1.0
*/
public class RedisSingletonPool {
private static String ip = Configuration.readConfigString("SINGLETONIP",
"redis_config");
private static int port = Integer.parseInt(Configuration.readConfigString(
"SINGLETONPORT", "redis_config"));
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"));
}
}
要添加jedis-2.0.0.jar包
在写这个工具类的时候 抛出了:
The constructor JedisPool(GenericObjectPool$Config, String, int) refers to the missing type GenericObjectPool$Config
查找原因之后 原来是没有添加:commons-pool-1.5.5.jar包