blob: 7d59d8d55c61c3815600ace39f13dae85d7b31a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# -*- coding: utf-8 -*-
import redis
class Client(object):
def __init__(self, **kwargs):
self.connection_settings = kwargs or {'host': 'localhost', 'port': 6379, 'db': 0}
def redis(self):
return redis.Redis(**self.connection_settings)
def update(self, d):
self.connection_settings.update(d)
def connection_setup(**kwargs):
global connection, client
if client:
client.update(kwargs)
else:
client = Client(**kwargs)
connection = client.redis()
def get_client():
global connection
return connection
client = Client()
connection = client.redis()
__all__ = ['connection_setup', 'get_client']
|