3
0
Telegram_PaimonBot/defs/redis_load.py
Xtao_dada 5eeea30fdc
v0.1.0beta (#1)
*  支持生成原神黄历
*  支持每日副本查询
*  支持角色资料、命座查询
*  支持武器查询
2021-07-09 23:31:30 +08:00

30 lines
849 B
Python

from configparser import RawConfigParser
from os import getcwd, sep
from redis import StrictRedis
from redis.exceptions import RedisError
def get_redis_conf():
config = RawConfigParser()
config.read(f"{getcwd()}{sep}config.ini")
redis_host: str = "127.0.0.1"
redis_port: int = 6379
redis_db: int = 0
redis_host = config.get("redis", "host", fallback=redis_host)
redis_port = config.get("redis", "port", fallback=redis_port)
redis_db = config.get("redis", "db", fallback=redis_db)
return {'host': redis_host, 'port': redis_port, 'db': redis_db}
redis = StrictRedis(host=get_redis_conf()['host'],
port=get_redis_conf()['port'],
db=get_redis_conf()['db'])
def redis_status():
try:
redis.ping()
return True
except RedisError:
return False