when I recently used Spring-data-redis redistemplate to operate Redis, I found that the key stored in Redis is not a string value set, and there are many more strings like \xac\xed\x00\x05t\x00 in front of it. , as follows
[HTML]View PlainCopyPrint?
- 127.0.0.1:6379 > Keys *
- 1) "\xac\xed\x00\x05t\x00\x04pass"
- 2) "\xac\xed\x00\x05t\x00\x04name"
- 3) "Name"
127.0.0.1:6379> keys) "\xac\xed\x00\x05t\x00\x04pass" 2) "\xac\xed\x00\x05t\x00\x04name" 3) "name"
Spring-data-redis redistemplate<k, the V> template class uses Jdkserializationredisserializer to serialize by default when working with Redis, as follows
True
Jdkserializationredisserializer ();
Null
Null
Null
Null
Workaround
PrivateRedistemplateredistemplate;
@Autowired(Required=false)
Public voidsetredistemplate(Redistemplate redistemplate) {
RedisserializerStringserializer =NewStringredisserializer ();
Redistemplate.setkeyserializer (Stringserializer);
Redistemplate.setvalueserializer (Stringserializer);
Redistemplate.sethashkeyserializer (Stringserializer);
Redistemplate.sethashvalueserializer (Stringserializer);
This.redistemplate= Redistemplate;
}
Fix spring Boot using Redistemplate storage key value garbled \xac\xed\x00\x05t\x00