There's more...

Sometimes we do not want to sort elements by their values, but by their weights that are defined in some external keys. For example, we may need to sort the user's favorite restaurants by ratings defined in keys like restaurnat_rating_200, where 200 is the restaurant ID. This can also be done in SORT:> SET "restaurant_rating_200" 4.3> SET "restaurant_rating_365" 4.0> SET "restaurant_rating_104" 4.8> SET "restaurant_rating_455" 4.7> SET "restaurant_rating_333" 4.6> SORT "user:123:favorite_restaurant_ids" BY restaurant_rating_* DESC 
1) "104" 
2) "455" 
3) "333" 
4) "200" 
5) "365" 

In some scenarios, the values from external keys are more useful. ...

Get Redis 4.x Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.