You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
712 B
30 lines
712 B
import redis
|
|
|
|
from ZhuQue.Config.config import Config
|
|
|
|
config = Config()
|
|
|
|
|
|
class RedisClient:
|
|
def __new__(cls, *args, **kwargs):
|
|
if not hasattr(cls, '_instance'):
|
|
cls._instance = redis.Redis(*args, **kwargs)
|
|
return cls._instance
|
|
|
|
|
|
def get_redis_connection():
|
|
# 配置 Redis 连接池
|
|
pool = redis.ConnectionPool(
|
|
host=config.get('Redis', 'HOST'), # Redis 服务器地址
|
|
port=int(config.get('Redis', 'PORT')), # Redis 服务器端口
|
|
db=0, # Redis 数据库索引
|
|
max_connections=20 # 连接池最大连接数
|
|
)
|
|
|
|
# 返回一个 Redis 客户端实例
|
|
return RedisClient(connection_pool=pool)
|
|
|
|
|
|
|
|
|