Resolving spring Boot uses redistemplate to store key values to appear garbled \xac\xed\x00\x05t\x00__spring

Source: Internet
Author: User
The most recent use of the Spring-data-redis redistemplate operation Redis found that the key stored in Redis is not a string value set, and there are many more similar \xac\xed\x00\x05t\x00 strings in front of it , as follows
127.0.0.1:6379> keys *
1) "\xac\xed\x00\x05t\x00\x04pass"
2) "\xac\xed\x00\x05t\x00\x04name"
3) " Name

Spring-data-redis redistemplate<k, the V> template class is serialized by default using Jdkserializationredisserializer when manipulating Redis, as follows

Private Boolean Enabledefaultserializer = true;
Private redisserializer<?> Defaultserializer = new Jdkserializationredisserializer ();
Private Redisserializer Keyserializer = null;
Private Redisserializer ValueSerializer = null;
Private Redisserializer Hashkeyserializer = null;
Private Redisserializer Hashvalueserializer = null;

Solving method
Private Redistemplate redistemplate;

@Autowired (required = false) public
void Setredistemplate (Redistemplate redistemplate) {
    Redisserializer Stringserializer = new Stringredisserializer ();
    Redistemplate.setkeyserializer (Stringserializer);
    Redistemplate.setvalueserializer (Stringserializer);
    Redistemplate.sethashkeyserializer (Stringserializer);
    Redistemplate.sethashvalueserializer (Stringserializer);
    This.redistemplate = redistemplate;
}

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.