rename class RedisStore -> RedisDB (uniform <Backend>DB naming); v0.1.1

Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
2026-06-29 23:07:02 -04:00
parent 237e3ff765
commit b87e532f80
4 changed files with 17 additions and 17 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
from .redis_store import RedisStore
from .redis_store import RedisDB
__all__ = ["RedisStore"]
__all__ = ["RedisDB"]
+7 -7
View File
@@ -2,14 +2,14 @@
async redis wrapper over redis-py's asyncio client
object pattern (one client per process), attach to the app:
from redis_store import RedisStore
app.kv = await RedisStore(host="localhost", port=6379, db=0).connect()
from redis_store import RedisDB
app.kv = await RedisDB(host="localhost", port=6379, db=0).connect()
await app.kv.set("user:1:name", "ada", ex=3600)
name = await app.kv.get("user:1:name") # "ada"
await app.kv.close() # on shutdown
context manager:
async with RedisStore(host="localhost") as kv:
async with RedisDB(host="localhost") as kv:
await kv.incr("hits")
lifecycle:
@@ -45,7 +45,7 @@ from redis.exceptions import RedisError
log = logging.getLogger(__name__)
class RedisStore:
class RedisDB:
"""async redis wrapper; one client per process, attach as app.kv"""
def __init__(
@@ -84,11 +84,11 @@ class RedisStore:
)
self._client = redis.Redis(connection_pool=self._pool)
async def connect(self) -> "RedisStore":
async def connect(self) -> "RedisDB":
"""open + validate the connection with a ping; fail loud on bad config
returns self so callers can write
`kv = await RedisStore(...).connect()`.
`kv = await RedisDB(...).connect()`.
"""
try:
await self._client.ping()
@@ -106,7 +106,7 @@ class RedisStore:
log.exception("redis.close()")
raise
async def __aenter__(self) -> "RedisStore":
async def __aenter__(self) -> "RedisDB":
return await self.connect()
async def __aexit__(self, exc_type, exc, tb) -> None: