基本操作:
事務操作:
在進行Redis 操作的時候還可能會出現一個問題,內存的速度太快導致,幾次運行結果不出來,或者和你的修改不一致,注意:這不是錯誤只是內存的執行太快,還沒有到緩存中。
在使用的時候首先要想到連接池,不要頻繁的new 連接
單例線程安全寫法:(大概looklook…)
public class JedisPoolUtil
{
private static volatile JedisPool jedisPool = null;
private JedisPoolUtil(){}
public static JedisPool getJedisPoolInstance()
{
if(null == jedisPool)
{
synchronized (JedisPoolUtil.class)
{
if(null == jedisPool)
{
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxActive(1000);
poolConfig.setMaxIdle(32);
poolConfig.setMaxWait(100*1000);
poolConfig.setTestOnBorrow(true);
jedisPool = new JedisPool(poolConfig,"127.0.0.1",6379);
}
}
}
return jedisPool;
}
public static void release(JedisPool jedisPool,Jedis jedis)
{
if(null != jedis)
{
jedisPool.returnResourceObject(jedis);
}
}
}