Using the sorted set data type
Compared to the data type set introduced in the previous recipe, sorted list is a similar but more complex one in Redis. The word Sorted means each element in this kind of set owns a weight that can be used for sorting, and you can retrieve the elements from the set in order. It's convenient to take advantage of this natively sorted feature in some scenarios for which the sorting is needed all the time. In this recipe, we'll see how to manipulate sorted set.
Getting ready…
You need to finish the installation of the Redis Server, as we described in the Downloading and installing Redis recipe in Chapter 1, Getting Started with Redis, and connect to the Redis Server by redis-cli
.
How to do it...
To understand how to use the sorted set data type, take the following steps:
- Open a Terminal and connect to Redis with
redis-cli
. - To make a ranking for the local restaurants in Relp, use the following:
- The first step we will take is to put the voting rate and the name of each...