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

Several small things about redis (1) the purpose and problems of using redis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What is 1.redis used for?

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

As can be seen from the description on the redis website above, redis is a thing that can store in-memory data structures and can be used as a database, cache, and message broker. It supports data structures such as strings, hashes, lists, collections, sort sets with range queries, bitmaps, super logs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of disk persistence, and provides high availability through Redis Sentinel and automatic partitioning using Redis Cluster.

In the project, it is mainly used as the cache of data, caching the data in redis to reduce the pressure of access to the underlying database and obtain higher concurrency and faster request response.

two。 How to use it in a project?

We know that the data in the project generally exists in the database, and the concurrency performance of the database is not particularly high, if a large number of requests are received at the same time, the database may collapse, and sql queries will consume a certain amount of time and increase the response time of requests, so without caching, the system will not be able to support a large number of concurrency, request response time will be longer and so on.

If we access a certain data for the first time, such as obtaining the details of an order according to an order id, and put the data in the cache when we return the data, then next time we can return the data directly in the cache without having to query the database. This can reduce the access pressure on the database, and caching it in memory is bound to be much faster than accessing the database directly. This reduces the response time of requests, and redis is mainly used in projects to solve the problem of data caching.

3. Why use caching?

Caching is used for two main purposes:

(1) High performance

For example, there is a very complex sql data query, which takes a lot of time. If you take the data query directly each time, it will inevitably have a great impact on the request response time. If you can save it directly in the cache after the first query, and take the ready-made data from the cache directly in the next query, it will greatly shorten the response time of the request.

(2) High concurrency

We know that the concurrency that the database can withstand is limited, so during the peak period of traffic (for example, rush purchase, discount, second kill, etc.), a large number of requests will enter our system, such as querying the details of a product, if we do not have a buffer, then we have to go to the database for each query, if our database can only accept 2000 requests per second, as a result, 5000 requests come in one second. Then the database will collapse directly, and there is no high concurrency to speak of, and if we have a cache service among us, then when the first user queries the product details (or put it away in advance), we can directly put the product details data into the cache, so that when subsequent users query, we can directly go to the cache, not the database, the cache is based on memory, and its access speed is fast and high. Therefore, it is possible to provide a high concurrency support.

4. What's wrong with using the cache?

The main common problems are as follows

1) inconsistent double writes between cache and database

2) cache avalanche

3) Cache traversal

4) cache concurrency contention

Collection of Flink series of essays:

Getting started with Flink

Flink DataSet&DataSteam API

Flink cluster deployment

Flink restart policy

Flink distributed cache

Flink restart policy

Time in Flink

Windows in Flink

Timestamp and watermark of Flink

Flink broadcast variable

Flink-Kafka-connetor

Flink-Table&SQL

Flink actual combat project-best-selling list

Flink-Redis-Sink

Flink consumption Kafka write Mysql

More practical cases will be updated later.

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

Internet Technology

Wechat

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

12
Report