RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[redis]

Martin Hope
Rasim
Asked: 2022-08-01 14:26:54 +0000 UTC

执行任务发送短信时,任务打印到Celery控制台,不工作

  • 0

这是我的代码:

项目/__init__.py

from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ('celery_app',)

芹菜.py

from __future__ import absolute_import

import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

app = Celery("proj")
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

任务.py

@app.task
def send_sms_prompt_1_hour(order_id):
    order = HelpSession.objects.get(id=order_id)
    text_message = 'Текст сообщения'
    if not order or order.cancel_at:
        return
    sms.send_sms(order.client.phone, text_message)
    return None

短信.py

def send_sms(phone, msg):
    params = dict(
        login=settings.SMS_LOGIN, psw=settings.SMS_PASSWORD,
        phones=phone, charset='utf-8', mes=msg
    )
    if settings.DEBUG:
        logger.info(f'sending sms {params}')
    else:
        resp = requests.get('example_addres', params)
        if not resp.ok:
            raise Exception(resp.content)
        return resp.content

错误的本质是什么。发送短信本身是可以的,但是当通过 celery 调用 send_sms 函数时,它将以下文本输出到控制台

[31/May/2022 19:25:09,601] sending sms {'login': 'example', 'example': 'example', 'phones': 'example', 'charset': 'utf-8', 'mes': 'example'}

示例是我的文本不显示敏感信息。用正确的数据代替它。

我再说一遍,如果你不是通过 celery 调用这个函数,它可以正常工作

django redis
  • 1 个回答
  • 31 Views
Martin Hope
Coffee inTime
Asked: 2020-02-07 15:10:25 +0000 UTC

这个菜单在 Redis 中的实现有多正确?

  • 0

现在我将菜单存储在 Redis 中,每个菜单项都是一个单独的条目。每个菜单项与其父菜单(1 到 1)和子菜单(1 到多个)相关联。

创建菜单项如下所示:

  1. 我创建菜单项:

    HMSET menu_item:1 menu_title 主菜单

    HMSET menu_item:2 menu_title 我的个人资料

    HMSET menu_item:3 menu_title 我的统计

  2. 我告诉每个菜单它的“父”是谁(它总是 1)

    SADD 菜单项:1:父 0

    SADD 菜单项:2:父项 1

    SADD menu_item:3:parent 2

  3. 我向菜单项指出他们的“孩子”是谁,如果有的话(可能有几个)

    SADD menu_item:1:儿童 2

    SADDmenu_item:2:儿童 3

我在这个结构中遇到的问题是:

当我想向用户显示菜单时,我需要获取其父级 == 当前用户菜单项编号的所有菜单项。为此,我使用 获取当前菜单的“子项” SMEMBERS menu_item:1:childs,例如返回,{'4','2','6'}然后我必须创建一个管道,并在内部循环中依次获取每个子项HGETALL,然后排序使用 python 编程语言生成的数组(y 每个菜单项按自己的顺序)。

问题 我是否完全正确地实现了菜单,有没有办法做得更好,例如以某种方式避免管道中的循环,您必须依次选择每个元素?其实我需要经常对存储执行如下查询(我会用SQL举例)

如何在 SQL db 中获取特定菜单项的子项:

1) SELECT * FROM `menu_items` WHERE `parent_id` = 1 ORDER BY `position` ASC
redis
  • 1 个回答
  • 10 Views
Martin Hope
Coffee inTime
Asked: 2020-02-05 05:09:26 +0000 UTC

Redis为外部连接设置IP地址

  • 0

文档说:

By default, if no "bind" configuration directive is specified, Redis listens
for connections from all the network interfaces available on the server.
It is possible to listen to just one or multiple selected interfaces using
the "bind" configuration directive, followed by one or more IP addresses.

Examples:

bind 192.168.1.100 10.0.0.1
bind 127.0.0.1 ::1

但是,我绝对不清楚“绑定 192.168.1.100 10.0.0.1”和“绑定 127.0.0.1::1”是什么意思

为什么第一次绑定有两个IP,它给了什么?

为什么在第二个例子::1中,它给出了什么?

假设我为外部连接添加了一个 IP,如下所示:

bind 94.103.**.***

连接此IP时如何设置密码?

redis
  • 1 个回答
  • 10 Views
Martin Hope
quaresma89
Asked: 2020-01-24 17:19:42 +0000 UTC

redis 复制

  • 2

有 4 台服务器,在所有Redis副本上都已安装和配置。第一个服务器是主服务器和其他从服务器。当第一台服务器崩溃时,工作转到第二台。是否可以配置Redis为使下一个优先活动服务器成为主服务器?

redis
  • 2 个回答
  • 10 Views
Martin Hope
Stvlpotapov
Asked: 2020-03-01 20:58:15 +0000 UTC

神秘的 Sanic Redis

  • 0

连接我自己 sanic-redis

app = Sanic()
redis = SanicRedis(app)   

app.config.update(
    {
        'REDIS': {
            'address': ('0.0.0.0', 6379),
            # 'db': 0,
            # 'password': 'password',
            # 'ssl': None,
            # 'encoding': None,
            'minsize': 1,
            'maxsize': 10
        }
    }
)

我增加了每个请求的错误或成功计数器,但是对于每个请求,我都会捕获以下错误:

Connection <RedisConnection [db:0]> has pending commands, closing it.
Future exception was never retrieved
future: <Future finished exception=ConnectionForcedCloseError()>
aioredis.errors.ConnectionForcedCloseError
Future exception was never retrieved
future: <Future finished exception=ConnectionForcedCloseError()>
aioredis.errors.ConnectionForcedCloseError

同时,一切正常,没有磨损,总的来说,一切都很好。

问题:如何用萝卜打开非关闭连接?

async def count_statistic():
    await redis_client.incr_success_and_all_count_in_redis()
    now = time.time()
    last_timestamp = await redis_client.get_timestamp_from_redis()
    redis_client.time_to_response = now - redis_client.time_start_request
    await redis_client.incr_sum_time_response_in_redis(redis_client.time_to_response)
    await redis_client.put_timestamp_to_redis(now)
    ttl = await redis.conn.pttl('average_stats')
    if (now - last_timestamp < 60):
        try:
            all_count, sum_time_response = await redis_client.get_for_statistic()

            first_average = sum_time_response / all_count
        except TypeError:
            return 0

        with await redis.conn as r:
            r.hset(redis_client.key, 'first_average', first_average)
            r.hset('average_stats', 'average_per_minute', first_average)
        await redis.conn.expire('average_stats', 120)
    else:
        await redis_client.drop_data()
redis
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5