Introduction
ZADD lets you add items with scores to a sorted list in Redis. This helps keep things in order by score.
ZADD lets you add items with scores to a sorted list in Redis. This helps keep things in order by score.
ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
key is the name of the sorted set.
You add one or more score member pairs to the set.
ZADD leaderboard 100 player1ZADD tasks 5 taskA 10 taskB
ZADD leaderboard NX 150 player2This adds three players with scores to the 'leaderboard' and then lists all players with their scores in order.
ZADD leaderboard 50 Alice ZADD leaderboard 70 Bob ZADD leaderboard 60 Charlie ZRANGE leaderboard 0 -1 WITHSCORES
ZADD returns the number of new members added, not counting updated scores.
Scores are numbers and can be decimals.
Use ZRANGE with WITHSCORES to see members and their scores.
ZADD adds members with scores to a sorted set.
It keeps members sorted by score automatically.
You can add multiple members at once.
ZADD do?ZADD leaderboard 50 Alice 70 Bob 60 Charlie ZRANGE leaderboard 0 -1 WITHSCORES
ZADD myset player1 100Pass the test and this pattern moves unknown