Reputation: 5147
For example, I'm setting the data like following to redis.
SET "projects:views:PROJECT_NAME1" 17
SET "projects:views:PROJECT_NAME2" 13
SET "projects:views:PROJECT_NAME3" 21
PROJECT_NAME
differs according to project record name that I get from relational database.
How can I sort all "project:views:*" by value. In this example our output should be
PROJECT_NAME3 21
PROJECT_NAME1 17
PROJECT_NAME2 13
Upvotes: 0
Views: 202
Reputation: 3794
Add them to a sorted set like this:
ZADD "projects:views" 17 PROJECT_NAME1 13 PROJECT_NAME2 21 PROJECT_NAME3
Then call:
ZREVRANGE projects:views 0 -1 WITHSCORES
Check here what other things a sorted set can do
Upvotes: 2