sadd_subquery
SADDS (subquery)
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Subquery feature
You can insert values by using a subquery in the member part.
Commands that can be used as a subquery are GET, MGET, LPOP, RPOP, LRANGE,
SMEMBERS, SUNION, SINTER, SDIFF, ZRANGE, ZREVRANGE,
HGET, HMGET, HKEYS, HVALS, HGETALL.
Example
| Command> | set key Hello |
| Result> | OK |
| Command> | sadds myset (get key) |
| Result> | 1 |
| Command> | smembers myset |
| Result> | 1) "Hello" |
Example
| Command> | sadds myset (lrange mylist2 0 -1) |
| Result> | 8 |
| Command> | sadds myset (sunion myset1 myset2) |
| Result> | 7 |
| Command> | sadds myset (zrange myzset1 0 -1) |
| Result> | 6 |
| Command> | sadds myset (hmget myhash1 field1 field2) |
| Result> | 2 |
Example
| Command> | sadds myset (lrange mylist2 0 -1) (sunion myset1 myset2) value1 |
| Result> | 16 |
| Available since Enterprise version 7.2.5 . |
Automatic member deletion (set expire time)
You can also use this with a subquery.
Example
| Command> | sadds myset (get key) ex 10 |
| Result> | 1 |
| Command> | sadds myset (lrange mylist 0 -1) ex 10 |
| Result> | 10 |
Note: If the member already exists, it is omitted from the return value, but expire is still applied. That is, if myset already has mem1, sadd myset mem1 ex 10 returns 0, but ex 10 is applied. This also applies to subqueries.
Syntax
SADDS key (subquery) [ex seconds]
- Available since Enterprise version 7.2.5.
- Time complexity depends on the subquery.
| << SADD | SADDS | SREM >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
