jedis操作redis

jedis操作redis

  使用jedis操作redis:

  定义变量:

1   public static JedisPool jedisPool;

  初始化redis: 

 1 public void init(){
 2         JedisPoolConfig jedisConfig = new JedisPoolConfig();
 3         jedisConfig.setMaxTotal(5000);
 4         jedisConfig.setMaxIdle(256);
 5         jedisConfig.setMaxWaitMillis(5000L);
 6         jedisConfig.setTestOnBorrow(false);
 7         jedisConfig.setMinIdle(6);
 8         jedisConfig.setTestWhileIdle(true);
 9         jedisConfig.setTimeBetweenEvictionRunsMillis(60000);
10         jedisConfig.setNumTestsPerEvictionRun(3);
11         jedisPool = new JedisPool(jedisConfig, "localhost", 6379, 15000, "123456");
12     }

  项目中使用:

  

1  public String call(){
2         Jedis jedis = MyApplication.jedisPool.getResource();
3         jedis.set("dddd", "yi");
4         String msg = "";
5         if(jedis.get("dddd") != null ){
6             msg = jedis.get("dddd");
7         }
8         return msg;
9     }

  结果:

  yi

 

posted @ 2018-07-24 20:47  何其小静  阅读(146)  评论(0编辑  收藏  举报