Files
Wu Clan 5e438c685d Refactor the backend architecture (#299)
* define the basic architecture

* Update script and deployment file locations

* Update the route registration

* Fix CI download dependencies

* Updated ruff to 0.3.3

* Update app subdirectory naming

* Update the model import

* fix pre-commit pdm lock

* Update the service directory naming

* Add CRUD method documents

* Fix the issue of circular import

* Update the README document

* Update the SQL statement for create tables

* Update docker scripts and documentation

* Fix docker scripts

* Update the backend README.md

* Add the security folder and move the redis client

* Update the configuration item

* Fix environment configuration reads

* Update the default configuration

* Updated README description

* Updated the user registration API

* Fix test cases

* Update the celery configuration

* Update and fix celery configuration

* Updated the celery structure

* Update celery tasks and api

* Add celery flower

* Update the import style

* Update contributors
2024-03-22 18:16:15 +08:00

34 lines
1.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from backend.database.db_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()