Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis expire on large set of keys

Tags:

redis

My problem is: i have a set of values that each of them has to have an expire value. code:

set a:11111:22222 someValue
expire a:11111:22222 604800 \\usually equal a week

In a perfect world i would have put all those values in a hash and give each of them it's appropriate expire value, but redis does not allow expire on a hash fields.

problem is that i also have a process that need to get all those keys about once an hour

keys a:*

this command is really expensive and according to redis documentation can cause performance issues. I have about 25000-30000 keys at each given moment.

Does someone knows how can i solve such a problem? thumbs up it guarantee (-;
Roy

like image 269
royB Avatar asked Nov 14 '13 12:11

royB


1 Answers

Let me propose an alternative solution.

Rather than asking Redis to scan all the keys, why not perform a background dump, and parse the dump to extract the keys? This way, there is zero impact on the Redis instance itself.

Parsing the dump file is not as scary as it sounds, because you can use the excellent redis-rdb-tools package:

https://github.com/sripathikrishnan/redis-rdb-tools

You can either convert the dump file into a json file, and then parse the json file, or use the Python API to extract the keys by yourself.

like image 79
Didier Spezia Avatar answered Nov 03 '22 10:11

Didier Spezia