When Spring data operates Redis, it finds that the key value appears \XAC\XED\X00\X05T\X00\TB

Source: Internet
Author: User
Tags hash object object redis

Recent research into Redis, and spring data support for Redis, has found a strange phenomenon

First say the phenomenon, through the redistemplate under the Opsforhash method to store the value of the hash type, after the successful operation, to the Redis console to display the keys *, found a strange phenomenon, the inserted hash type of key in front of a bunch of \xac\ XED\X00\X05T\X00\TB This kind of thing, see figure 1


(Fig. 1)

Did you see it. is the second line that a string of things they come out of, analysis Spring-data org.springframework.data.redis.core.RedisTemplate source code later found:

[Java] view plain copy private redisserializer<?> Defaultserializer = new      Jdkserializationredisserializer ();   Private Redisserializer Keyserializer = null;   Private Redisserializer ValueSerializer = null;   Private Redisserializer Hashkeyserializer = null;   Private Redisserializer Hashvalueserializer = null; Private redisserializer<string> Stringserializer = new Stringredisserializer ();

Found a:

[Java] view plain copy private redisserializer<?> Defaultserializer = new Jdkserializationredisserializer ();

 because spring operations Redis is based on the Jedis client, while the Jedis client interacts with Redis when the protocol defines a byte type to interact with, Jedis provides the type of the string type to byte[]. But see Spring-data-redis in Redistemplate<k, v> in the operation of the time k,v is generic, so redistemplate in the above code, in the absence of a special definition of the case, Spring uses defaultserializer = new Jdkserializationredisserializer () by default, to serialize the Key,value, In a series of operations that have been serialized in the view Jdkserializationredisserializer, the following code is found: 

[Java] view plain copy private converter<object, byte[]> serializer = new Serializingconverter ();       Public byte[] Serialize (Object object) {if (object = = null) {return serializationutils.empty_array;       } try {return Serializer.convert (object);       } catch (Exception ex) {throw new SerializationException ("Cannot serialize", ex); }   }

Serialization supports object objects, calls the Convert method under the Serializingconverter class, and transforms the object by:

[Java]   View plain copy private final serializer<object> serializer;  /**   * serializes the source object and returns the byte array  result.   */   Public byte[] convert (object source)  {       bytearrayoutputstream bytestream = new bytearrayoutputstream (128);        try  {            this.serializer.serialize (source, bytestream);            return bytestream.tobytearray ();       }        catch  (Throwable ex)  {            Throw new serializationfailedexception ("failed to serialize object using "  + &nbsp                  This.serializer.getClass

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.