redis-namespace
redis-namespace copied to clipboard
flushall and flushdb vs namespaces
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.
Yeah. This will cause lots of havok in the Resque tests....
:+1:
@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:.
Does this mean that there is no way to flush a namespace?
@plukevdh yes, that is correct.
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 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 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.
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 yes, that's right. To prevent from 2 calls, you have to use:
if (keys = redis.keys) && !keys.empty?
redis.del(keys)
end
Would there be any value in adding a new method that just deletes the namespaced keys? I could submit a PR if there is.
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.