源代码:
redisTemplate.opsForValue().set("int_key", "1");
stringRedisTemplate.opsForValue().set("int", "1");
//+1运算
stringRedisTemplate.opsForValue().increment("int");
//-1运算,stringRedisTemplate耐不活
//所以,通过StringRedisTemplate获取底层Jedis连接
Jedis jedis = (Jedis) stringRedisTemplate.
getConnectionFactory().
getConnection().
getNativeConnection();
//-1运算
jedis.decr("int");
Map hash = new HashMap<>();
hash.put("file1","value1");
hash.put("file2","value2");
stringRedisTemplate.opsForHash().putAll("hash",hash);
BoundHashOperations hashOps =
stringRedisTemplate.boundHashOps("hash");
hashOps.delete("file1","file2");
hashOps.put("file4","value5");
Map map = new HashMap<>();
map.put("success",true);
return map;
重点就是出错在:
//-1运算,stringRedisTemplate耐不活
//所以,通过StringRedisTemplate获取底层Jedis连接
Jedis jedis = (Jedis) stringRedisTemplate.
getConnectionFactory().
getConnection().
getNativeConnection();
因为springboot2.x中默认使用了Lettuce集成了Redis服务,
所以spring-boot-starter-data-redis中默认只引入了Lettuce,而没有引入Jedis
所以需要我们在pom文件中手动引入**Jedis**,并且去除redis中的Lettuce
pom:
org.springframework.boot spring-boot-starter-data-redis io.lettuce lettuce-core org.springframework.boot spring-boot-starter-test test redis.clients jedis



