私のpythonプロジェクトでredis 2.8.4を使用しています。zadd
特定のソート済みセットで、nx
オプションを使用したい。このnx
オプションはredis-py docs に記載されておらず、 docsによると、redis 3.0.2 以降でのみ機能します。
nx
では、実行時にオプションをシミュレートするために従うことができる代替パターンは何zadd
ですか?
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.
私はgithubの問題で解決策を見つけました:
redis.execute_command('ZADD', set_name, 'NX', score, key)