python3-commons 0.8.16__py3-none-any.whl → 0.8.18__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python3_commons/cache.py +17 -15
- {python3_commons-0.8.16.dist-info → python3_commons-0.8.18.dist-info}/METADATA +2 -2
- {python3_commons-0.8.16.dist-info → python3_commons-0.8.18.dist-info}/RECORD +7 -7
- {python3_commons-0.8.16.dist-info → python3_commons-0.8.18.dist-info}/WHEEL +1 -1
- {python3_commons-0.8.16.dist-info → python3_commons-0.8.18.dist-info}/licenses/AUTHORS.rst +0 -0
- {python3_commons-0.8.16.dist-info → python3_commons-0.8.18.dist-info}/licenses/LICENSE +0 -0
- {python3_commons-0.8.16.dist-info → python3_commons-0.8.18.dist-info}/top_level.txt +0 -0
python3_commons/cache.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import logging
|
2
2
|
import socket
|
3
3
|
from platform import platform
|
4
|
-
from typing import Any, Mapping, Sequence
|
4
|
+
from typing import Any, Mapping, Sequence
|
5
5
|
|
6
6
|
import valkey
|
7
7
|
from pydantic import RedisDsn
|
8
8
|
from valkey.asyncio import Valkey, StrictValkey, ConnectionPool, Sentinel
|
9
9
|
from valkey.asyncio.retry import Retry
|
10
10
|
from valkey.backoff import FullJitterBackoff
|
11
|
-
from valkey.typing import ResponseT
|
11
|
+
from valkey.typing import ResponseT
|
12
12
|
|
13
13
|
from python3_commons.conf import valkey_settings
|
14
14
|
from python3_commons.helpers import SingletonMeta
|
@@ -76,11 +76,11 @@ def get_valkey_client() -> Valkey:
|
|
76
76
|
|
77
77
|
|
78
78
|
async def scan(
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
cursor: int = 0,
|
80
|
+
match: bytes | str | memoryview | None = None,
|
81
|
+
count: int | None = None,
|
82
|
+
_type: str | None = None,
|
83
|
+
**kwargs,
|
84
84
|
) -> ResponseT:
|
85
85
|
return await get_valkey_client().scan(cursor, match, count, _type, **kwargs)
|
86
86
|
|
@@ -92,17 +92,17 @@ async def delete(*names: str | bytes | memoryview):
|
|
92
92
|
async def store_bytes(name: str, data: bytes, ttl: int = None, if_not_set: bool = False):
|
93
93
|
r = get_valkey_client()
|
94
94
|
|
95
|
-
return r.set(name, data, ex=ttl, nx=if_not_set)
|
95
|
+
return await r.set(name, data, ex=ttl, nx=if_not_set)
|
96
96
|
|
97
97
|
|
98
98
|
async def get_bytes(name: str) -> bytes | None:
|
99
99
|
r = get_valkey_client()
|
100
100
|
|
101
|
-
return r.get(name)
|
101
|
+
return await r.get(name)
|
102
102
|
|
103
103
|
|
104
104
|
async def store(name: str, obj: Any, ttl: int = None, if_not_set: bool = False):
|
105
|
-
return store_bytes(name, serialize_msgpack_native(obj), ttl, if_not_set)
|
105
|
+
return await store_bytes(name, serialize_msgpack_native(obj), ttl, if_not_set)
|
106
106
|
|
107
107
|
|
108
108
|
async def get(name: str, default=None, data_type: Any = None) -> Any:
|
@@ -137,8 +137,9 @@ async def store_sequence(name: str, data: Sequence, ttl: int = None):
|
|
137
137
|
|
138
138
|
async def get_sequence(name: str, _type: type = list) -> Sequence:
|
139
139
|
r = get_valkey_client()
|
140
|
+
lrange = await r.lrange(name, 0, -1)
|
140
141
|
|
141
|
-
return _type(map(deserialize_msgpack_native,
|
142
|
+
return _type(map(deserialize_msgpack_native, lrange))
|
142
143
|
|
143
144
|
|
144
145
|
async def store_dict(name: str, data: Mapping, ttl: int = None):
|
@@ -157,7 +158,7 @@ async def store_dict(name: str, data: Mapping, ttl: int = None):
|
|
157
158
|
async def get_dict(name: str, value_data_type=None) -> dict | None:
|
158
159
|
r = get_valkey_client()
|
159
160
|
|
160
|
-
if data := r.hgetall(name):
|
161
|
+
if data := await r.hgetall(name):
|
161
162
|
data = {k.decode(): deserialize_msgpack(v, value_data_type) for k, v in data.items()}
|
162
163
|
|
163
164
|
return data
|
@@ -223,7 +224,7 @@ async def has_set_item(name: str, value: str) -> bool:
|
|
223
224
|
try:
|
224
225
|
r = get_valkey_client()
|
225
226
|
|
226
|
-
return r.sismember(name, serialize_msgpack_native(value)) == 1
|
227
|
+
return await r.sismember(name, serialize_msgpack_native(value)) == 1
|
227
228
|
except valkey.exceptions.ConnectionError as e:
|
228
229
|
logger.error(f'Failed to check if set has item in cache: {e}')
|
229
230
|
|
@@ -246,8 +247,9 @@ async def delete_set_item(name: str, value: str):
|
|
246
247
|
async def get_set_members(name: str) -> set[str] | None:
|
247
248
|
try:
|
248
249
|
r = get_valkey_client()
|
250
|
+
smembers = await r.smembers(name)
|
249
251
|
|
250
|
-
return set(map(deserialize_msgpack_native,
|
252
|
+
return set(map(deserialize_msgpack_native, smembers))
|
251
253
|
except valkey.exceptions.ConnectionError as e:
|
252
254
|
logger.error(f'Failed to get set members from cache: {e}')
|
253
255
|
|
@@ -257,4 +259,4 @@ async def get_set_members(name: str) -> set[str] | None:
|
|
257
259
|
async def exists(name: str) -> bool:
|
258
260
|
r = get_valkey_client()
|
259
261
|
|
260
|
-
return r.exists(name) == 1
|
262
|
+
return await r.exists(name) == 1
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: python3-commons
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.18
|
4
4
|
Summary: Re-usable Python3 code
|
5
5
|
Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
|
6
6
|
License: gpl-3
|
@@ -16,7 +16,7 @@ Requires-Dist: aiohttp[speedups]~=3.11.16
|
|
16
16
|
Requires-Dist: asyncpg~=0.30.0
|
17
17
|
Requires-Dist: fastapi-users-db-sqlalchemy~=7.0.0
|
18
18
|
Requires-Dist: fastapi-users[sqlalchemy]~=14.0.1
|
19
|
-
Requires-Dist: lxml~=5.
|
19
|
+
Requires-Dist: lxml~=5.4.0
|
20
20
|
Requires-Dist: minio~=7.2.15
|
21
21
|
Requires-Dist: msgpack~=1.1.0
|
22
22
|
Requires-Dist: msgspec~=0.19.0
|
@@ -1,7 +1,7 @@
|
|
1
1
|
python3_commons/__init__.py,sha256=0KgaYU46H_IMKn-BuasoRN3C4Hi45KlkHHoPbU9cwiA,189
|
2
2
|
python3_commons/api_client.py,sha256=zj6zTF-DhUMu4bjj9VWLi63mVODG_SB47Q5qlmG-Sxg,4539
|
3
3
|
python3_commons/audit.py,sha256=DMQ-nrWSs0qilD7wkz_8PV4jXcee75O8FgAm2YIuOiY,6256
|
4
|
-
python3_commons/cache.py,sha256=
|
4
|
+
python3_commons/cache.py,sha256=PIzEcJSblDZJ9L4-9N3kI4fIG-vImwScXQ9gb0jk_L8,7792
|
5
5
|
python3_commons/conf.py,sha256=Vu6eZ8uHiKFHe3OLdtImrUZe5JH4KH7HULwF5M4kY8U,1232
|
6
6
|
python3_commons/fs.py,sha256=wfLjybXndwLqNlOxTpm_HRJnuTcC4wbrHEOaEeCo9Wc,337
|
7
7
|
python3_commons/helpers.py,sha256=OmuCF7UeJ6oe-rH1Y4ZYVW_uPQ973lCLsikj01wmNqs,3101
|
@@ -20,9 +20,9 @@ python3_commons/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
20
20
|
python3_commons/serializers/json.py,sha256=P288wWz9ic38QWEMrpp_uwKPYkQiOgvE1cI4WZn6ZCg,808
|
21
21
|
python3_commons/serializers/msgpack.py,sha256=tzIGGyDL3UpZnnouCtnxuYDx6InKM_C3PP1N4PN8wd4,1269
|
22
22
|
python3_commons/serializers/msgspec.py,sha256=FuZVqOLJb0-lEKrs7dtjhwEbHIpfMUk5yu1hD64zRdc,2038
|
23
|
-
python3_commons-0.8.
|
24
|
-
python3_commons-0.8.
|
25
|
-
python3_commons-0.8.
|
26
|
-
python3_commons-0.8.
|
27
|
-
python3_commons-0.8.
|
28
|
-
python3_commons-0.8.
|
23
|
+
python3_commons-0.8.18.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
|
24
|
+
python3_commons-0.8.18.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
|
25
|
+
python3_commons-0.8.18.dist-info/METADATA,sha256=JnFj1oxFjh5cQ49ndtN6EI3Znc4UttU8Fq1LSVN1ebc,1190
|
26
|
+
python3_commons-0.8.18.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
27
|
+
python3_commons-0.8.18.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
|
28
|
+
python3_commons-0.8.18.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|