如何获取redis中特定hash下的所有key和value?

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

我尝试使用以下 java 代码读取特定 Redis 哈希键中的所有键和值,

  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"));
          }
        }

我在输出中得到以下输出,

Connected to Redis Connected to Redis:{}

但是在 redis 中我可以看到下面的条目,

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}]}

请告诉我为什么会出现此错误,这对我会有帮助。

你在redis中输入的key和你代码中的key是一样的吗?看起来 'onlline' 应该是 'online'.

如您所见,从 hgetall 中检索到的值是一个数组,即 return 类型。所以尝试将值保存在 Set/Array 中并尝试使用迭代器显示。