Files
Meepoljdx 78dad3021a Add postgresql database support (#475)
* feat: add postgresql db supports

* change: change mysql conn str create way

* fix: Modify the default alembic migration file to meet multi-database support

* Update settings and lint

* update models

* Simplify database config

* Simplify the get db method

* Update create db url

* Updated model type adaptation

* Update sql scripts

* Fix models type

* Adaptation to postgresql code generation

* Update README.md

* Fix alembic file template

* Update docker scripts
2024-12-25 22:04:04 +08:00

34 lines
1.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from backend.database.redis import redis_client
from backend.utils.server_info import server_info
class RedisInfo:
@staticmethod
async def get_info():
info = await redis_client.info()
fmt_info = {}
for key, value in info.items():
if isinstance(value, dict):
value = ','.join({f'{k}={v}' for k, v in value.items()})
else:
value = str(value)
fmt_info[key] = value
db_size = await redis_client.dbsize()
fmt_info.update({'keys_num': db_size})
fmt_uptime = server_info.fmt_seconds(fmt_info.get('uptime_in_seconds', 0))
fmt_info.update({'uptime_in_seconds': fmt_uptime})
return fmt_info
@staticmethod
async def get_stats():
stats_list = []
command_stats = await redis_client.info('commandstats')
for k, v in command_stats.items():
stats_list.append({'name': k.split('_')[-1], 'value': str(v.get('calls', ''))})
return stats_list
redis_info: RedisInfo = RedisInfo()