mirror of
https://github.com/fuckpiracyshield/data-storage.git
synced 2024-05-20 05:56:18 +02:00
35 lines
841 B
Python
35 lines
841 B
Python
from piracyshield_data_storage.database.redis.connection import DatabaseRedisConnection
|
|
|
|
class DatabaseRedisDocument(DatabaseRedisConnection):
|
|
|
|
def set_with_expiry(self, key: str, value: any, expiry: int) -> bool | Exception:
|
|
if self.instance.set(key, value, ex = expiry) == True:
|
|
return True
|
|
|
|
raise DatabaseRedisSetException()
|
|
|
|
def incr(self, key: str, amount: int = 1) -> bool | Exception:
|
|
return self.instance.incr(name = key, amount = amount)
|
|
|
|
def get(self, key: str) -> any:
|
|
return self.instance.get(key)
|
|
|
|
def delete(self, key: str) -> any:
|
|
return self.instance.delete(key)
|
|
|
|
class DatabaseRedisSetException(Exception):
|
|
|
|
"""
|
|
Cannot set the data.
|
|
"""
|
|
|
|
pass
|
|
|
|
class DatabaseRedisGetException(Exception):
|
|
|
|
"""
|
|
Cannot get the data.
|
|
"""
|
|
|
|
pass
|