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 " +   This.serializer.getClass