Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedisCache.clear may return integer instead of boolean #1163

Closed
spacewander opened this issue Aug 19, 2017 · 2 comments
Closed

RedisCache.clear may return integer instead of boolean #1163

spacewander opened this issue Aug 19, 2017 · 2 comments

Comments

@spacewander
Copy link
Contributor

I am using python 2.7.12 with :

redis==2.10.6
werkzeug==0.12.2

According to the documentation, werkzeug.contrib.cache.RedisCache.clear should return a boolean value to indicate Whether the cache has been cleared.
However, because self._client.delete(*keys) returns an integer as the number of keys removed, the actual returned value could be an integer. And since clear is not atomic, the returned number may be not equal to the len(keys).

Maybe we could set status according to existence of redis.exceptions.ResponseError?
For example:

status = True
try:
      self._client.delete(*keys)
except redis.exceptions.ResponseError:
      status = False

BTW, if there is nothing to clear, RedisCache.clear will return False. On the same occasion, FileSystemCache.clear will return True. The documentation about this occasion is not clear.

I could submit a patch if those behaviors are considered as bug.

@spacewander
Copy link
Contributor Author

One more thing, RedisCache.clear should not use keys to get all keys.

Use keys in production is not recommended. Some people even suggest to rename keys command in production environment. I observed the mistake in a PHP background task before. The keys operation locked the Redis for more than 1 second, caused a great number of redis operation timeouts. I am not willing to see this happens again.

There is already an issue about replacing keys with scan(#1069), but there is not a related pull request yet.

@lepture
Copy link
Contributor

lepture commented Feb 4, 2018

close it via #1249

@lepture lepture closed this as completed Feb 4, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants