Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis / Get all keys & values from redis with prefix

Tags:

redis

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?

like image 898
MIDE11 Avatar asked Jun 09 '15 10:06

MIDE11


People also ask

How do I get multiple keys in Redis?

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.

Which Redis command is used to obtain all the keys in a database?

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).

How do I view the contents of Redis cache?

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.


1 Answers

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

like image 100
Igor Korkhov Avatar answered Sep 19 '22 00:09

Igor Korkhov