bot.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:dogbot 作者: slice 项目源码 文件源码
def is_global_banned(self, user: discord.User) -> bool:
        key = f'cache:globalbans:{user.id}'

        if await self.redis.exists(key):
            # use the cached value instead
            return await self.redis.get(key, encoding='utf-8') == 'banned'

        async with self.pgpool.acquire() as conn:
            # grab the record from postgres, if any
            banned = (await conn.fetchrow('SELECT * FROM globalbans WHERE user_id = $1', user.id)) is not None

            # cache the banned value for 2 hours
            await self.redis.set(key, 'banned' if banned else 'not banned', expire=7200)

            # return whether banned or not
            return banned
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号