initial
This commit is contained in:
30
BaseLib/redis.py
Normal file
30
BaseLib/redis.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import redis
|
||||
|
||||
from allinvest import settings
|
||||
|
||||
|
||||
class RedisClient:
|
||||
|
||||
def __init__(self, host, db=1, password=None):
|
||||
kwargs = {
|
||||
"host": host,
|
||||
"db": db
|
||||
}
|
||||
if password:
|
||||
kwargs['password'] = password
|
||||
self.cli = redis.Redis(**kwargs)
|
||||
|
||||
def get(self, key):
|
||||
with self.cli as cli:
|
||||
return cli.get(key)
|
||||
|
||||
def set(self, key, value):
|
||||
with self.cli as cli:
|
||||
cli.set(key, value)
|
||||
|
||||
|
||||
redis_client = RedisClient(
|
||||
settings.REDIS_HOST,
|
||||
settings.REDIS_DB,
|
||||
settings.REDIS_PASSWORD
|
||||
)
|
Reference in New Issue
Block a user