Migrated from keys to set datastructure in Redis

This commit is contained in:
2021-11-04 20:05:48 +01:00
parent 3c9772b8f1
commit c54f54ef47
5 changed files with 29 additions and 23 deletions
+18 -7
View File
@@ -1,20 +1,31 @@
from aioredis import Redis
from typing import Sequence
from typing import Dict, List, Optional
from bot import redis_prefix
class AutoJoin:
@staticmethod
async def get_channels(redis: Redis) -> Sequence[tuple]:
async def get_channels(redis: Redis) -> Dict[str, str]:
# return all channels
channels = await redis.hgetall(name="autojoin")
channels = await redis.hgetall(f"{redis_prefix}:autojoin")
return {key: value.split("-") for key, value in channels.items()}
@staticmethod
async def update_channel(redis: Redis, guild_id, voicechannel_id, textchannel_id):
async def update_channel(
redis: Redis, guild_id: int, voice_channel_id: int, text_channel_id: int
):
await redis.hset(
name="autojoin", key=guild_id, value=f"{voicechannel_id}-{textchannel_id}"
f"{redis_prefix}:autojoin",
guild_id,
f"{voice_channel_id}-{text_channel_id}",
)
@staticmethod
async def del_channel(redis: Redis, guild_id):
await redis.hdel("autojoin", guild_id)
async def del_channel(redis: Redis, guild_id: int):
await redis.hdel(f"{redis_prefix}:autojoin", guild_id)
class Playlist:
@staticmethod
async def random(redis: Redis, amount: Optional[int] = 1) -> List[str]:
return await redis.srandmember(f"{redis_prefix}:playlist", amount)