What is ZADD used for?

0341

ZADD is a command used in Redis to add one or more members to a sorted set, or update the score of an existing member. Each member is associated with a score, which determines its position in the sorted set. The syntax for ZADD is as follows:

ZADD key score member [score member ...]
  • key: The name of the sorted set.
  • score: The score associated with the member.
  • member: The member to be added to the sorted set.

For example, to add members to a sorted set named "myset":

ZADD myset 1 "member1" 2 "member2"

This command adds "member1" with a score of 1 and "member2" with a score of 2 to the sorted set "myset". If "member1" already exists, its score will be updated to 1.

0 Comments

no data
Be the first to share your comment!