Count keys of hashset

55 views
Skip to first unread message

manu.t...@gmail.com

unread,
Sep 30, 2015, 5:22:58 AM9/30/15
to Redis DB
Hello,

I want to make a count on hashset to determine the number of keys. 

I use a lua script for the count like db.eval("return #redis.call('keys', '"+collection_name+":*')",0) but performances decrease dramatically when I run my script.

Is there a way to make a hashset count and avoid to lost performance on redis ? 

Regards,

Emmanuel

Itamar Haber

unread,
Sep 30, 2015, 6:47:47 AM9/30/15
to redi...@googlegroups.com

Firstly, don't use KEYS, SCAN if you must.

Secondly, both the-command-that-should-not-be-used and SCAN iterate through your server's entire keyspace. This will always result degraded performance as the number of total keys grows.

The way you'd usually keep track of key names in Redis (to quickly retiring these names) is by managing a set who's members are the relevant key names. This requires you to SADD/SREM accordingly in your code whenever you create/delete a key that belongs to that "index" set.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Itamar Haber

unread,
Sep 30, 2015, 11:41:01 AM9/30/15
to redi...@googlegroups.com

^retiring^retrieving

Reply all
Reply to author
Forward
0 new messages