简体   繁体   中英

Migrate data from a Redis cluster to an other with Redisson

I want to migrate data from an old Redis cluster to a new one programmatically, so I did this:

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

The problem with this, is that I when I do RBucket::get , Redisson try to decode the value with a class that is not necessarily in the classpath (because that was set by an other microservice).

Is there a way to disable decoding in Redisson? Or a better way to do this?

Use ByteArrayCodec. Example:

RBucket<Object> bucket = encryptedRedisClient.getBucket(key, ByteArrayCodec.INSTANCE);
bucket.set(value);
bucket.expire(48L, DAYS);

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