2

I want to delete all redis keys defined under namespace "datetime_filter" in ruby (maintenance task). How to do this ?

3 Answers 3

6

The right way to do this if you don't want to block the server is to use the SCAN command. The command will provide you an iterator returning only the keys matching your pattern if you wish (in this case it is appropriate to use the MATCH option for sure). The Ruby script will just have to iterate and delete.

So:

WHILE keys = SCAN MATCH datetime_filter*
    FOREACH key in keys DEL key
Sign up to request clarification or add additional context in comments.

Comments

4

Try this -

 $redis.del(datetime_filter_key)

and follow following approach -

In redis, how do i remove keys?

Comments

2

You could use:

Rails.cache.redis.keys.grep(/pattern/).each do |k|
  Rails.cache.redis.del(k)
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.