22 lines
727 B
Python
22 lines
727 B
Python
import aioredis
|
|
import json
|
|
|
|
class DeviceService:
|
|
def __init__(self):
|
|
self.redis = aioredis.from_url("redis://localhost")
|
|
|
|
async def get_device_connection(self, user_id):
|
|
"""获取设备连接信息"""
|
|
key = f"device_connection:{user_id}"
|
|
return await self.redis.get(key)
|
|
|
|
async def set_device_connection(self, user_id, connection_info):
|
|
"""设置设备连接信息"""
|
|
key = f"device_connection:{user_id}"
|
|
await self.redis.set(key, json.dumps(connection_info))
|
|
|
|
async def remove_device_connection(self, user_id):
|
|
"""移除设备连接信息"""
|
|
key = f"device_connection:{user_id}"
|
|
await self.redis.delete(key)
|