redis-namespace icon indicating copy to clipboard operation
redis-namespace copied to clipboard

flushall and flushdb vs namespaces

Open yaauie opened this issue 11 years ago • 12 comments

Since these are especially destructive (beyond the scope of the namespace) and rather surprising to anyone who would think that namespacing provides segregation, perhaps #flushall and #flushdb should be blocked in a future version, requiring the user to use RedisNamespace#redis directly.

yaauie avatar Apr 10 '13 06:04 yaauie

Yeah. This will cause lots of havok in the Resque tests....

steveklabnik avatar Apr 10 '13 22:04 steveklabnik

:+1:

carlzulauf avatar Apr 10 '13 22:04 carlzulauf

@steveklabnik definitely in a major version release if at all. The trouble is that the documentation claims that this wrapper "Namespaces all Redis calls", and yet it doesn't. Same for #34.

The actual behaviour is very surprising in a very destructive way, so either that needs to stop happening or the documentation needs to be updated to something like "Namespaces most Redis calls that we know and care about, but lets the rest pass through unchanged" :smile:.

yaauie avatar Apr 10 '13 22:04 yaauie

Does this mean that there is no way to flush a namespace?

plukevdh avatar Sep 09 '13 19:09 plukevdh

@plukevdh yes, that is correct.

yaauie avatar Sep 10 '13 17:09 yaauie

We are doing it currently like redis.del(redis.keys('*')) in our tests (or previously redis.keys('*').each { |key| redis.del(key) }). And I guess there are no better way of doing the same thing.

:+1: for #flushall and #flushdb to raise an error and use redis directly instead of current behaviour.

dmitry avatar Mar 04 '15 21:03 dmitry

@dmitry if your redis-server supports it (versions >= 2.7.105), scan is a lot safer (and the ruby adapter has scan_each which behaves a lot like keys)

yaauie avatar Mar 04 '15 21:03 yaauie

@yaauie thanks for the suggestion. We have parallel tests that are isolated by the redis-namespace and they are running in sequential flow, so the keys + del is enough for us for this task.

dmitry avatar Mar 04 '15 21:03 dmitry

Thanks @dmitry. I believe you also have to wrap that call, since del fails on an empty array:

if redis.keys.any?
  redis.del(redis.keys)
end

Fryie avatar Mar 06 '15 10:03 Fryie

@Fryie yes, that's right. To prevent from 2 calls, you have to use:

if (keys = redis.keys) && !keys.empty?
  redis.del(keys)
end

dmitry avatar Mar 06 '15 12:03 dmitry

Would there be any value in adding a new method that just deletes the namespaced keys? I could submit a PR if there is.

richhollis avatar Oct 08 '15 11:10 richhollis

So seems like this issue can be closed, because using them already produces a warning and will raise in 2.0 - https://github.com/resque/redis-namespace/blob/f2f601632a9975bbb0f3a38327535a4923a81c78/lib/redis/namespace.rb#L332-L347

Would there be any value in adding a new method that just deletes the namespaced keys? I could submit a PR if there is.

Makes sense to me.

fatkodima avatar Jul 03 '22 14:07 fatkodima