Compare commits
1
Commits
v1.1.0
..
7aed6853ed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7aed6853ed |
@@ -14,19 +14,19 @@ datastore trio (`redis` / `psql` / `mysql`), a sibling of the `mongo` lib.
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v1.0.0
|
redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v0.2.1
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v1.0.0"
|
pip install "redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v0.2.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
Pulls `redis>=5.0.1` (redis-py, which ships the asyncio client — **not** the dead standalone
|
Pulls `redis>=5.0.1` (redis-py, which ships the asyncio client — **not** the dead standalone
|
||||||
`aioredis`; `5.0.1` is the floor because `5.0.0` lacks the async client's `aclose()`).
|
`aioredis`; `5.0.1` is the floor because `5.0.0` lacks the async client's `aclose()`).
|
||||||
|
|
||||||
Drop the `@v1.0.0` suffix from the line above to install the latest unpinned.
|
Drop the `@v0.2.1` suffix from the line above to install the latest unpinned.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "redis_store"
|
name = "redis_store"
|
||||||
version = "1.1.0"
|
version = "1.0.0"
|
||||||
description = "async redis wrapper over redis-py asyncio with a raw escape hatch, fail-loud and config-free"
|
description = "async redis wrapper over redis-py asyncio with a raw escape hatch, fail-loud and config-free"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ context manager:
|
|||||||
async with RedisDB(host="localhost") as kv:
|
async with RedisDB(host="localhost") as kv:
|
||||||
await kv.incr("hits")
|
await kv.incr("hits")
|
||||||
|
|
||||||
fail loud: wrapped methods catch RedisError and re-raise it - the raised exception IS
|
fail loud: wrapped methods catch RedisError, log, and re-raise; see each method's
|
||||||
the signal, and the caller (which alone knows fatal-vs-routine) decides and logs; the
|
docstring for its own contract. unwrapped ops go through the raw `.client` escape
|
||||||
wrapped method logs only at DEBUG (with the traceback) so a failure isn't reported
|
hatch: full driver surface, raises.
|
||||||
twice (raise XOR log). see each method's docstring for its own contract. unwrapped ops
|
|
||||||
go through the raw `.client` escape hatch: full driver surface, raises.
|
|
||||||
|
|
||||||
notes:
|
notes:
|
||||||
- import is `redis_store`; repo is `redis`, distribution is `redis_store` (the
|
- import is `redis_store`; repo is `redis`, distribution is `redis_store` (the
|
||||||
@@ -89,7 +87,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
await self._client.ping()
|
await self._client.ping()
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.connect() ping failed", exc_info=True)
|
log.exception("redis.connect() ping failed")
|
||||||
await self._pool.disconnect()
|
await self._pool.disconnect()
|
||||||
raise
|
raise
|
||||||
return self
|
return self
|
||||||
@@ -106,7 +104,7 @@ class RedisDB:
|
|||||||
finally:
|
finally:
|
||||||
await self._pool.disconnect()
|
await self._pool.disconnect()
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.close()", exc_info=True)
|
log.exception("redis.close()")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def __aenter__(self) -> "RedisDB":
|
async def __aenter__(self) -> "RedisDB":
|
||||||
@@ -130,7 +128,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.get(key)
|
return await self._client.get(key)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.get(%s)", key, exc_info=True)
|
log.exception("redis.get(%s)", key)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def set(self, key: str, value, ex: Optional[int] = None) -> bool:
|
async def set(self, key: str, value, ex: Optional[int] = None) -> bool:
|
||||||
@@ -138,7 +136,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return bool(await self._client.set(key, value, ex=ex))
|
return bool(await self._client.set(key, value, ex=ex))
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.set(%s)", key, exc_info=True)
|
log.exception("redis.set(%s)", key)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def delete(self, *keys: str) -> int:
|
async def delete(self, *keys: str) -> int:
|
||||||
@@ -146,7 +144,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.delete(*keys)
|
return await self._client.delete(*keys)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.delete(%s)", keys, exc_info=True)
|
log.exception("redis.delete(%s)", keys)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def exists(self, *keys: str) -> int:
|
async def exists(self, *keys: str) -> int:
|
||||||
@@ -154,7 +152,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.exists(*keys)
|
return await self._client.exists(*keys)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.exists(%s)", keys, exc_info=True)
|
log.exception("redis.exists(%s)", keys)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def incr(self, key: str, amount: int = 1) -> int:
|
async def incr(self, key: str, amount: int = 1) -> int:
|
||||||
@@ -162,7 +160,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.incrby(key, amount)
|
return await self._client.incrby(key, amount)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.incr(%s)", key, exc_info=True)
|
log.exception("redis.incr(%s)", key)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def decr(self, key: str, amount: int = 1) -> int:
|
async def decr(self, key: str, amount: int = 1) -> int:
|
||||||
@@ -170,7 +168,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.decrby(key, amount)
|
return await self._client.decrby(key, amount)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.decr(%s)", key, exc_info=True)
|
log.exception("redis.decr(%s)", key)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hget(self, name: str, field: str) -> Optional[str]:
|
async def hget(self, name: str, field: str) -> Optional[str]:
|
||||||
@@ -178,7 +176,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hget(name, field)
|
return await self._client.hget(name, field)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.hget(%s, %s)", name, field, exc_info=True)
|
log.exception("redis.hget(%s, %s)", name, field)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hset(self, name: str, key: Optional[str] = None, value=None, mapping: Optional[dict] = None) -> int:
|
async def hset(self, name: str, key: Optional[str] = None, value=None, mapping: Optional[dict] = None) -> int:
|
||||||
@@ -189,7 +187,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hset(name, key=key, value=value, mapping=mapping)
|
return await self._client.hset(name, key=key, value=value, mapping=mapping)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.hset(%s)", name, exc_info=True)
|
log.exception("redis.hset(%s)", name)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hgetall(self, name: str) -> dict:
|
async def hgetall(self, name: str) -> dict:
|
||||||
@@ -197,7 +195,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hgetall(name)
|
return await self._client.hgetall(name)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.hgetall(%s)", name, exc_info=True)
|
log.exception("redis.hgetall(%s)", name)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hdel(self, name: str, *fields: str) -> int:
|
async def hdel(self, name: str, *fields: str) -> int:
|
||||||
@@ -205,7 +203,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hdel(name, *fields)
|
return await self._client.hdel(name, *fields)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.hdel(%s)", name, exc_info=True)
|
log.exception("redis.hdel(%s)", name)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def expire(self, key: str, seconds: int) -> bool:
|
async def expire(self, key: str, seconds: int) -> bool:
|
||||||
@@ -213,7 +211,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return bool(await self._client.expire(key, seconds))
|
return bool(await self._client.expire(key, seconds))
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.expire(%s)", key, exc_info=True)
|
log.exception("redis.expire(%s)", key)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def ttl(self, key: str) -> int:
|
async def ttl(self, key: str) -> int:
|
||||||
@@ -225,5 +223,5 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.ttl(key)
|
return await self._client.ttl(key)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.debug("redis.ttl(%s)", key, exc_info=True)
|
log.exception("redis.ttl(%s)", key)
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user