我有以下代码片段来测试是否可以在Redis中添加HLL值,该测试通过了,但是当我从redis命令行验证它时,我没有看到“ HLLTEST”键,而是发现了奇怪的键您可以从以下输出中看到。 HyperLogLogOperations的使用是否有问题,
@Test
public void whenHllRecord_thenCount() throws Exception {
hyperLogLogOperations = redisTemplate.opsForHyperLogLog();
hyperLogLogOperations.add("HLLTEST:1010", 1);
hyperLogLogOperations.add("HLLTEST:1010",2);
long size = hyperLogLogOperations.size("HLLTEST:1010");
assertEquals("Size: "+size, size, 2);
}
Redis命令行
redis:6379> keys *
1) "\xac\xed\x00\x05t\x00\x0cHLLTEST:1010"
redis:6379> pfcount HLLTEST:1010
(integer) 0
RedisConf
@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
}
答案 0 :(得分:0)
我忘记了密钥序列化器。将其设置为如下操作之后,
@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
//template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
return template;
}