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

Fix redis cache #67125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions salt/cache/redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def _get_bank_redis_key(bank):
def _get_timestamp_key(bank, key):
opts = _get_redis_keys_opts()
return "{}{}{}/{}".format(
opts["timestamp_prefix"], opts["separator"], {bank}, {key}
opts["timestamp_prefix"], opts["separator"], bank, key
)
# Use this line when we can use modern python
# return f"{opts['timestamp_prefix']}{opts['separator']}{bank}/{key}"
Expand Down Expand Up @@ -340,10 +340,20 @@ def _build_bank_hier(bank, redis_pipe):
def joinbanks(*banks):
return "/".join(banks)

for bank_path in itertools.accumulate(bank.split("/"), joinbanks):
bank_set = _get_bank_redis_key(bank_path)
log.debug("Adding %s to %s", bank, bank_set)
redis_pipe.sadd(bank_set, ".")
bank_names = bank.split("/")
full_paths = list(itertools.accumulate(bank_names, joinbanks))

for parent_path, bank_name in zip(full_paths, bank_names[1:]):
parent_bank_redis_key = _get_bank_redis_key(parent_path)
log.debug("Adding %s to %s", bank_name, parent_bank_redis_key)
redis_pipe.sadd(parent_bank_redis_key, bank_name)

for bank_path in full_paths:
bank_redis_key = _get_bank_redis_key(bank_path)
log.debug("Adding a '.' to %s", bank_redis_key)
redis_pipe.sadd(bank_redis_key, ".")

return True


def _get_banks_to_remove(redis_server, bank, path=""):
Expand Down Expand Up @@ -531,7 +541,7 @@ def list_(bank):
Lists entries stored in the specified bank.
"""
redis_server = _get_redis_server()
bank_redis_key = _get_bank_keys_redis_key(bank)
bank_redis_key = _get_bank_redis_key(bank)
try:
banks = redis_server.smembers(bank_redis_key)
except (RedisConnectionError, RedisResponseError) as rerr:
Expand Down