Compare commits
3
Commits
7aed6853ed
...
v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69e0184cef | ||
|
|
b459fce9a8 | ||
|
|
24607aa5f7 |
@@ -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@v0.2.1
|
redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v1.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v0.2.1"
|
pip install "redis_store @ git+ssh://git@git.rethinkstudios.io/rethink-public/redis.git@v1.0.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
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 `@v0.2.1` suffix from the line above to install the latest unpinned.
|
Drop the `@v1.0.0` 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 = "0.2.1"
|
version = "1.1.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,9 +12,11 @@ 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, log, and re-raise; see each method's
|
fail loud: wrapped methods catch RedisError and re-raise it - the raised exception IS
|
||||||
docstring for its own contract. unwrapped ops go through the raw `.client` escape
|
the signal, and the caller (which alone knows fatal-vs-routine) decides and logs; the
|
||||||
hatch: full driver surface, raises.
|
wrapped method logs only at DEBUG (with the traceback) so a failure isn't reported
|
||||||
|
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
|
||||||
@@ -87,7 +89,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
await self._client.ping()
|
await self._client.ping()
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.connect() ping failed")
|
log.debug("redis.connect() ping failed", exc_info=True)
|
||||||
await self._pool.disconnect()
|
await self._pool.disconnect()
|
||||||
raise
|
raise
|
||||||
return self
|
return self
|
||||||
@@ -104,7 +106,7 @@ class RedisDB:
|
|||||||
finally:
|
finally:
|
||||||
await self._pool.disconnect()
|
await self._pool.disconnect()
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.close()")
|
log.debug("redis.close()", exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def __aenter__(self) -> "RedisDB":
|
async def __aenter__(self) -> "RedisDB":
|
||||||
@@ -128,7 +130,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.get(key)
|
return await self._client.get(key)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.get(%s)", key)
|
log.debug("redis.get(%s)", key, exc_info=True)
|
||||||
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:
|
||||||
@@ -136,7 +138,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.exception("redis.set(%s)", key)
|
log.debug("redis.set(%s)", key, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def delete(self, *keys: str) -> int:
|
async def delete(self, *keys: str) -> int:
|
||||||
@@ -144,7 +146,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.delete(*keys)
|
return await self._client.delete(*keys)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.delete(%s)", keys)
|
log.debug("redis.delete(%s)", keys, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def exists(self, *keys: str) -> int:
|
async def exists(self, *keys: str) -> int:
|
||||||
@@ -152,7 +154,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.exists(*keys)
|
return await self._client.exists(*keys)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.exists(%s)", keys)
|
log.debug("redis.exists(%s)", keys, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def incr(self, key: str, amount: int = 1) -> int:
|
async def incr(self, key: str, amount: int = 1) -> int:
|
||||||
@@ -160,7 +162,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.incrby(key, amount)
|
return await self._client.incrby(key, amount)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.incr(%s)", key)
|
log.debug("redis.incr(%s)", key, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def decr(self, key: str, amount: int = 1) -> int:
|
async def decr(self, key: str, amount: int = 1) -> int:
|
||||||
@@ -168,7 +170,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.decrby(key, amount)
|
return await self._client.decrby(key, amount)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.decr(%s)", key)
|
log.debug("redis.decr(%s)", key, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hget(self, name: str, field: str) -> Optional[str]:
|
async def hget(self, name: str, field: str) -> Optional[str]:
|
||||||
@@ -176,7 +178,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hget(name, field)
|
return await self._client.hget(name, field)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.hget(%s, %s)", name, field)
|
log.debug("redis.hget(%s, %s)", name, field, exc_info=True)
|
||||||
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:
|
||||||
@@ -187,7 +189,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.exception("redis.hset(%s)", name)
|
log.debug("redis.hset(%s)", name, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hgetall(self, name: str) -> dict:
|
async def hgetall(self, name: str) -> dict:
|
||||||
@@ -195,7 +197,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hgetall(name)
|
return await self._client.hgetall(name)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.hgetall(%s)", name)
|
log.debug("redis.hgetall(%s)", name, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def hdel(self, name: str, *fields: str) -> int:
|
async def hdel(self, name: str, *fields: str) -> int:
|
||||||
@@ -203,7 +205,7 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.hdel(name, *fields)
|
return await self._client.hdel(name, *fields)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.hdel(%s)", name)
|
log.debug("redis.hdel(%s)", name, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def expire(self, key: str, seconds: int) -> bool:
|
async def expire(self, key: str, seconds: int) -> bool:
|
||||||
@@ -211,7 +213,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.exception("redis.expire(%s)", key)
|
log.debug("redis.expire(%s)", key, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def ttl(self, key: str) -> int:
|
async def ttl(self, key: str) -> int:
|
||||||
@@ -223,5 +225,5 @@ class RedisDB:
|
|||||||
try:
|
try:
|
||||||
return await self._client.ttl(key)
|
return await self._client.ttl(key)
|
||||||
except RedisError:
|
except RedisError:
|
||||||
log.exception("redis.ttl(%s)", key)
|
log.debug("redis.ttl(%s)", key, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user