Redis / Get all keys & values from redis with pref

2019-02-21 19:43发布

问题:

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?

回答1:

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



标签: redis