redis_service.operations.string
string
codex_platform.redis_service.operations.string
Redis String/Key operations.
Classes
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. |