![](/img/trans.png)
[英]How to get value of a key in redis cluster using redisson client
[英]Migrate data from a Redis cluster to an other with Redisson
我想以編程方式將數據從舊的 Redis 集群遷移到新集群,所以我這樣做了:
legacyRedisClient.getKeys()
.getKeys()
.forEach(key -> {
LOGGER.info("Redis Migration : Migrating key {}", key);
Optional.of(legacyRedisClient.getBucket(key))
.filter(RObject::isExists)
.map(RBucket::get)
.ifPresent(value -> {
LOGGER.info("Redis Migration : Storing element with key {}", key);
RBucket<Object> bucket = encryptedRedisClient.getBucket(key);
bucket.set(value);
bucket.expire(48L, DAYS);
});
});
問題在於,當我執行RBucket::get
時,Redisson 嘗試使用不一定在類路徑中的 class 解碼值(因為它是由其他微服務設置的)。
有沒有辦法在 Redisson 中禁用解碼? 或者更好的方法來做到這一點?
使用 ByteArrayCodec。 例子:
RBucket<Object> bucket = encryptedRedisClient.getBucket(key, ByteArrayCodec.INSTANCE);
bucket.set(value);
bucket.expire(48L, DAYS);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.