Fix spring Boot using Redistemplate storage key value garbled \xac\xed\x00\x05t\x00

Source: Internet
Author: User

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?
    1. 127.0.0.1:6379 > Keys *
    2. 1) "\xac\xed\x00\x05t\x00\x04pass"
    3. 2) "\xac\xed\x00\x05t\x00\x04name"
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.