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

Support version 3 of the redis python library #49445

Merged
merged 2 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/redis-3-compat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- redis cache - Support version 3 of the redis python library (https://github.com/ansible/ansible/issues/49341)
11 changes: 7 additions & 4 deletions lib/ansible/plugins/cache/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- This cache uses JSON formatted, per host records saved in Redis.
version_added: "1.9"
requirements:
- redis (python lib)
- redis>=2.4.5 (python lib)
options:
_uri:
description:
Expand Down Expand Up @@ -48,9 +48,9 @@
from ansible.plugins.cache import BaseCacheModule

try:
from redis import StrictRedis
from redis import StrictRedis, VERSION
except ImportError:
raise AnsibleError("The 'redis' python module is required for the redis fact cache, 'pip install redis'")
raise AnsibleError("The 'redis' python module (version 2.4.5 or newer) is required for the redis fact cache, 'pip install redis'")


class CacheModule(BaseCacheModule):
Expand Down Expand Up @@ -99,7 +99,10 @@ def set(self, key, value):
else:
self._db.set(self._make_key(key), value2)

self._db.zadd(self._keys_set, time.time(), key)
if VERSION[0] == 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want <= 2 ... those using the OS package for redis python might have ancient libs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of verifying that VERSION was available, I checked the tags in GitHub, and found that 2.4.6 (the oldest in GitHub) was released in Jul 13, 2011. It seems as though 2.4.5 was when VERSION was added. Roughly 2.4.5 was released around Jun 7, 2011.

As such, this change would put a requirement on at least 2.4.5, although I have no idea whether other functionality would work this far back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gtk, so it will just fail on import for older redis, we might want to capture that and state min requirement is 2.4.5

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

self._db.zadd(self._keys_set, time.time(), key)
else:
self._db.zadd(self._keys_set, {key: time.time()})
self._cache[key] = value

def _expire_keys(self):
Expand Down