69

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?

asked Jun 9, 2015 at 10:04
1
  • This GUI interface helped me out a lot when getting started: 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. Commented May 12, 2021 at 3:31

1 Answer 1

95

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.

However, an important note per docs:

Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.

Ermiya Eskandary
24.3k3 gold badges57 silver badges72 bronze badges
answered Jun 9, 2015 at 10:17
Sign up to request clarification or add additional context in comments.

5 Comments

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:* redis.io/commands/scan
@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.
@LiviuCostea Saying it's dangerous without giving a reason is not very helpful.
@StevenWade read the docs: redis.io/commands/keys there is a Warning there
Maybe this part is new. 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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.