preface

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
<message_id>
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
Summary

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

Technology
©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network