问题标签 [redis-py]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - Terminate a hung redis pubsub.listen() thread
Related to this question I have the following code which subscribes to a redis pubsub queue and uses the handler provided in __init__ to feed the messages to the class that processes them:
In the linked question above, it is noted that pubsub.listen()
never returns if the connection is dropped. Therefore, my die()
function, while it can be called, will never actually cause the thread to terminate because it is hanging on the call to listen()
inside the thread's run()
.
The accepted answer on the linked question mentions hacking redis-py's connection pool. I really don't want to do this and have a forked version of redis-py (at least until the fix is hopefully accepted into master), but I've had a look at the redis-py code anyway and don't immediately see where this change would be made.
Does anyone have an idea how to cleanly solve the hanging redis-py listen()
call?
What issues will I incur by directly using Thread._Thread__stop
?
redis - redis 客户端管道在 twemproxy 环境中不起作用
我使用redis-py对redis进行操作,我们的环境使用twemproxy作为redis代理。但是当连接到 twemproxy 时,看起来 clinet 管道不起作用。
执行方法时抛出异常
在 twemproxy 环境中,客户端管道不起作用还是 redis-py 的问题?
python - Redis Python - how to delete all keys according to a specific pattern In python, without python iterating
I'm writing a django management command to handle some of our redis caching. Basically, I need to choose all keys, that confirm to a certain pattern (for example: "prefix:*") and delete them.
I know I can use the cli to do that:
But I need to do this from within the app. So I need to use the python binding (I'm using py-redis). I have tried feeding a list into delete, but it fails:
# And now
# returns 0 . nothing is deleted
I know I can iterate over x:
But that would be losing redis awesome speed and misusing its capabilities. Is there a pythonic solution with py-redis, without iteration and/or the cli?
Thanks!
python - 使用 redis.StrictRedis() 在 redis 中插入一个新数据库
我知道 Redis 默认有 16 个数据库,但是如果我需要添加另一个数据库,我该如何使用 redis-py 呢?
redis - Redis-python 在一次操作中设置多个键/值
目前我使用基本mset
功能来存储键/值;
我单独存储每个键/值(例如,不在一个 json 中)因为存储整个 dict 会将其转换为字符串,并且需要我在存储和检索时序列化/反序列化,我真的需要访问单独的键/值。
我的问题::有没有办法一次可以mset
多个键/值?而不是多次写入redis db?反之亦然,我可以在一次访问中进行多次读取(获取)吗?(是的 - 我有很多 redis 活动正在进行并且负载很重。我确实关心这个)
python - 使用 redis-py 的复杂对象
我一直在使用 redis-cli 来了解 redis 的工作原理。我知道使用这个工具我可以做到这一点:
我似乎无法弄清楚如何使用 redis-py 来实现这一点。提供的命令似乎set
不允许对象类型或 ID。谢谢你的帮助。
python - Flask 应用程序不会在浏览器中加载
我刚刚开始使用flask,正在尝试使用redis构建教程微博。这是我的应用程序:
当我跑步时,python testapp.py
我得到
但是,该页面永远不会加载,http://127.0.0.1:5000/
也不会返回错误。它只是挂起,试图永远加载。我已经离开它一段时间了,它还在继续。我不确定是什么原因造成的,但感谢您的帮助。
更新:我print
在视图中添加了几条语句,index
以查看代码运行时发生的情况,这是打印到终端的内容。
python - redis-py AttributeError:“PubSub”对象没有属性“get_message”
我在 Windows 命令行中编写代码。该代码仅来自 Redis-py 的GitHub 页面。
我不知道这是怎么回事,所以我。
结果是:
我找不到“get_message”。我的 redis 版本是-2.9.1。
python-3.x - redis-py 和 hgetall 行为
我玩过烧瓶微框架,并想在 redis 中缓存一些统计信息。假设我有这个字典:
我把它保存到redis
不过还原后
我觉得很奇怪{b'test': b'test11'}
,所以stored.get("test")
给了我 None
mydict
str 方法结果看起来不错{'test': 'test11'}
。那么,为什么要将这个二进制标记添加到恢复的数据中呢?我还检查了 redis-cli 并没有在那里看到明确的 b 标记。hgetall 有问题吗?
python - 如何在redis-py中设置redis超时等待管道响应?
在下面的代码中,管道超时是 2 秒吗?
在redis中,集合“key”中有很多成员。它总是返回错误,如下所示,代码最后:
如果我将 socket_timeout 值修改为 10,它会返回 ok。
参数“socket_timeout”不是表示连接超时吗?但它看起来像响应超时。
redis-py 版本是 2.6.7。