Spring jedis 获取密钥列表 return 为空
Spring jedis get key list return empty
我正在尝试从 Redis 获取密钥列表,但它不起作用。
@Autowired
org.springframework.data.redis.core.RedisTemplate redisTemplate;
redisTemplate.opsForValue().set("test","test");
redisTemplate.opsForValue().set("t:test","test");
redisTemplate.opsForValue().set("t::test1","test");
redisTemplate.opsForValue().set("t1.t2::test2","test");
Set<String> keys = redisTemplate.keys("t*");
我尝试了键“*”、"t:*"、"t::*" 的不同模式。什么都不管用。
只有当我写完整的键名时它才有效。
正在创建 bean 代码:
@Bean
RedisTemplate<String,Object> redisTemplate(@Autowired JedisConnectionFactory jedisConnectionFactory){
RedisTemplate<String,Object> template=new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory);
return template;
}
@Bean
JedisConnectionFactory jedisConnectionFactory(@Value("${redis.host:192.168.99.100}") String host, @Value("${redis.port:6379}") int port, @Value("${redis.password:}") String password){
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(host, port);
redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
return new JedisConnectionFactory(redisStandaloneConfiguration);
}
添加密钥序列化程序。
template.setKeySerializer(new StringRedisSerializer());
我正在尝试从 Redis 获取密钥列表,但它不起作用。
@Autowired
org.springframework.data.redis.core.RedisTemplate redisTemplate;
redisTemplate.opsForValue().set("test","test");
redisTemplate.opsForValue().set("t:test","test");
redisTemplate.opsForValue().set("t::test1","test");
redisTemplate.opsForValue().set("t1.t2::test2","test");
Set<String> keys = redisTemplate.keys("t*");
我尝试了键“*”、"t:*"、"t::*" 的不同模式。什么都不管用。 只有当我写完整的键名时它才有效。
正在创建 bean 代码:
@Bean
RedisTemplate<String,Object> redisTemplate(@Autowired JedisConnectionFactory jedisConnectionFactory){
RedisTemplate<String,Object> template=new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory);
return template;
}
@Bean
JedisConnectionFactory jedisConnectionFactory(@Value("${redis.host:192.168.99.100}") String host, @Value("${redis.port:6379}") int port, @Value("${redis.password:}") String password){
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(host, port);
redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
return new JedisConnectionFactory(redisStandaloneConfiguration);
}
添加密钥序列化程序。
template.setKeySerializer(new StringRedisSerializer());