redis_service
redis_service
codex_platform.redis_service
Async Redis service with mixin architecture.
Requires redis.asyncio.Redis client. All methods are async-only.
Quick start::
from codex_platform.redis_service import RedisService
service = RedisService(client=redis_client)
await service.set_hash_json("my_key", "field", {"a": 1})
Custom composition::
from codex_platform.redis_service import BaseRedisService, HashMixin, StreamMixin
class MyRedisService(BaseRedisService, HashMixin, StreamMixin):
pass
Key Registry::
from codex_platform.redis_service import UserKey
await service.get_hash_json(UserKey(), "profile", user_id=42)
Classes
BaseRedisService
Base class that holds a Redis connection.
Inherit from this class when building a service that wraps a Redis client
but does not need the full :class:~codex_platform.redis_service.service.RedisService
composition.
Source code in src/codex_platform/redis_service/base.py
Functions
__init__(client)
Initialize the service with an existing async Redis client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
An already-constructed |
required |
BaseRedisKey
Bases: ABC
Abstract base for all Redis key definitions.
Subclass and define template with {placeholder} syntax.
Call .build(**kwargs) to construct the final key string.
Source code in src/codex_platform/redis_service/keys.py
Attributes
template
abstractmethod
property
Key template string with {placeholder} syntax.
Functions
build(**kwargs)
Build the final key string by formatting the template with keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Values for each placeholder defined in |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
Fully resolved Redis key string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required placeholder argument is missing. |
Source code in src/codex_platform/redis_service/keys.py
SessionKey
Bases: BaseRedisKey
Session data. Args: token.
Source code in src/codex_platform/redis_service/keys.py
UserKey
Bases: BaseRedisKey
User data hash. Args: user_id.
Source code in src/codex_platform/redis_service/keys.py
BaseRedisManager
Base manager that initialises common Redis operation helpers.
Subclass and add only the operation attributes your manager actually needs.
Example::
class SiteSettingsManager(BaseRedisManager):
async def get_settings(self) -> dict:
return await self.hash.get_all("site:settings") or {}
Source code in src/codex_platform/redis_service/managers/base_manager.py
Functions
__init__(redis_client)
Initialize the manager with an existing async Redis client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
redis_client
|
Redis
|
An already-constructed |
required |
Source code in src/codex_platform/redis_service/managers/base_manager.py
SiteSettingsManager
Bases: BaseRedisManager
Async interface to the shared site_settings Redis hash.
Provides a fixed CACHE_KEY so that all services in the Codex ecosystem read and write the same Redis key without coupling to Django models.
Example::
manager = SiteSettingsManager(redis_client)
await manager.aset_fields({"maintenance": "false", "version": "1.2"})
value = await manager.aget_field("maintenance")
all_settings = await manager.aget_all()
Source code in src/codex_platform/redis_service/managers/site_settings.py
Functions
aget_all()
async
Return all settings as a flat dict (HGETALL).
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of |
Source code in src/codex_platform/redis_service/managers/site_settings.py
aget_field(field)
async
Return a single setting value (HGET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Setting name. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
String value, or |
Source code in src/codex_platform/redis_service/managers/site_settings.py
aset_field(field, value)
async
Write a single setting atomically (HSET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
Setting name. |
required |
value
|
str
|
String value to store. |
required |
Source code in src/codex_platform/redis_service/managers/site_settings.py
aset_fields(data)
async
Write multiple settings in a single call (HSET mapping).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, str]
|
Mapping of |
required |
Source code in src/codex_platform/redis_service/managers/site_settings.py
aexists()
async
Check whether any settings are present in the cache (HLEN > 0).
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/codex_platform/redis_service/managers/site_settings.py
HashOperations
Redis Hash operations (HSET / HGET / HGETALL / HDEL and more).
Accepts an already-constructed redis.asyncio.Redis client.
All methods wrap Redis errors in typed exceptions.
Example::
ops = HashOperations(client)
await ops.set_json("user:42", "profile", {"name": "Alice"})
profile = await ops.get_json("user:42", "profile")
Source code in src/codex_platform/redis_service/operations/hash.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
Functions
set_json(key, field, data, **kwargs)
async
Serialize a dict to JSON and store it in a hash field (HSET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
field
|
str
|
Hash field name. |
required |
data
|
dict[str, Any]
|
Dictionary to serialize as JSON. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisDataError
|
If |
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
get_json(key, field, **kwargs)
async
Retrieve a hash field and deserialize it from JSON (HGET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
field
|
str
|
Hash field name. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Deserialized dictionary, or |
Raises:
| Type | Description |
|---|---|
RedisDataError
|
If the field value is not valid JSON. |
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
set_field(key, field, value, **kwargs)
async
Set a single string field in a hash (HSET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
field
|
str
|
Hash field name. |
required |
value
|
str
|
String value to store. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
set_fields(key, data, *, encoder=None, **kwargs)
async
Set multiple hash fields in a single call (HSET mapping).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
data
|
dict[str, Any]
|
Mapping of |
required |
encoder
|
Callable[[Any], Any] | None
|
Optional callable to transform values before setting. |
None
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
get_field(key, field, **kwargs)
async
Retrieve a single hash field as a string (HGET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
field
|
str
|
Hash field name. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str | None
|
String value of the field, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
get_fields(key, *fields, **kwargs)
async
Retrieve multiple hash fields in a single request (HMGET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*fields
|
str
|
Field names to retrieve. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str | None]
|
List of values in the same order as |
list[str | None]
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
get_all(key, **kwargs)
async
Retrieve all fields and values from a hash (HGETALL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, str] | None
|
Dict of |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
delete_field(key, *fields, **kwargs)
async
Delete one or more fields from a hash (HDEL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*fields
|
str
|
Field names to delete. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of fields actually deleted. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
delete(key, **kwargs)
async
Delete the entire hash key (DEL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
exists_field(key, field, **kwargs)
async
Check whether a field exists in a hash (HEXISTS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
field
|
str
|
Hash field name to check. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
keys(key, **kwargs)
async
Return all field names of a hash (HKEYS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of field names. Empty list if the hash does not exist. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
values(key, **kwargs)
async
Return all field values of a hash (HVALS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of field values. Empty list if the hash does not exist. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
length(key, **kwargs)
async
Return the number of fields in a hash (HLEN).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of fields. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
increment(key, field, amount=1, **kwargs)
async
Increment a numeric hash field by the given amount (HINCRBY).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
field
|
str
|
Numeric field name. |
required |
amount
|
int
|
Increment step. Defaults to |
1
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
New value of the field after incrementing. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/hash.py
JsonModuleOperations
Redis JSON operations using the server-side RedisJSON module (JSON.* commands).
Requires the RedisJSON module on the server and redis-py with JSON support. Supports path-based access, atomic updates, array append, and more.
Example::
svc = JsonModuleOperations(client)
await svc.set("user:42", "$", {"name": "Alice", "age": 30})
name = await svc.get("user:42", "$.name") # [["Alice"]]
Source code in src/codex_platform/redis_service/operations/json_module.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
Functions
set(key, path, obj, nx=False, xx=False)
async
Set a JSON value at the given path (JSON.SET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
path
|
str
|
JSONPath expression, e.g. |
required |
obj
|
Any
|
Any JSON-serializable object. |
required |
nx
|
bool
|
Set only if the key does not exist. |
False
|
xx
|
bool
|
Set only if the key already exists. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the RedisJSON module is not available. |
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_module.py
get(key, path='$')
async
Retrieve a JSON value at the given path (JSON.GET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
path
|
str
|
JSONPath expression. Defaults to |
'$'
|
Returns:
| Type | Description |
|---|---|
Any
|
Parsed value, or |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the RedisJSON module is not available. |
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_module.py
arrappend(key, path, *args)
async
Append elements to a JSON array at the given path (JSON.ARRAPPEND).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
path
|
str
|
JSONPath expression pointing to an array. |
required |
*args
|
Any
|
Values to append to the array. |
()
|
Returns:
| Type | Description |
|---|---|
int
|
New length of the array after appending. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the RedisJSON module is not available. |
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_module.py
delete(key, path='$')
async
Delete a JSON value at the given path (JSON.DEL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
path
|
str
|
JSONPath expression. Defaults to |
'$'
|
Returns:
| Type | Description |
|---|---|
int
|
Number of elements deleted. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the RedisJSON module is not available. |
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_module.py
JsonStringOperations
Store JSON objects as Redis strings using SET/GET with json.dumps/loads.
Works with any standard Redis instance — no server modules required.
Does not support path-based access; for that use
:class:~codex_platform.redis_service.operations.json_module.JsonModuleOperations.
Example::
svc = JsonStringOperations(client)
await svc.set("user:42", {"name": "Alice", "age": 30}, ttl=3600)
user = await svc.get("user:42") # {"name": "Alice", "age": 30}
Source code in src/codex_platform/redis_service/operations/json_string.py
Functions
set(key, obj, ttl=None)
async
Serialize an object to JSON and store it in Redis (SET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
obj
|
Any
|
Any JSON-serializable object (dict, list, str, int, …). |
required |
ttl
|
int | None
|
Expiry in seconds. |
None
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_string.py
get(key)
async
Read a Redis string and deserialize it from JSON (GET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Deserialized object, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_string.py
set_nx(key, obj, ttl=None)
async
Set a JSON value only if the key does not exist (SET NX).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Redis key string. |
required |
obj
|
Any
|
Any JSON-serializable object. |
required |
ttl
|
int | None
|
Expiry in seconds. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_string.py
mget(*keys)
async
Retrieve multiple JSON values in a single request (MGET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
Redis key strings. |
()
|
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of deserialized objects in the same order as |
list[Any]
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/json_string.py
ListOperations
Redis List operations (RPUSH / LPUSH / LPOP / LRANGE and more).
Accepts an already-constructed redis.asyncio.Redis client.
All methods wrap Redis errors in typed exceptions.
Example::
ops = ListOperations(client)
await ops.push("queue:jobs", "job-1", "job-2")
job = await ops.pop("queue:jobs")
Source code in src/codex_platform/redis_service/operations/list_.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
Functions
push(key, *values, **kwargs)
async
Append one or more values to the end of a list (RPUSH).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*values
|
str
|
String values to append. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
New length of the list after the operation. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
lpush(key, *values, **kwargs)
async
Prepend one or more values to the beginning of a list (LPUSH).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*values
|
str
|
String values to prepend. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
New length of the list after the operation. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
pop(key, **kwargs)
async
Remove and return the first element of a list (LPOP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str | None
|
The first element, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
rpop(key, **kwargs)
async
Remove and return the last element of a list (RPOP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str | None
|
The last element, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
brpop(*keys, timeout=0)
async
Blocking pop of the last element from the first non-empty list (BRPOP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
One or more Redis key strings to check in order. |
()
|
timeout
|
int
|
Maximum seconds to block. |
0
|
Returns:
| Type | Description |
|---|---|
tuple[str, str] | None
|
|
tuple[str, str] | None
|
or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
range(key, start=0, end=-1, **kwargs)
async
Return a slice of list elements by index range (LRANGE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
start
|
int
|
Start index (0-based). Negative values count from the end. |
0
|
end
|
int
|
End index inclusive. |
-1
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of elements in the requested range. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
length(key, **kwargs)
async
Return the number of elements in a list (LLEN).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
List length. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
set_index(key, index, value, **kwargs)
async
Set the element at a specific list index (LSET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
index
|
int
|
Zero-based index. Negative values count from the end. |
required |
value
|
str
|
New value to set at the given index. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
trim(key, start, end, **kwargs)
async
Trim a list to the specified index range, discarding all other elements (LTRIM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
start
|
int
|
Start index (inclusive). |
required |
end
|
int
|
End index (inclusive). |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
move(src, dst)
async
Atomically move the last element of src to the head of dst (RPOPLPUSH).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source list key. |
required |
dst
|
str
|
Destination list key. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The moved element, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/list_.py
PipelineOperations
Redis pipeline and atomic transaction operations.
Provides three execution modes:
- Batching (
execute) — commands are sent in one round-trip, not atomic. - Transaction (
transact) — commands are wrapped in MULTI/EXEC, atomic. - Context manager (
atomic) — atomic block with automatic EXEC on exit.
Also exposes Lua script execution via eval_script.
Source code in src/codex_platform/redis_service/operations/pipeline.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
Functions
execute(builder_func)
async
Execute a sequence of commands in a pipeline without MULTI/EXEC (batching).
Commands are sent in a single round-trip but are not atomic.
Use transact or atomic when atomicity is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
builder_func
|
Callable[[Pipeline], Awaitable[None]]
|
Async function that receives a |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of results for each queued command, in order. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Example::
async def build(pipe):
await pipe.set("k1", "v1")
await pipe.set("k2", "v2")
results = await ops.execute(build)
Source code in src/codex_platform/redis_service/operations/pipeline.py
transact(builder_func)
async
Execute commands in an atomic transaction (MULTI/EXEC).
All commands inside builder_func are executed atomically.
If the server crashes before EXEC, none of the commands are applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
builder_func
|
Callable[[Pipeline], Awaitable[None]]
|
Async function that receives a |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
List of results for each queued command, in order. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Example::
async def transfer(pipe):
await pipe.decrby("wallet:from", 100)
await pipe.incrby("wallet:to", 100)
results = await ops.transact(transfer)
Source code in src/codex_platform/redis_service/operations/pipeline.py
atomic()
async
Async context manager for an atomic block (MULTI/EXEC).
Opens a Pipeline in transaction mode. EXEC is called automatically on exit.
Yields:
| Type | Description |
|---|---|
AsyncIterator[Pipeline]
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Example::
async with service.pipeline.atomic() as pipe:
await pipe.set("session:abc", "token")
await pipe.expire("session:abc", 3600)
# EXEC is called automatically on context exit
Source code in src/codex_platform/redis_service/operations/pipeline.py
eval_script(script, keys=None, args=None)
async
Execute a Lua script (EVAL). Lua scripts are always atomic in Redis.
Use for complex read-modify-write operations that must not be interrupted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script
|
str
|
Lua script source code. |
required |
keys
|
list[str] | None
|
List of Redis keys accessible as |
None
|
args
|
list[Any] | None
|
Script arguments accessible as |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Value returned by the Lua script. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Example::
result = await ops.eval_script(
"""
local val = redis.call('GET', KEYS[1])
if val == ARGV[1] then
redis.call('SET', KEYS[1], ARGV[2])
return 1
end
return 0
""",
keys=["mykey"],
args=["expected", "new_value"],
)
Source code in src/codex_platform/redis_service/operations/pipeline.py
SetOperations
Redis Set operations (SADD / SREM / SMEMBERS / SISMEMBER and more).
Accepts an already-constructed redis.asyncio.Redis client.
All methods wrap Redis errors in typed exceptions.
Example::
ops = SetOperations(client)
await ops.add("tags:post:42", "python", "redis")
has_tag = await ops.is_member("tags:post:42", "python")
Source code in src/codex_platform/redis_service/operations/set_.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
Functions
add(key, *values, **kwargs)
async
Add one or more members to a set (SADD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*values
|
str | int
|
Values to add. Integers are coerced to strings. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members actually added (already-existing members are not counted). |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
remove(key, *values, **kwargs)
async
Remove one or more members from a set (SREM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*values
|
str | int
|
Values to remove. Integers are coerced to strings. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members actually removed. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
members(key, **kwargs)
async
Return all members of a set (SMEMBERS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of all member strings. Empty set if the key does not exist. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
is_member(key, value, **kwargs)
async
Check whether a value is a member of a set (SISMEMBER).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
value
|
str | int
|
Value to check. Integers are coerced to strings. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
card(key, **kwargs)
async
Return the number of members in a set (SCARD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Set cardinality. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
pop(key, count=1, **kwargs)
async
Remove and return random members from a set (SPOP).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
count
|
int
|
Number of members to pop. Defaults to |
1
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of popped members. Empty set if the key does not exist. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
random(key, count=1, **kwargs)
async
Return random members without removing them (SRANDMEMBER).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
count
|
int
|
Number of random members to return. |
1
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of random members (may contain duplicates if |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
union(*keys)
async
Return the union of multiple sets (SUNION).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
Redis key strings. |
()
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set containing all members from all given sets. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
inter(*keys)
async
Return the intersection of multiple sets (SINTER).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
Redis key strings. |
()
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set containing only members present in all given sets. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
diff(*keys)
async
Return the difference between the first set and all subsequent sets (SDIFF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
Redis key strings. The first key is the base set. |
()
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of members present in the first set but not in any of the others. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/set_.py
StringOperations
Redis String and key-level operations (SET / GET / EXPIRE / TTL and more).
Accepts an already-constructed redis.asyncio.Redis client.
All methods wrap Redis errors in typed exceptions.
Example::
ops = StringOperations(client)
await ops.set("session:abc", "token-value", ttl=3600)
token = await ops.get("session:abc")
Source code in src/codex_platform/redis_service/operations/string.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
Functions
set(key, value, ttl=None, **kwargs)
async
Set a string value (SET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
value
|
str
|
String value to store. |
required |
ttl
|
int | None
|
Expiry in seconds. |
None
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
setnx(key, value, ttl=None, **kwargs)
async
Set a value only if the key does not exist (SET NX).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
value
|
str
|
String value to store. |
required |
ttl
|
int | None
|
Expiry in seconds. |
None
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
get(key, **kwargs)
async
Retrieve a string value (GET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str | None
|
String value, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
getset(key, value, **kwargs)
async
Atomically set a new value and return the previous one (GETSET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
value
|
str
|
New value to store. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str | None
|
Previous value, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
mget(*keys)
async
Retrieve values for multiple keys in a single request (MGET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys
|
str
|
Redis key strings. |
()
|
Returns:
| Type | Description |
|---|---|
list[str | None]
|
List of values in the same order as |
list[str | None]
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
mset(mapping)
async
Set values for multiple keys in a single call (MSET).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping
|
dict[str, str]
|
Dict of |
required |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
incr(key, **kwargs)
async
Increment a numeric value by 1 (INCR).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
New value after incrementing. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
incrby(key, amount, **kwargs)
async
Increment a numeric value by a given amount (INCRBY).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
amount
|
int
|
Increment step. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
New value after incrementing. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
append(key, value, **kwargs)
async
Append a string to an existing value (APPEND).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
value
|
str
|
String to append. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
New total length of the value after appending. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
delete(key, **kwargs)
async
Delete a key (DEL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
delete_by_pattern(pattern)
async
Delete all keys matching a glob pattern (SCAN + DEL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Glob pattern, e.g. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of keys deleted. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
expire(key, ttl, **kwargs)
async
Set a TTL (expiry) on a key in seconds (EXPIRE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
ttl
|
int
|
Time-to-live in seconds. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
ttl(key, **kwargs)
async
Return the remaining TTL of a key in seconds (TTL).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Remaining TTL in seconds. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
exists(key, **kwargs)
async
Check whether a key exists (EXISTS).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
rename(key, new_key, **kwargs)
async
Rename a key (RENAME).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
new_key
|
str
|
Target key name. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
key_type(key, **kwargs)
async
Return the data type stored at a key (TYPE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
One of: |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/string.py
ZSetOperations
Redis Sorted Set operations (ZADD / ZRANGE / ZRANGEBYSCORE / ZREM and more).
Accepts an already-constructed redis.asyncio.Redis client.
All methods wrap Redis errors in typed exceptions.
Example::
ops = ZSetOperations(client)
await ops.add("leaderboard", {"alice": 1500.0, "bob": 1200.0})
top = await ops.range("leaderboard", 0, 9, reverse=True, with_scores=True)
Source code in src/codex_platform/redis_service/operations/zset.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
Functions
add(key, mapping, **kwargs)
async
Add members with scores to a sorted set (ZADD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
mapping
|
dict[str, float]
|
Dict of |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of new members added (existing members with updated scores are not counted). |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
score(key, member, **kwargs)
async
Return the score of a member in a sorted set (ZSCORE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
member
|
str
|
Member name. |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
float | None
|
Float score of the member, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
rank(key, member, reverse=False, **kwargs)
async
Return the rank (position) of a member in a sorted set (ZRANK / ZREVRANK).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
member
|
str
|
Member name. |
required |
reverse
|
bool
|
If |
False
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int | None
|
Zero-based rank of the member, or |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
range(key, start=0, end=-1, reverse=False, with_scores=False, **kwargs)
async
Return a range of members by rank (ZRANGE / ZREVRANGE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
start
|
int
|
Start rank (0-based). |
0
|
end
|
int
|
End rank inclusive. |
-1
|
reverse
|
bool
|
If |
False
|
with_scores
|
bool
|
If |
False
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str] | list[tuple[str, float]]
|
List of member strings, or list of |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
range_by_score(key, min_score, max_score, with_scores=False, **kwargs)
async
Return members within a score range (ZRANGEBYSCORE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
min_score
|
float
|
Minimum score (inclusive). |
required |
max_score
|
float
|
Maximum score (inclusive). |
required |
with_scores
|
bool
|
If |
False
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
list[str] | list[tuple[str, float]]
|
List of member strings, or list of |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
remove(key, *members, **kwargs)
async
Remove one or more members from a sorted set (ZREM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
*members
|
str
|
Member names to remove. |
()
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members actually removed. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
card(key, **kwargs)
async
Return the number of members in a sorted set (ZCARD).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
increment(key, member, amount=1.0, **kwargs)
async
Increment the score of a member by the given amount (ZINCRBY).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
member
|
str
|
Member name. |
required |
amount
|
float
|
Increment value. Defaults to |
1.0
|
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
New score of the member after incrementing. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
count(key, min_score, max_score, **kwargs)
async
Count members within a score range (ZCOUNT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
min_score
|
float
|
Minimum score (inclusive). |
required |
max_score
|
float
|
Maximum score (inclusive). |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members with score in |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
remove_by_rank(key, start, end, **kwargs)
async
Remove members by rank range (ZREMRANGEBYRANK).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
start
|
int
|
Start rank (inclusive, 0-based). |
required |
end
|
int
|
End rank (inclusive). |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members removed. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
remove_by_score(key, min_score, max_score, **kwargs)
async
Remove members within a score range (ZREMRANGEBYSCORE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | BaseRedisKey
|
Redis key or a |
required |
min_score
|
float
|
Minimum score (inclusive). |
required |
max_score
|
float
|
Maximum score (inclusive). |
required |
**kwargs
|
Any
|
Extra parameters forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
int
|
Number of members removed. |
Raises:
| Type | Description |
|---|---|
RedisConnectionError
|
Redis connection failure. |
RedisServiceError
|
Redis operation failure. |
Source code in src/codex_platform/redis_service/operations/zset.py
RedisService
Unified Redis service — all data-type operations in one place.
Suitable for projects that need access to multiple Redis data types through
a single entry point. For selective composition, instantiate individual
Operations classes directly.
Attributes:
| Name | Type | Description |
|---|---|---|
hash |
Hash operations (HSET / HGET / HGETALL …). |
|
string |
String and key-level operations (SET / GET / EXPIRE …). |
|
list |
List operations (RPUSH / LPOP / LRANGE …). |
|
set |
Set operations (SADD / SREM / SMEMBERS …). |
|
zset |
Sorted-set operations (ZADD / ZRANGE / ZRANK …). |
|
json |
JSON stored as Redis strings — works with any Redis instance. |
|
json_module |
JSON via the server-side RedisJSON module (requires RedisJSON). |
|
pipeline |
Pipeline / transaction helpers. |
Source code in src/codex_platform/redis_service/service.py
Functions
__init__(client)
Initialize the service with an existing async Redis client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Redis
|
An already-constructed |
required |