Skip to content

[Question]: Regarding the use of thread pools #5759

@lianwenke

Description

@lianwenke

Describe your problem

Why aren't thread pools used here

@singleton
class RedisDB:
def init(self):
self.REDIS = None
self.config = settings.REDIS
self.open()

# def __open__(self):
#     try:
#         self.REDIS = redis.StrictRedis(
#             host=self.config["host"],
#             port=int(self.config["port"]),
#             db=int(self.config["database"]),
#             password=self.config.get("password"),
#             decode_responses=True,
#         )
#     except Exception:
#         logging.warning("Redis can't be connected.")
#     return self.REDIS
def __open__(self):
    try:
        self.pool = redis.ConnectionPool(
            host=self.config["host"],
            port=int(self.config["port"]),
            db=int(self.config["database"]),
            password=self.config.get("password"),
            decode_responses=True,
            max_connections=100  # 设置最大连接数
        )
        self.REDIS = redis.StrictRedis(
            connection_pool=self.pool
        )
    except Exception:
        logging.warning("Redis can't be connected.")
    return self.REDIS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions