Module Hub Beta

TOPK.ADD

key k ele [ele ...]

Adds one or more elements to a TopK Sorted Set.

k is the TopK Sorted Set’s maximal size. If k is zero, the TopK Sorted Set has no size limit.

Notes:

  • elem can’t begin with the prefix ‘TOPK’.
  • Using different a k from call to call is perfectly possible, and could be even interesting.

An error is returned when:

  • The Sorted Set isn’t a TopK.
  • The operation requires running TOPK.SHRINK before.

Return Value

Integer reply: if positive, it is the number of new elements added, if negative it is the number of elements removed due to k overflow, if 0 then only the offset was updated.

Examples

redis> TOPK.ADD tk 3 foo bar baz
(integer) 3
redis> TOPK.ADD tk 3 foo bar
(integer) 0
redis> TOPK.ADD tk 3 qaz
(integer) -1
redis> TOPK.ADD tk 3 qaz
(integer) 0

© 2017 Redis Labs, Inc. All rights reserved.