22 lines
635 B
Python
22 lines
635 B
Python
import redis # type: ignore
|
|
from protocols.models import KeyDTO
|
|
from protocols.repository import Repository
|
|
|
|
|
|
class RedisRepository(Repository):
|
|
def __init__(self, redis_pool: redis.Redis) -> None:
|
|
self.pool = redis_pool
|
|
|
|
def get_key(self, obj: KeyDTO) -> KeyDTO | None:
|
|
data = self.pool.get(obj.key)
|
|
if not data:
|
|
return None
|
|
return KeyDTO(key=obj.key, val=str(data))
|
|
|
|
def add_key(self, obj: KeyDTO) -> KeyDTO:
|
|
self.pool.set(obj.key, obj.val)
|
|
return KeyDTO(key="3", val="4")
|
|
|
|
def put_key(self, obj: KeyDTO) -> KeyDTO:
|
|
return KeyDTO(key="5", val="6")
|