ZINTER

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

Compute the intersection

Usage: zinter 2 src_key1 src_key2.
Each member score is added by default if not specified.

src_key1 ={ (1,A),(2,B),(3,C)}
src_key2 = {(4,B),(5,C)(6,D)}
Result = {(6,B),(8,C)}

Example

Command>zinter 2 src_key1 src_key2 withscores
Result> 1) "B"
2) "6"
3) "C"
4) "8"

Using weights

Usage: zinter 2 src_key1 src_key2 weights 2 3.
The first weight 2 is multiplied by each score of src_key1, and the second weight 3 is multiplied by each score of src_key2.

src_key1 ={ (1,A),(2,B),(3,C) } ->{ (2*2,B)(3*2,C) }
src_key2 ={ (4,B),(5,C),(6,D) }->{ (4*3,B)(5*3,C) }
Result ={ (4+12,B)(6+15,C) }
={ (16,B)(21,C) }

Example

Command>zinter 2 src_key1 src_key2 weights 2 3 withscores
Result> 1) "B"
2) "16"
3) "C"
4) "21"

Using aggregate

Usage: zinter 2 src_key1 src_key2 aggregate sum|min|max.
sum adds the scores. If aggregate is omitted, sum is the default.
min takes the smaller score of each member, and max takes the larger score.

src_key1 ={ (1,A),(2,B),(3,C) }
src_key2 ={ (4,B),(5,C),(6,D) }
aggregate min = {(2,B),(3,C) }
aggregate max = {(4,B),(5,C) }

Example

Command>zinter 2 src_key1 src_key2 aggregate min withscores
Result> 1) "B"
2) "2"
3) "C"
4) "3"
Command>zinter 2 src_key1 src_key2 aggregate max withscores
Result> 1) "B"
2) "4"
3) "C"
4) "5"


Syntax

ZINTER numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]

  • Available since version 6.2.0.
  • Time complexity is O(N*K)+O(M*log(M)).
Related commands ZUNION, ZDIFF

<< ZUNION ZINTER ZDIFF >>

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