fix(bot): 🚑 Migrate to serverless redis.
This commit is contained in:
+5
-11
@@ -11,7 +11,7 @@ from discord.ext.commands import errors
|
||||
|
||||
from tortoise import expressions, transactions, exceptions as tortoise_exc
|
||||
|
||||
import redis.asyncio as aredis
|
||||
import upstash_redis.asyncio as aredis
|
||||
|
||||
import asyncpg.exceptions
|
||||
|
||||
@@ -30,11 +30,8 @@ class Payphone(commands.AutoShardedBot):
|
||||
log = logging.logger
|
||||
|
||||
redis: aredis.Redis = aredis.Redis(
|
||||
connection_pool=aredis.ConnectionPool(
|
||||
host="localhost" if config.IS_DEBUG else "redis.default.svc.cluster.local",
|
||||
socket_timeout=3,
|
||||
socket_connect_timeout=10
|
||||
)
|
||||
url="http://localhost:8079" if config.IS_DEBUG else "http://serverless-redis:8079",
|
||||
token="payphone"
|
||||
)
|
||||
|
||||
def __init__(self) -> None:
|
||||
@@ -310,12 +307,9 @@ class Payphone(commands.AutoShardedBot):
|
||||
|
||||
key = constants.PREFIX_TEMPLATE % server_id
|
||||
|
||||
prefix: bytes | None = await self.redis.get(key)
|
||||
prefix: str | None = await self.redis.get(key)
|
||||
|
||||
if prefix is not None:
|
||||
prefix = prefix.decode()
|
||||
|
||||
else:
|
||||
if prefix is None:
|
||||
server, _ = await models.Server.update_or_create(
|
||||
(
|
||||
{"name": message.guild.name}
|
||||
|
||||
@@ -819,7 +819,7 @@ class Calls(base.Cog):
|
||||
pipe.hset(
|
||||
constants.CALL_MESSAGE_REPLIES_TEMPLATE % call.id,
|
||||
replying_to_id,
|
||||
other_replies.decode() + f",{message.id}",
|
||||
other_replies + f",{message.id}",
|
||||
)
|
||||
|
||||
await pipe.execute()
|
||||
@@ -893,7 +893,7 @@ class Calls(base.Cog):
|
||||
if message_replies is None:
|
||||
return
|
||||
|
||||
for message_id in message_replies.decode().split(","):
|
||||
for message_id in message_replies.split(","):
|
||||
try:
|
||||
await webhook.edit_message(message_id, embed=None)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import discord
|
||||
|
||||
import orjson
|
||||
|
||||
import redis.asyncio as aredis
|
||||
import upstash_redis.asyncio as aredis
|
||||
|
||||
from payphone.db import models
|
||||
from payphone.core import constants, formatting
|
||||
|
||||
Reference in New Issue
Block a user