zincrby
ZINCRBY
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Increment or decrement a score
Usage: zincrby key increment member.
increment can be an integer, a float, or a negative number.
Returns the updated score
Example
| Command> | zadd mysite 1000 google.com 900 facebook.com 800 youtube.com |
| Result> | 3 |
| Command> | zrevrange mysite 0 -1 withscores |
| Result> |
0) 1000 -> google.com 1) 900 -> facebook.com 2) 800 -> youtube.com |
| Command> | zincrby mysite 150 youtube.com Increase youtube.com by 150 |
| Result> | 950 |
| Command> | zrevrange mysite 0 -1 withscores |
| Result> |
0) 1000 -> google.com 1) 950 -> youtube.com Increased to 950, so the ranking changed 2) 900 -> facebook.com |
| Command> | zincrby mysite -60 google.com Decrease |
| Result> | 940 |
| Command> | zrevrange mysite 0 -1 withscores |
| Result> |
0) 950 -> youtube.com 1) 940 -> google.com 2) 900 -> facebook.com |
Floating-point values are allowed
For floats, many decimal digits may be shown as below.
Example
| Command> | zadd unemp 3.7 Korea 8.1 OECD 9.9 France 5.3 Germany 6.3 USA |
| Result> | 5 |
| Command> | zrevrange mysite 0 -1 withscores |
| Result> |
0) 3.7000000000000002 -> Korea 1) 5.2999999999999998 -> Germany 2) 6.2999999999999998 -> USA 3) 8.0999999999999996 -> OECD 4) 9.9000000000000004 -> France |
| Command> | zincrby unemp 1.5 Korea |
| Result> | 5.2000000000000002 |
| Unemployment rates by country |
Create the key and member
If the key or member does not exist, it is created. The starting score is 0.0.
Example
| Command> | zincrby daily_views 1 20160401 Create the key and member and store them |
| Result> | 1 |
| Command> | zincrby daily_views 1 20160401 |
| Result> | 2 |
| Command> | zincrby daily_views 1 20160401 |
| Result> | 3 |
| Command> | zincrby daily_views 1 20160402 The key already exists, so only the member is created |
| Result> | 1 |
| Command> | zincrby daily_views 1 20160402 |
| Result> | 2 |
| Command> | zrevrange daily_views 0 -1 withscores |
| Result> |
0) 2 -> 20150402 1) 3 -> 20150401 |
| Example) daily page views |
Syntax
ZINCRBY key increment member
- Available since version 1.2.0.
- Time complexity is O(log(N)). N is the number of members in the set.
| Related commands | INCR, INCRBY, INCRBYFLOAT, HINCRBY |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << ZADDS | ZINCRBY | ZRANGE >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
