英文:
Lettuce Using RedisAsyncCommands with non String,String codec
问题
我想使用与 Lettuce 默认初始化编解码器 <String, String>
不同的类型 (K, V)
来初始化 Lettuce 的 RedisAsyncCommands。我想使用 <String, byte[]>
,请问我该如何做?
RedisURI redisUri = RedisURI.builder()
.withHost(configuration.getTelematicsRedis().getHost())
.withPort(configuration.getTelematicsRedis().getPort())
.build();
RedisClient client = RedisClient.create(redisUri);
RedisAsyncCommands<String, byte[]> redisAsyncCommands = client.connect().async();
我查阅了 Lettuce 的文档以及一些其他在线资源,但仍然不太清楚。
提前感谢您。
英文:
I want to initialize Lettuce's RedisAsyncCommands with (K, V) different from <String, String>
which is the default initialization codec for Lettuce. I want <String, byte[]>
, how can I do that?
RedisURI redisUri = RedisURI.builder().withHost(configuration.getTelematicsRedis().getHost()).withPort(configuration.getTelematicsRedis().getPort()).build();
RedisClient client = RedisClient.create(redisUri);
RedisAsyncCommands<String, String> redisAsyncCommands = client.connect().async();
I went through the lettuce documentation and some other resources online but it's still not clear to me.
Thanks in advance.
答案1
得分: 1
我们可以通过以下方式传递所需的 Key 和 Value 编解码器来实现相同的操作:
RedisURI redisUri = RedisURI.builder()
.withHost(configuration.getTelematicsRedis().getHost())
.withPort(configuration.getTelematicsRedis().getPort())
.build();
RedisClient client = RedisClient.create(redisUri);
RedisAsyncCommands<String, byte[]> redisAsyncCommands = client.connect(RedisCodec.of(new StringCodec(), new ByteArrayCodec())).async();
英文:
We can do the same by passing the required Key and Value codec in this way:
RedisURI redisUri = RedisURI.builder().withHost(configuration.getTelematicsRedis().getHost()).withPort(configuration.getTelematicsRedis().getPort()).build();
RedisClient client = RedisClient.create(redisUri);
RedisAsyncCommands<String, byte[]> redisAsyncCommands = client.connect(RedisCodec.of(new StringCodec(), new ByteArrayCodec())).async();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论