jedis 调用redis工具类
package com.atguigu.redis.test; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; 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, "10.0.5.233", 6379, 3000, "redis"); } } } return jedisPool; } public static void release(JedisPool jedisPool, Jedis jedis) { if (null != jedis) { jedisPool.returnResourceObject(jedis); } } public static void main(String[] args) { JedisPool jedisPool = JedisPoolUtil.getJedisPoolInstance(); Jedis jedis = null; try { jedis = jedisPool.getResource(); jedis.set("aa", "bb"); System.out.println(jedis.get("aa")); } catch (Exception e) { e.printStackTrace(); } finally { JedisPoolUtil.release(jedisPool, jedis); } } }
jar包支持:
jedis-2.1.0.jar
commons-pool-1.6.jar
相关推荐
txj 2020-08-17
亦碎流年 2020-06-18
middleware0 2020-06-13
anglehearts 2020-04-03
camhan 2020-05-09
枫叶上的雨露 2020-05-04
zhangtianshun 2020-05-03
博了个客 2020-04-29
sunzxh 2020-04-22
八角塘塘主 2020-04-09
GavinZhera 2020-04-08
郭宇 2020-02-22
Cheetahcubs 2020-02-12
middleware0 2020-02-11
wangxiaoxue 2020-01-23
guweiyuthinker 2020-01-20
MLXY 2020-01-21