0

I am trying to get value of a key in redis cluster using redisson client .

Config config = new Config();
        config.useClusterServers()      
    .addNodeAddress("redis://localhost:6380","redis://localhost:6379","redis://localhost:6381");

        RedissonClient redisson = Redisson.create(config);

        RMapCache<String, String> map = redisson.getMapCache("db0");

        System.out.println("Key value  is :  "+map.get("key"));

I have got db0 as keyspace from this command result

INFO keyspace

db0:keys=1,expires=0,avg_ttl=0

but the result is :

Key value is : null

Elsayed
  • 2,712
  • 7
  • 28
  • 41

2 Answers2

0

Redis cluster has always single keyspace and it couldn't be switched or accessed through db0 name. db0:keys=1 means that you already has single key with db0 in your case.

Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71
0

I propose this code for connecting to Redis (cluster or simple server) and get a existing key simple value:

package org.example;

import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.redisson.config.Config;

public class Main {
    public static void main(String[] args) {

        try {
            Config config = new Config();
            config.useSingleServer().setAddress("redis://localhost:6379");
            config.setCodec(new StringCodec());
            RedissonClient redisson = Redisson.create(config);
            RBucket<String> bucket = redisson.getBucket("clientName");
            String objValue = bucket.get();
            System.out.println("The object value is: " + objValue);
            redisson.shutdown();
        } catch (Exception e) {
            System.out.println("e = " + e);
            e.printStackTrace();
        }
    }
}
jlguenego
  • 1,192
  • 15
  • 23