class RedisClient(object):
def __init__(self):
super(RedisClient, self).__init__()
host = settings[RedisConstant.REDIS_SERVER]
port = settings[RedisConstant.REDIS_PORT]
if host is None or port is None:
raise ValueError
self.redis = redis.Redis(host, port, db=0)
def rpush(self, key, value):
self.redis.rpush(key, value)
def sadd(self, key, value):
self.redis.sadd(key, value)
def lpop(self, key):
return self.redis.lpop(key)
rpush和lpop为List的操作,sadd为set的操作
item = {
'market': self.market,
'country': country,
'device': device,
'data': data,
'date': time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
}
self.result_client.rpush(Constant.REDIE_TREND, pickle.dumps(item, protocol=2))
此处我们将python字典item序列化之后存进redis