Cache - client¶
InMemoryCache
¶
Bases: BaseCache
Implementation of a InMemory client. DO NOT USE IN PRODUCTION.
lock
¶
Sets a key-value pair in a lock mechanism.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key to be locked.
TYPE:
|
ttl_ms
|
The time-to-live for the lock in milliseconds.
TYPE:
|
blocking
|
If True, the method will block until the lock is acquired.
TYPE:
|
blocking_timeout
|
The maximum time in seconds to block while waiting for the lock to be acquired.
TYPE:
|
blocking_sleep
|
The time in seconds to wait between attempts to acquire the lock when blocking.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AsyncInMemoryLock
|
The Lock object representing the acquired lock.
TYPE:
|
Source code in webtool/cache/client.py
set
async
¶
Sets a key-value pair.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for the data to be set.
TYPE:
|
value
|
The value associated with the key.
TYPE:
|
ex
|
Expiration time for the key, in seconds or as a timedelta.
TYPE:
|
exat
|
Expiration time as an absolute timestamp.
TYPE:
|
nx
|
if set to True, set the value at key to value only if it does not exist.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
return of set.
TYPE:
|
Source code in webtool/cache/client.py
get
async
¶
Gets a key-value pair.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for the data to be set.
TYPE:
|
Returns: Any: return of get.
Source code in webtool/cache/client.py
delete
async
¶
Deletes a key-value pair.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for the data to be set.
TYPE:
|
Returns: None
Source code in webtool/cache/client.py
RedisCache
¶
Bases: BaseCache
Implementation of a Redis client with failover capabilities.
Initializes the Redis client.
PARAMETER | DESCRIPTION |
---|---|
redis_url
|
Redis data source name for connection.
TYPE:
|
connection_pool
|
An existing connection pool to use.
TYPE:
|
Source code in webtool/cache/client.py
lock
¶
Sets a key-value pair in a lock mechanism.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key to be locked.
TYPE:
|
ttl_ms
|
The time-to-live for the lock in milliseconds.
TYPE:
|
blocking
|
If True, the method will block until the lock is acquired.
TYPE:
|
blocking_timeout
|
The maximum time in seconds to block while waiting for the lock to be acquired.
TYPE:
|
blocking_sleep
|
The time in seconds to wait between attempts to acquire the lock when blocking.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AsyncRedisLock
|
The Lock object representing the acquired lock.
TYPE:
|
Source code in webtool/cache/client.py
set
async
¶
Sets a key-value pair.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for the data to be set.
TYPE:
|
value
|
The value associated with the key.
TYPE:
|
ex
|
Expiration time for the key, in seconds or as a timedelta.
TYPE:
|
exat
|
Expiration time as an absolute timestamp.
TYPE:
|
nx
|
if set to True, set the value at key to value only if it does not exist.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
return of set.
TYPE:
|
Source code in webtool/cache/client.py
get
async
¶
Gets a key-value pair.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for the data to be set.
TYPE:
|
Returns: Any: return of get.
Source code in webtool/cache/client.py
delete
async
¶
Deletes a key-value pair.
PARAMETER | DESCRIPTION |
---|---|
key
|
The key for the data to be set.
TYPE:
|
Returns: None
aclose
async
¶
Closes the Redis client connection and connection pool.
Source code in webtool/cache/client.py
RedisConfig
dataclass
¶
RedisConfig(
username=None,
password=None,
health_check_interval=0,
socket_timeout=0.5,
socket_connect_timeout=2.0,
socket_keepalive=True,
retry=Retry(default_backoff(), retries=3),
retry_on_error=lambda: [
BusyLoadingError,
ConnectionError,
RedisError,
OSError,
](),
retry_on_timeout=True,
ssl=False,
max_connections=None,
protocol=3,
)
Configuration settings for establishing a connection with a Redis server.
PARAMETER | DESCRIPTION |
---|---|
username
|
username
TYPE:
|
password
|
password
TYPE:
|
health_check_interval
|
Interval in seconds for performing health checks.
TYPE:
|
socket_timeout
|
Timeout in seconds for socket operations, including reads and writes.
TYPE:
|
socket_connect_timeout
|
Timeout in seconds for establishing a new connection to Redis.
TYPE:
|
socket_keepalive
|
Whether to enable TCP keepalive for the connection. Default is True.
TYPE:
|
retry
|
Retry policy for handling transient failures.
TYPE:
|
retry_on_error
|
A list of exception types that should trigger a retry.
TYPE:
|
retry_on_timeout
|
Whether to retry operations when a timeout occurs.
TYPE:
|
ssl
|
Specifies if SSL should be used for the Redis connection.
TYPE:
|
protocol
|
Redis protocol version to be used. Default is RESP3.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
to_dict |
Converts the configuration fields to a dictionary. |
retry_on_error
class-attribute
instance-attribute
¶
retry_on_error = field(
default_factory=lambda: [
BusyLoadingError,
ConnectionError,
RedisError,
OSError,
]
)