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?
You already can retrieve multiple keys, but not arbitrary ones. If your primary goal is to retrieve multiple arbitrary keys, use a hash and hmget. If your primary need is to access a sorted set, use sorted set and either go the scripting route or pipeline a series of zscore calls.
The Redis KEYS command returns all the keys in the database that match a pattern (or all the keys in the key space). Similar commands for fetching all the fields stored in a hash is HGETALL and for all fetching the members of a SMEMBERS. The keys in Redis themselves are stored in a dictionary (aka a hash table).
You can check the actual number by running redis-cli config get databases. In interactive mode, the database number is displayed in the prompt within square braces. For example, 127.0. 0.1:6379[13] shows that the 13th database is in use.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With