Alexandr Alexandr - 1 month ago 47
Java Question

How to use Redisson to upload byte array in Redis Cluster?

I haven't found an explanation about how to upload pure array of bytes. Redisson has a RBitSet but it manages an array of bits not bytes. How to store a byte array by using Redisson?

Here is my configuration:

Config config = new Config();

LoadBalancer loadBalancer = new RoundRobinLoadBalancer();

config.useClusterServers()
.setScanInterval(5000) // cluster state scan interval in milliseconds
.addNodeAddress("192.168.0.14:6379", "192.168.0.15:6379")
.setReadMode(ReadMode.MASTER_SLAVE)
.setLoadBalancer(loadBalancer)
.setPassword("bTFBx1NYYWRMTUEyNHhsCg")
.setSlaveConnectionPoolSize(10)
.setMasterConnectionPoolSize(10);

RedissonClient redisson = Redisson.create(config);

Answer

I was helped on github. Here is how to write a byte array:

RBucket<byte[]> bucket = redisson.getBucket("myBucket", ByteArrayCodec.INSTANCE);
byte[] myarray = ...
bucket.set(myarray);