2024-10-08 16:10:34 +00:00
|
|
|
import logging as log
|
2024-10-09 08:28:57 +00:00
|
|
|
from .r_helper import RedisManager
|
2024-10-08 16:10:34 +00:00
|
|
|
|
|
|
|
|
2024-10-09 08:28:57 +00:00
|
|
|
async def ping():
|
2024-10-08 21:14:07 +00:00
|
|
|
async with RedisManager() as redis_connect:
|
2024-10-09 08:28:57 +00:00
|
|
|
if redis_connect:
|
|
|
|
result = await redis_connect.client.ping()
|
|
|
|
log.info("Ping - %s", result)
|
|
|
|
return result
|
2024-10-08 16:10:34 +00:00
|
|
|
|
|
|
|
|
2024-10-09 08:28:57 +00:00
|
|
|
async def set_value(key, value):
|
2024-10-08 21:14:07 +00:00
|
|
|
async with RedisManager() as redis_connect:
|
2024-10-09 08:28:57 +00:00
|
|
|
if redis_connect:
|
|
|
|
await redis_connect.client.set(key, value)
|
|
|
|
log.info("Set %s = %s", key, value)
|
2024-10-08 21:14:07 +00:00
|
|
|
|
|
|
|
|
2024-10-09 08:28:57 +00:00
|
|
|
async def get_value(key):
|
|
|
|
async with RedisManager() as redis_connect:
|
|
|
|
if redis_connect:
|
|
|
|
value = await redis_connect.client.get(key)
|
|
|
|
log.info("Get %s = %s", key, value)
|
|
|
|
return value
|
2024-10-09 11:26:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def pop_value(key):
|
|
|
|
async with RedisManager() as redis_connect:
|
|
|
|
if redis_connect:
|
|
|
|
value = await redis_connect.client.getdel(key)
|
|
|
|
log.info("Get and delete %s = %s", key, value)
|
|
|
|
return value
|