Search code examples
javaredisredisson

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 ?


Solution

  • Use ByteArrayCodec. Example:

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