jedis操作redis

it2022-05-07  3

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

 

转载于:https://www.cnblogs.com/heqiyoujing/p/9362504.html


最新回复(0)