:py:mod:`redis` =============== .. py:module:: redis .. autoapi-nested-parse:: Redis-backed implementation of a token cache for OAuth2 service tokens. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: redis.RedisCache .. py:class:: RedisCache(host, port) Bases: :py:obj:`ska_src_api_global_execution.cache.cache.Cache` .. autoapi-inheritance-diagram:: redis.RedisCache :parts: 1 :private-bases: A Redis-based cache implementation for storing and retrieving OAuth2 tokens. This class stores tokens in Redis using a key derived from the token's scopes and audiences. Tokens are serialised to JSON and automatically validated for expiration before being returned. Expired tokens are removed from the cache. Optionally, a key prefix can be used to namespace cached entries. Keys are deterministically generated by alphabetically sorting scopes and audiences. .. py:attribute:: logger .. py:method:: add_dict(key, value, ttl = None) :async: Add a dictionary to the Redis cache with optional TTL. .. py:method:: add_string(key, value, ttl = None) :async: Add a string to the Redis cache with optional TTL. .. py:method:: add_to_sorted_set(set_name, member, score) :async: Add a member to a sorted set and optionally set an expiry on the whole set. .. py:method:: get_cache_token(scopes, audiences, key_prefix=None) Retrieve a cached token from Redis using scopes and audiences as the cache key. The cache key is generated by alphabetically sorting the scopes and audiences, and optionally prepending a key prefix for namespacing. .. py:method:: get_count_sorted_set(set_name) :async: Retrieve the count of members in a sorted set. .. py:method:: get_dict(key) :async: Retrieve a dictionary from the Redis cache, raising an error if not found. .. py:method:: get_dict_or_none(key) :async: Retrieve a dictionary from Redis or return None if missing. .. py:method:: get_latest_from_sorted_set(set_name, start, end, desc = True, withscores = False) :async: Retrieve top N members from a sorted set. .. py:method:: get_string(key) :async: Retrieve a string from the Redis cache, raising an error if not found. .. py:method:: get_string_or_none(key) :async: Retrieve a string from Redis or return None if missing. .. py:method:: lock(lock_name, timeout = 10, blocking_timeout = 5) :async: Create a lock object. timeout: Automatically releases the lock after 10 seconds to prevent deadlocks if the worker crashes. blocking_timeout: How long the worker will wait to acquire the lock before giving up. :return: .. py:method:: ping() :async: Ping the Redis server to check connectivity. .. py:method:: set_cache_token(scopes, audiences, token, key_prefix=None) Store a token in Redis with a key based on scopes and audiences. The cache key is generated by alphabetically sorting the scopes and audiences, and optionally prepending a key prefix for namespacing. The token is serialized to JSON before being stored. .. py:method:: test_connection() :async: Test connection to the Redis server.