Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the five functions of redis

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about the five kinds of redis, which may not be well understood by many people. In order to let you know more, Xiaobian summarized the following contents for you. I hope you can gain something according to this article.

Generally speaking, Redis also exists in the form of message queues, as embedded Lists, to meet the high concurrency requirements of real-time. Usually in the process of data processing of an e-commerce type, queues related to commodities, hot sales, and recommendation sorting are usually stored in Redis, during which Storm is also expanded to read and update the Redis list.

Redis is a high-performance key-value database.

Redis and other key-value caching products have three characteristics:

- Redis supports persistence of data. It can save data in memory to disk and load it again for use when restarting.

- Redis not only supports simple key-value data, but also provides storage for list, set, zset, hash and other data structures.

- Redis supports data backup, namely master-slave mode data backup.

Five uses:

1. Full page cache

Full page cache. If you're using server-side rendered content, you don't need to re-render each page for each individual request. With a cache like Redis, you can cache frequently requested content, greatly reducing latency for the most requested pages, and most frameworks have hooks for Redis cached pages.

//Set full page cache for 1 minute SET key "... " EX 60//Get full page GET key

2. order

Because Redis in-memory Set data structures can increment and decrement very quickly and efficiently, performance is much higher than SQL queries. This, combined with Redis 'sort set, means that you can grab the highest rated items in the list in milliseconds, and it's very easy to implement.

//Add value ZADD sortedSet 1 "one" to sorted set//Get all values from sorted set ZRANGE sortedSet 0 -1//Get all values and weights from sorted set ZRANGE sortedSet 0 -1 WITH SCORES

3. Session Storage

The most common use I've seen for Redis is session storage. Unlike other session stores, such as Memcache, Redis can retain data so that in the event of a cache stop, all data is still present upon restart. Even if it's not a strictly continuous task, this feature can still save your users a lot of trouble. No one would like to see their conversations deleted randomly for no reason.

//Set sessionSET randomHash "{userId}" EX 60 that expires in one minute//Get user ID GET randomHash

4. Queue

A less common, but very useful thing you can do with Redis is queue. Whether it's email queues or data used by other applications, you can create an efficient queue in Redis. Any developer familiar with stacks and push and pop projects can easily and naturally use this feature.

//Add messages HSET messages ZADD due //Receive messages ZRANGEBYSCORE due -inf LIMIT 0 1 HGET messages //Delete messages ZREM due HDEL messages

5.pub/sub

The ultimate use of Redis in the real world is pub / sub, which I will propose in this article. This is one of the most powerful features built into Redis; the possibilities are unlimited. You can create a live chat system, trigger notifications of friend requests on Social networks, and so on. This feature is one of the most underrated features offered by Redis, but it is very powerful and easy to use.

//Push message PUBLISH channel message to channel//Get message SUBSCRIBE channel from channel After reading the above contents, do you have any further understanding of the five functions of redis? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report