56

I store my data in redis. I store in one raw it guid, createday, and it size.

So I define the following:

var dbclient1 = db.createClient();
dbclient1.hmset("doc:3743-da23-dcdf-3213", "date", "2015-09-06 00:00:01", "size", "203")
dbclient1.zadd("cache", 32131, "37463-da23-dcdf-3213")

I wish to view all my files in my db. So I try the following:

dbclient1.hgetall("doc:*", function (err, res){
        console.log(err)
        console.log(res)
})

but res is undefined. How can I do it?

MIDE11
  • 3,140
  • 7
  • 31
  • 53
  • This GUI interface helped me out a lot when getting started: https://redislabs.com/blog/redisinsight-gui/ Not at all an answer to your question; but, great for viewing data, testing search, profiling, etc, so thought worth adding to this thread. There are other similar tools. – ficuscr May 12 '21 at 03:31

1 Answers1

79

HGETALL returns all fields and values of the hash stored at key, you can't specify a mask: http://redis.io/commands/hgetall

You can call KEYS doc:* to get a list of all keys matching your criteria and then get all values in a loop.

But please read a section on potential performance hit before you do that: http://redis.io/commands/keys

Igor Korkhov
  • 8,283
  • 1
  • 26
  • 31
  • 40
    Don't use KEYS on production, it is too dangerous. Use SCAN instead, you have filtering WITH MATCH and cursor with COUNT - so it will be something like SCAN 0 COUNT 50 MATCH doc:* http://redis.io/commands/scan – Liviu Costea Jun 09 '15 at 11:49
  • 11
    @lcostea: using `KEYS` may or may not be dangerous depending on a particular scenario which OP didn't describe. Granted, `SCAN` is safer performance-wise, but since it's just a cursor it may not return all entries or return some entries multiple times, so must be used carefully as well. – Igor Korkhov Jun 09 '15 at 15:45
  • 47
    @LiviuCostea Saying it's dangerous without giving a reason is not very helpful. – swade Nov 01 '16 at 15:55
  • 9
    @StevenWade read the docs: http://redis.io/commands/keys there is a Warning there – Liviu Costea Nov 02 '16 at 09:46
  • 18
    Maybe this part is new. https://redis.io/commands/keys says: "Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds." -- which means the performance penalty might be a non-issue depending on your application. – nishanthshanmugham Aug 03 '20 at 19:08