0

I have tried to read all the key and values inside the specific redis hash key with the below java code,

  import redis.clients.jedis.Jedis;

        public class RedisDBExport {

          public static void main(String[] args) throws Exception {
            Jedis jedis = new Jedis("hostname", portno);
            jedis.auth("password");
            System.out.println("Connected to Redis");
            System.out.println("Connected to Redis:"+jedis.hgetAll("bookstore:englishauthor:usa:2017-08-27:online:subscriberlist"));
          }
        }

I am getting the below output in output ,

Connected to Redis Connected to Redis:{}

But in redis i could see the below entries are there,

row  key         value 

1   Kumar       {"totalbooks":0,"openbooks":[{"total":0}]}
2   Anuxx       {"totalbooks":1,"openbooks":[{"total":1}]}
3   Manux       {"totalbooks":2,"openbooks":[{"total":2}]}
4   Kumal       {"totalbooks":4,"openbooks":[{"total":4}]}
5   Anuxy       {"totalbooks":3,"openbooks":[{"total":3}]}
6   Manuy       {"totalbooks":5,"openbooks":[{"total":5}]}

Kindly suggest why i am getting this error,it will be helpful for me.

sathya
  • 199
  • 5
  • 26

2 Answers2

0

Is the key you typed in redis identical to the one in your code? Looks like 'onlline' should be 'online'.

Chris Tanner
  • 1,624
  • 1
  • 12
  • 20
0

As you can see the values that has retrieved from the hgetall is an Array i.e the return type . So try saving the values in a Set/Array and the try to display using an iterator.

  • actually there is an typo mistaken in our code and its resolved.also you are correct with the hgetall @Nikhil Asakar – sathya Jan 10 '19 at 11:24