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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With