2

我在我的一个 python 项目中使用 redis 2.8.4。在特定的排序集中,我想zadd使用该nx选项。redis-pynx文档中没有记录该选项,并且根据文档,它仅适用于 redis 3.0.2 或更高版本。

那么我可以遵循什么替代模式来模拟nx选项zadd

4

2 回答 2

0

The most efficient pattern that comes to my mind is using using zscore (or zrank) to test for existence. If value exists, do nothing, otherwise, zadd the relevant value.

于 2016-12-16T17:26:45.397 回答
0

我在github 问题中找到了解决方案:

redis.execute_command('ZADD', set_name, 'NX', score, key)
于 2018-08-17T11:45:57.713 回答