The problem of garbled Spring-data-redis interface call

Source: Internet
Author: User
Tags redis serialization set set

The first figure, the use of the Redistemplate interface to call the data to find the result is empty, this is strange, the data written in the visual software to find out is this:

Classpathxmlapplicationcontext classpathxmlapplicationcontext = new Classpathxmlapplicationcontext ("classpath*: Applicationcontext-redis2.xml ");
Redistemplate = (redistemplate) classpathxmlapplicationcontext.getbean ("Redistemplate");
public void Testgeopos () {
    zsetoperations<string, string> zsetoperations = Redistemplate.opsforzset ();
    Set set = Zsetoperations.range ("Beijing", 0,zsetoperations.size ("Beijing"));
    System.out.print (Set.tostring ());   zsetoperations.add ("Beijing", "hehe", 1);

    geooperations<string, string> geooperations = Redistemplate.opsforgeo ();


    list<point> list = Redistemplate.opsforgeo (). Geopos ("Beijing", "Dongcheng");
    System.out.println (List.tostring ());

}
Use the terminal login to find that the data is really created, but the name of the front more garbled


The solution, Baidu later found that the data transmitted through the network must be serialized after the use of the reason can be Baidu, there are two ways to solve:

1, in the code will be redistemplate serialization;

2. The spring schema can configure serialization in XML.

Redistemplate.setkeyserializer (Stringserializer);
Redistemplate.setvalueserializer (Stringserializer);
Redistemplate.sethashkeyserializer (Stringserializer);
Redistemplate.sethashvalueserializer (Stringserializer);

<bean id= "Redistemplate" name= "Redistemplate" class= "Org.springframework.data.redis.core.RedisTemplate" >
        <property name= "ConnectionFactory" ref= "redisconnectionfactory"/> <property name=
        "KeySerializer" "ref=" Stringredisserializer "/>
        <property name=
        " ValueSerializer "ref=" Stringredisserializer "/>" <property name= "Hashkeyserializer" ref= "Stringredisserializer"/> <property name=
        "HashValueSerializer" "ref=" Jackson2jsonredisserializer "/>
        <!--<property name=" Enabletransactionsupport "value=" true "/ >-->
    </bean>
<bean id= "Stringredisserializer"
        class= "Org.springframework.data.redis.serializer.StringRedisSerializer" />

You can read it correctly after you modify it.



Related Article

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.