redis
Redis-backed implementation of a token cache for OAuth2 service tokens.
Module Contents
Classes
A Redis-based cache implementation for storing and retrieving OAuth2 tokens. |
- class redis.RedisCache(host, port)
Bases:
digraph inheritanceaa6055ebb3 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "Cache" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Abstract base class for caching OAuth2 tokens."]; "ABC" -> "Cache" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RedisCache" [URL="#redis.RedisCache",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A Redis-based cache implementation for storing and retrieving OAuth2 tokens."]; "Cache" -> "RedisCache" [arrowsize=0.5,style="setlinewidth(0.5)"]; }ska_src_api_global_execution.cache.cache.CacheA 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.
- logger
- async add_dict(key, value, ttl=None)
Add a dictionary to the Redis cache with optional TTL.
- async add_string(key, value, ttl=None)
Add a string to the Redis cache with optional TTL.
- async add_to_sorted_set(set_name, member, score)
Add a member to a sorted set and optionally set an expiry on the whole set.
- 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.
- async get_count_sorted_set(set_name)
Retrieve the count of members in a sorted set.
- async get_dict(key)
Retrieve a dictionary from the Redis cache, raising an error if not found.
- async get_dict_or_none(key)
Retrieve a dictionary from Redis or return None if missing.
- async get_latest_from_sorted_set(set_name, start, end, desc=True, withscores=False)
Retrieve top N members from a sorted set.
- async get_string(key)
Retrieve a string from the Redis cache, raising an error if not found.
- async get_string_or_none(key)
Retrieve a string from Redis or return None if missing.
- async lock(lock_name, timeout=10, blocking_timeout=5)
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:
- async ping()
Ping the Redis server to check connectivity.
- 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.
- async test_connection()
Test connection to the Redis server.