Introduction to Redis Sorted Sets

Commands for Sorted Sets in Redis

 
  redis 127.0.0.1:6379> zadd game1 20 killer1
  (integer) 1
  
  redis 127.0.0.1:6379> zadd game1 14 killer2
  (integer) 1
  
  redis 127.0.0.1:6379> zadd game1 3 killer3
  (integer) 1
  
  redis 127.0.0.1:6379> zadd game1 3 killer4
  (integer) 1
  
  redis 127.0.0.1:6379> zrange game1 0 3
  1 "killer3"
  2 "killer4"
  3 "killer2"
  4 "killer1"
  
  redis 127.0.0.1:6379> zrange game1 0 3 withscores
  1 "killer3"
  2 "3"
  3 "killer4"
  4 "3"
  5 "killer2"
  6 "14"
  7 "killer1"
  8 "20"
  
  redis 127.0.0.1:6379> zrange game1 0 3
  1 "killer3"
  2 "killer4"
  3 "killer2"
  4 "killer1"
  
  redis 127.0.0.1:6379> zrevrange game1 0 3
  1 "killer1"
  2 "killer2"
  3 "killer4"
  4 "killer3"
  
  redis 127.0.0.1:6379> zrevrange game1 0 3 withscores
  1 "killer1"
  2 "20"
  3 "killer2"
  4 "14"
  5 "killer4"
  6 "3"
  7 "killer3"
  8 "3"
  
  redis 127.0.0.1:6379> zrevrange game1 0 6 withscores
  1 "killer1"
  2 "20"
  3 "killer2"
  4 "14"
  5 "killer4"
  6 "3"
  7 "killer3"
  8 "3"
  
  redis 127.0.0.1:6379> zadd game2 30 killer1 20 killer2
  (integer) 2
  
  redis 127.0.0.1:6379> zrange game2 0 1
  1 "killer2"
  2 "killer1"
  
  redis 127.0.0.1:6379> zrange game2 0 1 withscores
  1 "killer2"
  2 "20"
  3 "killer1"
  4 "30"
  
  redis 127.0.0.1:6379> zrevrank game1 killer1
  (integer) 0
  
  redis 127.0.0.1:6379> zrevrank game1 killer2
  (integer) 1
  
  redis 127.0.0.1:6379> zrevrank game1 killer3
  (integer) 3
  
  redis 127.0.0.1:6379> zrevrank game1 killer4
  (integer) 2
  
  redis 127.0.0.1:6379> zrange game1 0 3 withscores
  1 "killer3"
  2 "3"
  3 "killer4"
  4 "3"
  5 "killer2"
  6 "14"
  7 "killer1"
  8 "20"
  
  redis 127.0.0.1:6379> zrevrank game1 killer1
  (integer) 0
  
  redis 127.0.0.1:6379> zrevrank game1 killer4
  (integer) 2
  
  redis 127.0.0.1:6379> zrevrank game1 killer3
  (integer) 3
  
  redis 127.0.0.1:6379> zrevrank game1 killer2
  (integer) 1
  
  redis 127.0.0.1:6379> zscore game1 killer1
  "20"
  
  redis 127.0.0.1:6379> zscore game1 killer2
  "14"
  
  redis 127.0.0.1:6379> zrangebyscore game1 3 14
  1 "killer3"
  2 "killer4"
  3 "killer2"
  
  redis 127.0.0.1:6379> zrangebyscore game1 14 3
  (empty list or set)
  
  redis 127.0.0.1:6379> zrangebyscore game1 3 14
  1 "killer3"
  2 "killer4"
  3 "killer2"
  
  redis 127.0.0.1:6379> zrevrangebyscore game1 14 3
  1 "killer2"
  2 "killer4"
  3 "killer3"
  
  redis 127.0.0.1:6379> zrank game1 killer1
  (integer) 3
  
  redis 127.0.0.1:6379> zrank game1 killer3
  (integer) 0
  
  redis 127.0.0.1:6379> zincrby game1 3 killer4
  "6"
  
  redis 127.0.0.1:6379> zrange game1 0 3
  1 "killer3"
  2 "killer4"
  3 "killer2"
  4 "killer1"
  
  redis 127.0.0.1:6379> zrange game1 0 3 withscores
  1 "killer3"
  2 "3"
  3 "killer4"
  4 "6"
  5 "killer2"
  6 "14"
  7 "killer1"
  8 "20"
  
  redis 127.0.0.1:6379> zcard game1
  (integer) 4
  
  redis 127.0.0.1:6379> zcount game1 3 14
  (integer) 3
  
  redis 127.0.0.1:6379> zremrangebyscore game1 3 14
  (integer) 3
  
  redis 127.0.0.1:6379> zrange game1 0 1
  1 "killer1"