Redis Is a powerful memory storage , It has rich data structure , It can be applied in many aspects , Include as database , cache , Message queuing and so on .

If you remember Redis It's just one key-value storage , Then I miss it Redis A lot of powerful features , The following is the actual application scenario 5 The most common cases .

1. Full page caching

If you're using server-side content rendering , You don't want to re render every page for every request , You can use it Redis
Cache frequently requested content , Can greatly reduce the delay of page request , There are already a lot of frameworks to use Redis To cache pages , This is a way of static pages .
// Set the page that will last 1 minute SET key "<html>...</html>" EX 60 //
Get the page GET key
2. Ranking List

Redis Memory based , Can be very fast and efficient processing increase and decrease operations , Compared with using SQL How requests are handled , The performance improvement is huge .

Redis Can be easily implemented “ Get the highest ranking from a large list N Elements ”, millisecond , And it's very simple .
// Add an item to the sorted set ZADD sortedSet 1 "one" // Get all items from
the sorted set ZRANGE sortedSet 0 -1 // Get all items from the sorted set with
their score ZRANGE sortedSet 0 -1 WITHSCORES
3. Session storage

This is probably the most widely used point , Compared with similar memcache Of session storage ,Redis
It has the ability of cache data persistence , When the cache is restarted due to a problem , The previous cache data is still there , This is more practical , Avoided because session User experience problems caused by sudden disappearance .
// Set session that will last 1 minute SET randomHash "{userId}" EX 60 // Get
userId GET randomHash
4. queue

for example email Send queue for , Data queues waiting to be consumed by other applications ,Redis It is easy and natural to create an efficient queue .
// Add a Message HSET messages <id> <message> ZADD due <due_timestamp> <id> //
Recieving Message ZRANGEBYSCORE due -inf <current_timestamp> LIMIT 0 1 HGET
messages<message_id> // Delete Message ZREM due <message_id> HDEL messages
5. release / subscribe

pub/sub yes Redis A very powerful feature built in , For example, you can create a real-time chat system , Notification triggers in social networks and so on .
// Add a message to a channel PUBLISH channel message // Recieve messages from
a channel SUBSCRIBE channel

this 5 A small use case is just Redis A very superficial function of , Hope to bring you a little inspiration .

©2019-2020 Toolsou All rights reserved,
Non preemptive static priority scheduling algorithm for operating system (C language )Go Language learning notes (GUI programming )XCTF Attack and defense world web Advanced practice _ 2_lottery What's the difference between computer major and training background ?python realization vlookup_ Dry goods I : Why python It's inside vlookup Bubble sort primary springboot2 Separation of front and rear platforms ,token Put in header Pit for verification Python Case conversion of letters ( Two methods )javascript event ( Detailed explanation of zero basis )Unity2019 UIElement note ( ten ) Simple exercise 2