ZBLOG

redis zadd

Redis ZADD command is used to add one or more members with their scores to a sorted set. The syntax of the command is:

ZADD key [NX|XX] [CH] [INCR] score member [score member …]

  • key: The name of the sorted set.
  • NX: Optional keyword that only adds new members and ignores the ones that already exist in the set.
  • XX: Optional keyword that only updates the scores of existing members and ignores the ones that do not exist in the set.
  • CH: Optional keyword that returns the number of changed members.
  • INCR: Optional keyword that increments the score of a member by the given value if it already exists in the set, or adds it with the given score if it does not exist.
  • score: The score associated with the member, which determines its position in the sorted set.
  • member: The member to add to the set.

Example usage:

ZADD myset 1 “one” ZADD myset 2 “two” ZADD myset 3 “three” 4 “four” ZADD myset NX 5 “five” XX 3 “three”

The above commands create a sorted set named “myset” and add members with their respective scores. The fourth command uses both NX and XX options to selectively add new and update existing members.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=1220

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?