# !/usr/bin/env python3
# -*- coding: utf-8 -*-
import redis
RedisConfig = dict(host='127.0.0.1', port=6379, db=1)
class RedisCache:
_instance = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = object.__new__(cls)
return cls._instance
_redis_pool_data = redis.ConnectionPool(decode_responses=True, **RedisConfig)
# 以管道方式运行redis
@classmethod
def get_pipe(cls):
conn = cls.get_conn()
return conn.pipeline(transaction=True)
# 实例化redis
@classmethod
def get_conn(cls):
conn = redis.StrictRedis(connection_pool=cls._redis_pool_data)
return conn