Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby redis client scan vs keys

Tags:

ruby

redis

I am looking for some documentation for the ruby client for redis with no luck. I am using keys, but I've heard their performance in production redis is terrible.

$redis = Redis.new(host: Settings.redis_host, port: Settings.redis_port)
keys = $redis.keys("prefix*")

Want to switch to $redis.scan("prefix*") but I didn't find any examples for it. also tried

keys = $redis.scan(0, {match: "key:1?"})
Redis::CommandError: ERR syntax error
keys = $redis.scan(0, match: "key:1?")
Redis::CommandError: ERR syntax error

appreciate a little light on this. Thanks.

Edit: After updating the redis client from 3.0.4 to 3.0.7 the

keys = $redis.scan(0, match: "prefix*")

worked.

like image 278
WebQube Avatar asked Mar 20 '23 09:03

WebQube


1 Answers

Do it like this:

keys = $redis.scan(0, match: 'prefix?')

Here is the "documentation" you need.

Be sure to also read the official documentation of SCAN.

like image 125
Agis Avatar answered Mar 30 '23 05:03

Agis