Lettuce Using RedisAsyncCommands with non String,String codec

huangapple go评论84阅读模式
英文:

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 &lt;String, String&gt; which is the default initialization codec for Lettuce. I want &lt;String, byte[]&gt; , how can I do that?

RedisURI redisUri = RedisURI.builder().withHost(configuration.getTelematicsRedis().getHost()).withPort(configuration.getTelematicsRedis().getPort()).build();
RedisClient client = RedisClient.create(redisUri);
RedisAsyncCommands&lt;String, String&gt; 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&lt;String, byte[]&gt; redisAsyncCommands = client.connect(RedisCodec.of(new StringCodec(), new ByteArrayCodec())).async();

huangapple
  • 本文由 发表于 2020年7月25日 15:52:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63085821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定