简体   繁体   中英

Lettuce Using RedisAsyncCommands with non String,String codec

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM