ZRANGEBYSCORE


Returns all the elements in the sorted set at key with a score between min and max [min and max can be -inf and +inf]


redis> ZADD myzset 1 "one"
(integer) 1
redis> ZADD myzset 2 "two"
(integer) 1
redis> ZADD myzset 3 "three"
(integer) 1
redis> ZRANGEBYSCORE myzset -inf +inf
1) "one"
2) "two"
3) "three"
redis> ZRANGEBYSCORE myzset 1 2
1) "one"
2) "two"
redis> ZRANGEBYSCORE myzset (1 2
1) "two"
redis> ZRANGEBYSCORE myzset (1 (2
(empty list or set)
redis>



ZADD + ZRANGE


ZADD permette di aggiungere un < chiave,valore > ad un sorted set, bisogna quindi specificare lo score

ZADD mycolorset 1 white
ZADD mycolorset 2 black
ZADD mycolorset 3 red

ZRANGE Redis ZRANGE command is used to return the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score. Both start and stop are zero-based indexes, 0 is the first element, 1 is the next element and so on. They can also be negative numbers indicating offsets from the end of the sorted set:

  • -1 being the last element of the sorted set
  • -2 the penultimate element and so on.


127.0.0.1:6379> ZRANGE colors 0 -1
1) "white"
2) "brown"
3) "red"


Esempio con le città

ZADD mycity 1 Delhi 2 London 3 Paris 4 Tokyo 5 NewYork 6 Seoul

127.0.0.1:6379> ZRANGE mycity 0 -1
1) "Delhi"
2) "London"
3) "Paris"
4) "Tokyo"
5) "NewYork"
6) "Seoul"

127.0.0.1:6379> zrange mycity 0 0 // PRIMO
1) "Delhi"
127.0.0.1:6379> zrange mycity -1 -1 // ULTIMO
1) "Seoul"
127.0.0.1:6379> zrange mycity -2 -2 // PENULTIMO
1) "NewYork"



ZRANGEBYLEX

Indice lessicografico ZRANGEBYLEX. Valid start and stop must start with ( or [, in order to specify if the range item is respectively exclusive or inclusive


ZADD movies 1 1984:09.30:LeAliDellaLiberta
ZADD movies 2 1974:09.00:IlPadrinoParteII
ZADD movies 1 1975:08.07:QualcunoVoloSulNidoDelCuculo
ZADD movies 3 1994:08.08:ForrestGump
ZADD movies 4 1995:07.00:Braveheart

Lista dei film che sono usciti nel 1994

127.0.0.1:6379> ZRANGEBYLEX movies [1994 (1995
1) "1994:08.08:ForrestGump"

Lista dei film che sono usciti tra il 1990 e 2000 (escuso)

127.0.0.1:6379> ZRANGEBYLEX movies [1990 (2000
1) "1994:08.08:ForrestGump"
2) "1995:07.00:Braveheart"


QUALCOSA CHE NON VA



127.0.0.1:6379> ZRANGEBYLEX movies [1970 (1995
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
2) "1984:09.30:LeAliDellaLiberta"
3) "1974:09.00:IlPadrinoParte2"
4) "1974:09.00:IlPadrinoParteII"
5) "1994:08.08:ForrestGump"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1976
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1979
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1980
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1981
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1982
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1983
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1984
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
127.0.0.1:6379> ZRANGEBYLEX movies [0000 (1985
1) "1975:08.07:QualcunoVoloSulNidoDelCuculo"
2) "1984:09.30:LeAliDellaLiberta"
3) "1974:09.00:IlPadrinoParte2"
4) "1974:09.00:IlPadrinoParteII"



HMSET

127.0.0.1:6379> HMSET langhash lang1 "PHP" lang2 "JavaScript" lang3 "Redis"
OK
127.0.0.1:6379> HGET langhash lang1
"PHP"
127.0.0.1:6379> HGET langhash lang2
"JavaScript"
127.0.0.1:6379> HGET langhash lang3
"Redis"



SINTER

Returns the members of the set resulting from the intersection of all the given sets. For example:

  • key1 = {a,b,c,d}
  • key2 = {c}
  • key3 = {a,c,e}

SINTER key1 key2 key3 = {c}


(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SINTER key1 key2
1) "c"



SDIFF

Returns the members of the set resulting from the difference between the first set and all the successive sets.

  • key1 = {a,b,c,d}
  • key2 = {c}
  • key3 = {a,c,e}

SDIFF key1 key2 key3 = {b,d}


redis> SADD key1 "a"
(integer) 1
redis> SADD key1 "b"
(integer) 1
redis> SADD key1 "c"
(integer) 1
redis> SADD key2 "c"
(integer) 1
redis> SADD key2 "d"
(integer) 1
redis> SADD key2 "e"
(integer) 1
redis> SDIFF key1 key2
1) "b"
2) "a"