Redis序列化以额外的字符串为前缀

编程入门 行业动态 更新时间:2024-10-28 18:36:19
本文介绍了Redis序列化以额外的字符串为前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Camel-Redis的序列化程序在消息密钥的前面加上了额外的字符.

Camel-Redis's serializer is prefixing extra characters to message key.

当我检查数据库时,消息键显示类似..

When I checked the DB, the message key shows something like..

"\xac\xed\x00\x05t\x00\x11test150827171118"

如您所见,字符串"\xac\xed\x00\x05t\x00\x11"

是键"test150827171118"的前缀.

我尝试了两种模式,

首先,我直接在注册表中设置序列化器.

Firstly, I set the serializer in the registry directly.

Registry.put("serializer", new StringRedisSerializer());

第二种模式是通过首先在RedisTemplate中进行设置.然后将redis模板放入注册表中.

Second pattern is by setting in the RedisTemplate first. Then putting the redis template in the registry.

RedisTemplate<?, ?> template = new RedisTemplate<>(); template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(new StringRedisSerializer()); registry.put("redisTemplate", template);

两者都无法解决序列化问题.我是否缺少骆驼-redis的其他配置.

Both cannot solve the problem of serizlization. Am I missing additional configuration for camel-redis.

推荐答案

经过五到六个小时的搜索并在我的开发机上实现,我终于找到了答案.

I finally found the answer after five or six hours of googling and implementing on my development machine.

骆驼serializer URI选项仅适用于CONSUMER. 为了影响PRODUCER,我还需要使用StringRedisSerializer作为默认序列化程序来配置自定义RedisTemplate.

Camel serializer URI options is only for CONSUMER. To affect PRODUCER, I also need to configure a custom RedisTemplate with StringRedisSerializer as default serializer.

redisTemplate.setDefaultSerializer(new StringRedisSerializer());

然后将序列化程序和redis模板实例都放在注册表中,并从Camel URI中引用它.

Then put both the serializer and redis template instance in registry and reference it from Camel URI.

registry.put("customTemplate", template); registry.put("stringSerializer", new StringRedisSerializer());

骆驼URI就像...

Camel URI is like...

redis://<host>:<port>?redisTemplate=#customTemplate&serializer=#stringSerializer

更多推荐

Redis序列化以额外的字符串为前缀

本文发布于:2023-10-16 17:11:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1498207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前缀   字符串   序列化   Redis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!