redisson icon indicating copy to clipboard operation
redisson copied to clipboard

Unable to retrieve original string stored in HyperLogLog using GET operation on the key

Open divyad1508 opened this issue 6 years ago • 3 comments

Hi Everyone,

I am in process of backing up the values present in the HyperLogLog data structure in Redis to a backing store on disk, which can later be used for cache misses. I am unable to do the same because of the following scenario, details of which I have mentioned below.

Please let me know if anyone has encountered the same or if have any solutions for this scenario.

Thanks in advance!

Expected behavior

On running GET operation on the key containing hyper log log structure, it should return the string which is stored in value like "HYLL\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00]f\x80b\x97"

Actual behavior

Although, on running GET operation from redisson client it is returning string like HYLL]f�b�.

Steps to reproduce or test case

RHyperLogLog<Object> rHyperLogLog = RedissonClient.getInstance().getHyperLogLog(key, StringCodec.INSTANCE);

rHyperLogLog.add(value);

String value = RedissonClient.getInstance().getBucket(key).get();

Value returned here is not the expected one.

Redis version

Redis server v=4.0.6

Redisson version

3.11.0

Redisson configuration

Config redisConfig = new Config();
            redisConfig.setTransportMode(TransportMode.NIO);
            redisConfig.useClusterServers()
                    // .addNodeAddress("redis://127.0.0.1:7000", "redis://127.0.0.1:7001");
                    .addNodeAddress(config.getString(RedissonConstant.REDIS_CLUSTER_NODE_ADDRESSES).split(","))
                    .setIdleConnectionTimeout(config.getInt(RedissonConstant.REDIS_CLUSTER_IDLE_CONN_TIMEOUT, 10000))
                    .setConnectTimeout(config.getInt(RedissonConstant.REDIS_CLUSTER_IDLE_CONN_TIMEOUT, 10000))
                    .setTimeout(config.getInt(RedissonConstant.REDIS_CLUSTER_IDLE_CONN_TIMEOUT, 3000))
                    .setRetryAttempts(config.getInt(RedissonConstant.REDIS_CLUSTER_RETRY_ATTEMPTS, 3))
                    .setRetryInterval(config.getInt(RedissonConstant.REDIS_CLUSTER_RETRY_INTERVAL, 1500))
                    .setFailedSlaveReconnectionInterval(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_FAILED_SLAVE_RECONN_INTERVAL, 3000))
                    .setFailedSlaveCheckInterval(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_FAILED_SLAVE_CHECK_INTERVAL, 60000))
                    .setPassword(config.get(RedissonConstant.REDIS_CLUSTER_PASSWORD, null))
                    .setSubscriptionsPerConnection(config.getInt(RedissonConstant.REDIS_CLUSTER_SUB_PER_CONN, 5))
                    .setClientName(config.get(RedissonConstant.REDIS_CLUSTER_CLIENT_NAME, null))
                    .setLoadBalancer(new RoundRobinLoadBalancer())
                    .setSubscriptionConnectionMinimumIdleSize(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_SUB_CONN_MIN_IDLE_SIZE, 1))
                    .setSubscriptionConnectionPoolSize(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_SUB_CONN_POOL_SIZE, 50))
                    .setSlaveConnectionMinimumIdleSize(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_SLAVE_CONN_MIN_IDLE_SIZE, 32))
                    .setSlaveConnectionPoolSize(config.getInt(RedissonConstant.REDIS_CLUSTER_SLAVE_CONN_POOL_SIZE, 64))
                    .setMasterConnectionMinimumIdleSize(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_MASTER_CONN_MIN_IDLE_SIZE, 32))
                    .setMasterConnectionPoolSize(
                            config.getInt(RedissonConstant.REDIS_CLUSTER_MASTER_CONN_POOL_SIZE, 64))
                    .setReadMode(ReadMode.SLAVE).setSubscriptionMode(SubscriptionMode.SLAVE)
                    .setScanInterval(config.getInt(RedissonConstant.REDIS_CLUSTER_SCAN_INTERVAL, 1000))
                    .setPingConnectionInterval(config.getInt(RedissonConstant.REDIS_CLUSTER_PING_CONN_INTERVAL, 0))
                    .setKeepAlive(Boolean.parseBoolean(config.get(RedissonConstant.REDIS_CLUSTER_KEEP_ALIVE, "false")))
                    .setTcpNoDelay(
                            Boolean.parseBoolean(config.get(RedissonConstant.REDIS_CLUSTER_TCP_NO_DELAY, "false")));
            redisConfig.setThreads(config.getInt(RedissonConstant.REDIS_CLUSTER_THREADS, 16))
                    .setNettyThreads(config.getInt(RedissonConstant.REDIS_CLUSTER_NETTY_THREADS, 32))
                    .setCodec(new FstCodec());

            clusterRedissonClient = Redisson.create(redisConfig);

divyad1508 avatar Dec 05 '19 11:12 divyad1508

Hi Everyone,

I was able to solve the issue after referencing the following link which helped in gaining the insight to get the value from HyperLogLog key in bytes.

https://stackoverflow.com/questions/41245658/redis-java-writing-and-reading-binary-data

Solution

byte[] value = RedissonClient.getInstance().getBucket(key, ByteArrayCodec.INSTANCE).get();

This byte array can be stored as it is or can be encoded to Base64 string for saving on disk storage.

Please let me know if anyone has doubts on this. Thanks!

divyad1508 avatar Dec 06 '19 07:12 divyad1508

You could use dump and restore methods instead

mrniko avatar Dec 06 '19 07:12 mrniko

Thanks for your suggestion @mrniko . Will try using dump & restore as well.

divyad1508 avatar Dec 06 '19 08:12 divyad1508