Spring Data Redis(Serializers)

Serializers
序列化转换器

From the framework perspective, the data stored in Redis is just bytes. While Redis itself supports various types, for the most part these refer to the way the data is stored rather than what it represents. It is up to the user to decide whether the information gets translated into Strings or any other objects. The conversion between the user (custom) types and raw data (and vice-versa) is handled in Spring Data Redis through the RedisSerializer interface (package org.springframework.data.redis.serializer) which as the name implies, takes care of the serialization process. Multiple implementations are available out of the box, two of which have been already mentioned before in this documentation: the StringRedisSerializer and the JdkSerializationRedisSerializer. However one can use OxmSerializer for Object/XML mapping through Spring 3 OXM support or either JacksonJsonRedisSerializer, Jackson2JsonRedisSerializer or GenericJackson2JsonRedisSerializer for storing data in JSON format. Do note that the storage format is not limited only to values - it can be used for keys, values or hashes without any restrictions.

从架构层面来看,在Redis中存储的数据是字节类型的。然而Redis它自己支持多种数据类型,在大多数情况下这涉及到数据存储的方式而不是展现的方式。由用户来决定是要转换为Strings还是其他对象objects。用户类型和原生数据类型之间的转换,需要通过Spring Data Redis 的RedisSerializer(包目录位于org.springframework.data.redis.serializer) 接口来实现。该接口关心的是转换的处理过程。多数实现都是有效的,拿来就可以用的;其中的两个在前面的文章中已经提到了:StringRedisSerializer 和 JdkSerializationRedisSerializer。然而还可以使用Spring 3 OXM支持的OxmSerializer 来进行Object与XML转换;也可以使用JacksonJsonRedisSerializer、Jackson2JsonRedisSerializer 或者GenericJackson2JsonRedisSerializer来存储JSON数据类型。注意,存储的类型格式不是只能适用于values,也可以适用于keys、values或者hashes等,其实是没有任何限制的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值