Lor*_*lli 5 synchronization redis
我有多个作者覆盖了 redis 中的同一个键。我如何保证只有被选中的人写最后?
我可以在 Redis 中执行写同步而不先同步编写器吗?
背景:在我的系统中,一个独特的调度员将工作发送给不同的工人。然后每个工作人员将结果写入 Redis 并覆盖相同的键。我需要确保只有从调度程序接收工作的最后一个工人在 Redis 中写入。
使用有序集 ( ZSET ):添加分数等于 unix 时间戳的条目,然后删除除最高排名之外的所有条目。
\n\nRedis有序集是一个集合,其中每个条目也有一个分数。集合按照分数进行排序,元素在有序集合中的位置称为Rank。
\n\n为了:
\n\npython 中的示例:
\n\n# timestamp contains the time when the dispatcher sent a message to this worker\nkey = "key_zset:%s"%id\npipeline = self._redis_connection.db.pipeline(transaction=True)\npipeline.zremrangebyscore(key, 0, t) \xc2\xa0# Avoid duplicate Scores and identical data\npipeline.zadd(key, t, "value")\npipeline.zremrangebyrank(key, 0, -2)\npipeline.execute(raise_on_error=True)\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4676 次 |
| 最近记录: |