diff --git a/changelogs/fragments/35120-redis_inventory_plugin_flush_cache.yaml b/changelogs/fragments/35120-redis_inventory_plugin_flush_cache.yaml new file mode 100644 index 00000000000..5ee8b4e080f --- /dev/null +++ b/changelogs/fragments/35120-redis_inventory_plugin_flush_cache.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Only delete host key from redis in-memory cache if present. diff --git a/lib/ansible/plugins/cache/redis.py b/lib/ansible/plugins/cache/redis.py index 230a9177cb1..a8edaa6a046 100644 --- a/lib/ansible/plugins/cache/redis.py +++ b/lib/ansible/plugins/cache/redis.py @@ -116,7 +116,8 @@ class CacheModule(BaseCacheModule): return (self._db.zrank(self._keys_set, key) is not None) def delete(self, key): - del self._cache[key] + if key in self._cache: + del self._cache[key] self._db.delete(self._make_key(key)) self._db.zrem(self._keys_set, key)