Redis isn't just the shortest introduction (4), Redis

How to use Redis like that-Z set

――Since there are a few more, it seems that we will repeat the times instead of the shortest introduction

At the very least, if you can put it in and out, the rest will be manageable. For first-time users, see Redis Shortest Introduction (1) Install & Start in 2 Lines.

Why not step into a place where Redis is unmatched?

Z series

There is a method that starts with Z that can handle Sorted Set. (´ ・ ω ・ `). .. .. (Is it because z is similar to s)

Since it is NOSQL in KVS, do you get the ranking by API and then sort it by yourself?

"NO!" Who says something like that programmer?

Quickly put out with the key! Real-time ally, that is redis

Sorting by score, it seems that only that will do the aggregation work.

First, add

ZADD key score value

--Save value with score for key --Hash type + Feeling like adding a score to hints for sorting

Please specify the range

ZREVRANGE key start end [WITHSCORES]

--Partially acquired by specifying the start end interval in the order sorted by score --20-30th place, convenient to go to the next page

It seems that the ranking is elaborate, and GJ!

It seems that weight can be passed to each, so it is a god for recommendation and machine learning.

Please make it a comprehensive ranking

ZUNIONSTORE newkey N key1 key2 ... (WEIGHTS w1 w2 .... ) (AGGREGATE (SUM|MIN|MAX))

--Create a new ranking from N keys and store it in newkey It seems to specify N as a hint of how many to continue. Number of keys.

--The result is obtained by specifying the new key. This is a little like KVS. I will not return it.

--Miso that can be used for ranking by genre and overall ranking

--SUM, MIN and MAX are score evaluation formulas when they have the same value. They come in descending order of score.

It seems that ZINTERSTORE is a common item, so I don't use it much. ..

Next up is PUBLISH and SUBSCRIBE

Recommended Posts

Redis isn't just the shortest introduction (4), Redis
[Introduction to Algorithm] Find the shortest path [Python3]
Redis Shortest Introduction (3) API in 5 minutes even in Python