gpt4 book ai didi

java - Spring Jedis 获取键列表返回空

转载 作者:可可西里 更新时间:2023-11-01 11:23:54 24 4
gpt4 key购买 nike

我正在尝试从 Redis 获取 key 列表,但它不起作用。

    @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);
}

最佳答案

添加 key 序列化程序。

template.setKeySerializer(new StringRedisSerializer());

关于java - Spring Jedis 获取键列表返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54461219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com