Redis6 Java 使用Jedis

基本操作:
在這裏插入圖片描述

事務操作:
在這裏插入圖片描述

在進行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);
		}
	}
	
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章