Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a ZSET in Redis database?

Tags:

redis

What is a zset in a redis database. I have a redis database with some data. In order to get the values

KEYS *apple*  1) "compleet-index:products:apple" 2) "compleet-index:brands:apple" 

after to get the key

GET  compleet-index:productos:apple 

and I had the response

(error) WRONGTYPE Operation against a key holding the wrong kind of value 

I get the type

TYPE  compleet-index:productos:iphone  zset 

When I make

DUMP  compleet-index:productos:iphone 

I obtain an exas codes.

like image 411
Rafa Cuestas Avatar asked Apr 22 '15 14:04

Rafa Cuestas


People also ask

How is Redis ZSET implemented?

ZSETs are ordered sets using two data structures to hold the same elements in order to get O(log(N)) INSERT and REMOVE operations into a sorted data structure. The elements are added to a hash table mapping Redis objects to scores.

What are sorted sets in Redis?

In Redis, sorted sets are a data type similar to sets in that both are non repeating groups of strings. The difference is that each member of a sorted set is associated with a score, allowing them to be sorted from the smallest score to the largest.

What is ZADD in Redis?

Redis ZADD command adds all the specified members with the specified scores to the sorted set stored at the key. It is possible to specify multiple score/member pairs.

What is Zrange in Redis?

Redis and PHP Redis ZRANGE command returns the specified range of elements in the sorted set stored at the key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with an equal score.


1 Answers

Short answer: Use ZRANGE compleet-index:products:apple 0 -1 WITHSCORES

ZSET is a short name for Redis Sorted Set, a Redis data type documented here. Each key in a sorted set has multiple values inside, associated with a floating value score.

like image 167
antirez Avatar answered Oct 11 '22 13:10

antirez