ZADDS (subquery)

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Subquery feature

You can put a subquery in the member argument.
Commands allowed as a subquery: GET, MGET, LPOP, RPOP, LRANGE, SMEMBERS, SUNION, SINTER, SDIFF, ZRANGE, ZREVRANGE, HGET, HMGET, HKEYS, HVALS, HGETALL, LS.
In most cases the score is 0, so members are sorted by member.

Example

Command>set key Hello
Result>OK
Command>zadds zset1 (get key)
Result>1
Command>zrange zset1 0 -1 withscores
Result>1) "Hello"
2) "0"
  • You can load multiple values using various subquery commands.
  • Useful when you want to sort LIST or SET members.
  • ZRANGE and ZREVRANGE with withscores can supply scores.
  • LS with memory sorts by memory so you can find keys that use a lot of RAM. LS with len finds keys with many or few members.

Example

Command>zadds zset1 (lrange mylist2 0 -1)
Result>8
Command>zadds zset1 (sunion myset1 myset2)
Result>7
Command>zadds zset1 (zrange myzset1 0 -1)
Result>6
Command>zadds zset1 (zrange myzset2 0 -1 withscores)
Result>6
Command>zadds zset1 (hmget myhash1 field1 field2)
Result>2
Command>zadds zset1 (ls * memory)
Result>2
Command>zadds zset1 (ls * len)
Result>2
Command>zadds zset1 (ls * zset memory)
Result>2

  • Only one subquery is allowed.
  • Available since Enterprise version 7.2.5.

    Automatic member expire

    It also works with a subquery.

    Example

    Command>zadds myzset (get key) ex 10
    Result>1
    Command>zadds myzset (lrange mylist 0 -1) ex 10
    Result>10

    Syntax

    ZADDS key (subquery)   [ex seconds]

    • Available since Enterprise version 7.2.5.
    • Time complexity depends on the subquery.

    << ZADD ZADDS ZINCRBY >>

    Email 답글이 올라오면 이메일로 알려드리겠습니다.