Using redis-rb in a Rails app, the following doesn’t work:
irb> keys = $redis.keys("autocomplete*")
=> ["autocomplete_foo", "autocomplete_bar", "autocomplete_bat"]
irb> $redis.del(keys)
=> 0
This works fine:
irb> $redis.del("autocomplete_foo", "autocomplete_bar")
=> 2
Am I missing something obvious? The source is just:
# Delete a key.
def del(*keys)
synchronize do
@client.call [:del, *keys]
end
end
which looks to me like it should work to pass it an array…?
A little coding exploration of the way the splat operator works:
So passing in a regular array will cause that array to be evaluated as a single item, so that you get an array inside an array within your method. If you preface the array with * when you call the method:
That lets the method know to unpack it/not to accept any further arguments. So that should solve the problem that you’re having!
Just for the sake of further clarification, this works:
This causes a syntax error: