Search code examples
javadatabasespringredisspring-data-redis

How to get all the keys and values under the specific hash in redis?


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.


Solution

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