Retrieve a list of all keys stored in Redis (Ruby) Retrieve a list of all keys stored in Redis (Ruby) ruby ruby

Retrieve a list of all keys stored in Redis (Ruby)


Sure, the redis-rb exposes all of the Redis commands and represents them as methods on your client object.

redis.keys('*')


If you have any substantial amount of records in your db, kernel will kill your redis.keys because it will be taking too much RAM.

What you want is extracting keys in batches. redis-rb has a wonderful method for this (not present in redis itself):

    redis.scan_each(match: 'user:*') do |resume_key_name|        resume_key_name #=> "user:12"    end

If you want all the keys, just don't use the match option.


redis.keysthis will return the result in array form.

more info : http://www.rubydoc.info/github/ezmobius/redis-rb/Redis