Redis 序列化以额外字符串为前缀 [英] Redis serialization prefixed with extra string

查看:33
本文介绍了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.

Camel serializer URI 选项仅适用于 CONSUMER.为了影响 PRODUCER,我还需要配置一个自定义的 RedisTemplate,其中 StringRedisSerializer 作为默认序列化器.

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());

Camel URI 就像...

Camel URI is like...

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

这篇关于Redis 序列化以额外字符串为前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆