REDIS-based multi-level caching system and caching method

By configuring multi-level caching strategies in the driver layer and proxy layer, Redis's read and write pressure and network I/O overhead are solved, and the performance bottleneck of Redis in high concurrency and large data volume scenarios is significantly improved. The overall system is performance.

CN119440412APending Publication Date: 2025-02-14JIANGSU DAMENG DATABASE CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411509191.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

In scenarios with high concurrency and large data volume, Redis may have a longer response time due to frequent read and write operations, and may even experience performance problems such as delay and blocking. The existing technology has not fully utilized the upper-level caching mechanism to reduce Redis literacy pressure.

Method used

Design a multi-level caching system based on REDIS. By configuring cache policies at the driver layer and proxy layer, introducing multi-level caching, reasonably allocating cache responsibilities at different levels, reducing the read load of Redis database, improving cache hit rate, and reducing network I Overhead of /O.

Benefits of technology

It significantly reduces the read and write load of Redis, reduces network I/O overhead, improves the overall performance and response speed of the system, and is suitable for high concurrency and large data volume application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440412A_ABST
    Figure CN119440412A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-level cache system and method based on REDIS. The multi-level cache system comprises N Node nodes, a plurality of application programs and proxy services are deployed on each Node node, and a first-level cache is configured on a driving layer closest to the application programs; simultaneously deploying a proxy cache database proxy service on a server where the application program is located, and configuring a second-level cache; and finally, the cache database Redis itself is used as a third-level cache. According to the method, by reasonably distributing cache responsibilities of different levels, the read load of the Redis database is reduced, the cache hit rate is increased, the network I / O overhead is reduced, and the overall performance and stability of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer cache, and in particular to a multi-level cache system and a cache method based on REDIS. Background Art

[0002] With the development of the Internet and cloud computing, modern applications usually need to handle a large number of user requests and data interactions. In order to improve system performance and reduce database load, cache technology is widely used in various high-performance computing environments. As an open source, memory-based high-performance cache database, Redis has become a common tool in distributed cache systems with its extremely fast read and write speeds and rich data structure support.

[0003] However, as business needs grow, Redis may encounter performance bottlenecks in high-concurrency, large-data-volume scenarios. Typical Redis architectures often rely on a single cache layer (i.e., the Redis database itself) to handle a large number of requests. When the system load is too high, Redis may have a longer response time due to frequent read and write operations, and may even experience performance issues such as delays and blocking.

[0004] To cope with this situation, existing technical solutions usually adopt cluster mode or read-write separation architecture to expand the capabilities of Redis, but these solutions still rely on the Redis database itself and fail to fully utilize the upper-layer caching mechanism to reduce the read and write pressure of Redis.

[0005] Therefore, how to design an efficient multi-level cache system at the upper layer to reduce the direct access pressure of Redis and reduce the network I / O overhead has become an urgent problem to be solved in current technology. Summary of the invention

[0006] Purpose of the invention: The present invention provides a multi-level cache system and cache method based on REDIS, introduces multi-level cache, and reduces the read load of the Redis database, improves the cache hit rate, reduces the network I / O overhead, and improves the overall performance and stability of the system by reasonably allocating cache responsibilities at different levels.

[0007] Technical solution: The multi-level cache system based on REDIS described in the present invention includes: N Node nodes, multiple applications and proxy services are deployed on each Node node, and the first-level cache is configured at the driver layer closest to the application; the proxy cache database proxy service is deployed on the server where the application is located, and the second-level cache is configured; finally, the cache database Redis itself is used as the third-level cache.

[0008] Furthermore, the driver layer cache is located inside the application, close to the business logic. The data in the driver layer cache comes from Redis. When the data in Redis is updated or invalidated, the driver layer cache will remain consistent with the data in Redis through a synchronization mechanism.

[0009] Furthermore, the proxy layer is applied in the Redis distributed architecture, located between the application and the Redis server, and is responsible for managing the connection and request routing between the client and multiple Redis instances. The data cached in the proxy layer is synchronized with Redis. When the Redis data is invalid or updated, the proxy layer cache will be updated in time according to the Redis invalidation mechanism to ensure the validity of the data.

[0010] Furthermore, a second-level cache is introduced in the proxy server to cache shared hotspot data from multiple applications.

[0011] Furthermore, the cache database layer is implemented based on a Redis cluster or a single-node instance. When a piece of data in Redis expires or is updated, Redis will promptly notify the driver layer and proxy layer to update or clear the corresponding data through the invalidation notification mechanism to ensure the validity and consistency of the cached data. Based on the Redis Tracking mechanism, when the cache key expires or changes, Redis will push the invalidation information. The driver cache layer or proxy cache layer will parse the invalidation information to eliminate or obtain new values ​​from the lower layer redis, that is, the Tacking function of Redis itself is used to ensure the validity and consistency of the cached data.

[0012] Accordingly, a multi-level caching method based on REDIS includes the following steps:

[0013] Step 1: Application request: The application initiates a data request and first searches for data in the driver layer cache;

[0014] Step 2: Driver layer cache query: If the driver layer cache hits, the result is returned directly; if not, the request is forwarded to the proxy layer;

[0015] Step 3: Proxy layer cache query: After receiving the request, the proxy layer searches for data in its cache. If it hits, it returns the result. If it does not hit, it initiates a request to the Redis database layer.

[0016] Step 4: Redis database query: After the Redis database layer returns the data, the proxy layer caches the result and passes it to the driver layer. The driver layer updates the cache according to the cache strategy.

[0017] Step 5: Data return: The final result is returned to the application.

[0018] Furthermore, the driver layer cache is located inside the application, close to the business logic. The data in the driver layer cache comes from Redis. When the data in Redis is updated or invalidated, the driver layer cache will remain consistent with the data in Redis through a synchronization mechanism.

[0019] Furthermore, the proxy layer is applied in the Redis distributed architecture, located between the application and the Redis server, and is responsible for managing the connection and request routing between the client and multiple Redis instances. The data cached in the proxy layer is synchronized with Redis. When the Redis data is invalid or updated, the proxy layer cache will be updated in time according to the Redis invalidation mechanism to ensure the validity of the data.

[0020] Furthermore, a second-level cache is introduced in the proxy server to cache shared hotspot data from multiple applications.

[0021] Furthermore, the cache database layer is implemented based on a Redis cluster or a single-node instance. When a piece of data in Redis expires or is updated, Redis will promptly notify the driver layer and proxy layer to update or clear the corresponding data through the invalidation notification mechanism to ensure the validity and consistency of the cached data. Based on the Redis Tracking mechanism, when the cache key expires or changes, Redis will push the invalidation information. The driver cache layer or proxy cache layer will parse the invalidation information to eliminate or obtain new values ​​from the lower layer redis, that is, the Tacking function of Redis itself is used to ensure the validity and consistency of the cached data.

[0022] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages: (1) Reducing the read and write pressure of Redis: By configuring the cache strategy at the driver layer and the proxy layer, the number of requests directly initiated to Redis is reduced, and most data reading operations can be completed at the driver layer or the proxy layer, thereby greatly reducing the read and write load of Redis, especially in high concurrency scenarios, significantly reducing the performance pressure of Redis; (2) Reducing network I / O overhead: Since the driver layer cache is embedded in the application, data requests do not need to go back and forth to Redis through the network, which greatly reduces the number of network transmissions; in addition, the proxy layer cache can further reduce the direct interaction between the application and Redis, significantly reducing the network I / O overhead, thereby improving the overall response speed of the system; (3) Improving the overall performance of the system: By reducing direct access to Redis, reducing network I / O overhead, and improving the hit rate of the driver cache layer and the proxy layer cache, the overall performance and response speed of the system are significantly improved. For high concurrency and large data volume scenarios, the system throughput is optimized, and the access delay is significantly reduced, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 It is a schematic diagram of the system structure of the present invention.

[0024] Figure 2 It is a schematic diagram of the method flow of the present invention.

[0025] Figure 3 This is a timing diagram of the multi-level cache query of the present invention. DETAILED DESCRIPTION

[0026] like Figure 1 As shown, a multi-level cache system based on REDIS includes: N Node nodes, multiple applications and proxy services (Redis proxy services) are deployed on each Node node, the driver is a driver for the application to request the Redis service (integrated in the application, common redis drivers include Jedis, Redisson, go-redis, Hiredis, etc.), and the cache database (redis) is a cache database service.

[0027] The data link between the application and the cache database is <application business code-Redis driver-Proxy agent-Redis>. The application business code connects to the Proxy agent service through the Redis driver. The Proxy agent node forwards the request to the corresponding Redis service, and finally returns the query results step by step.

[0028] Based on the above data links, the query logic is optimized, and the first-level cache is configured at the driver layer closest to the application. The proxy cache database proxy service is deployed on the server where the application is located, and the second-level cache is configured. Finally, the cache database Redis itself is used as the third-level cache.

[0029] The driver layer cache is located inside the application, close to the business logic. Its main function is to cache frequently accessed data, use memory to cache short-term valid data, and prioritize querying data in the local cache to reduce the number of requests to the proxy layer or Redis. The data in the driver layer cache comes from Redis. When the data in Redis is updated or invalidated, the driver layer cache will keep it consistent with the data in Redis through a synchronization mechanism (such as using the Redis tracking invalidation mechanism).

[0030] The proxy layer is mainly used in the Redis distributed architecture, located between the application and the Redis server, and is responsible for managing the connection and request routing between the client and multiple Redis instances. In order to further optimize the performance, the present invention introduces a second-level cache in the proxy server, which is mainly used to cache shared hotspot data from multiple applications. The data cached in the proxy layer is synchronized with Redis. When the data of Redis is invalid or updated, the proxy layer cache will be updated in time according to the invalidation mechanism of Redis to ensure the validity of the data.

[0031] The cache database layer is the core data storage layer of the entire system. It is implemented based on Redis cluster or single-node instance, stores a large amount of persistent data, and supports complex data operations and transaction management. When a piece of data in Redis expires or is updated, Redis will promptly notify the driver layer and proxy layer to update or clear the corresponding data through the invalidation notification mechanism to ensure the validity and consistency of the cached data.

[0032] like Figure 2 As shown, a multi-level caching method based on REDIS includes the following steps:

[0033] Step 1: The application calls the String type Get method of the driver client to query the value of key k1;

[0034] Step 2: The driver first checks whether k1 is cached in its own memory. If yes, it returns. Otherwise, it requests the Proxy node (network IO).

[0035] Step 3: After receiving the "get k1" command, the Proxy checks whether k1 is cached in its own memory. If yes, it returns. Otherwise, it forwards the request to the corresponding Redis node.

[0036] Step 4: After receiving the command, the Redis node replies to the command and returns the value v1 corresponding to k1;

[0037] Step 5. Proxy obtains the value v1 of k1 and<k1,v1> caches it in its own memory and returns v1 to the driver; the driver<k1,v1> Cache and return the results to the business layer.

[0038] like Figure 3 The following is a multi-level cache query sequence diagram of the present invention. The Proxy service and the Redis service are considered as Redis services to describe the processing of user query requests in the case of cache misses and cache hits. It can be seen from the sequence diagram that:

[0039] (1) When the driver does not cache the value of k1 for the first request, it sends a get command to the Redis node to obtain the value v1 of key k1.<k1,v1> Cache in its own memory and return the result;

[0040] (2) During driving<k1,v1> Multiple query requests (get k1) within the cache expiration time hit the cache in the driver memory and directly return v1.

[0041] If the cache hits at the driver layer, the application can get the return result immediately without any network overhead, effectively reducing the access pressure of the Redis service and improving the performance of the Redis service.

[0042] The present invention reduces the number of Redis accesses and reduces network overhead through the optimized design of the multi-level cache system. It has significant technical advantages and can significantly improve the overall performance of the system. It is particularly suitable for application scenarios with high concurrency and large data volumes.

Claims

1. A multi-level cache system based on REDIS, characterized in that: include: N Node nodes, deploy multiple applications and proxy services on each Node node, configure the first-level cache at the driver layer closest to the application; deploy the proxy cache database proxy service on the server where the application is located, and configure the second-level cache; finally, the cache database Redis itself is used as the third-level cache.

2. The multi-level cache system based on REDIS as claimed in claim 1, characterized in that: The driver layer cache is located inside the application, close to the business logic. The data in the driver layer cache comes from Redis. When the data in Redis is updated or invalidated, the driver layer cache will keep it consistent with the data in Redis through a synchronization mechanism.

3. The multi-level cache system based on REDIS as claimed in claim 1, characterized in that: The proxy layer is used in the Redis distributed architecture, located between the application and the Redis server. It is responsible for managing the connection and request routing between the client and multiple Redis instances. The data cached in the proxy layer is synchronized with Redis. When the Redis data is invalid or updated, the proxy layer cache will be updated in time according to the Redis invalidation mechanism to ensure the validity of the data.

4. The multi-level cache system based on REDIS as claimed in claim 1, characterized in that: A second-level cache is introduced in the proxy server to cache shared hotspot data from multiple applications.

5. The multi-level cache system based on REDIS as claimed in claim 1, characterized in that: The cache database layer is implemented based on Redis cluster or single-node instance. When a piece of data in Redis expires or is updated, Redis will promptly notify the driver layer and proxy layer to update or clear the corresponding data through the invalidation notification mechanism to ensure the validity and consistency of the cached data. Based on the Redis Tracking mechanism, when the cache key expires or changes, Redis will push the invalidation information. The driver cache layer or proxy cache layer will parse the invalidation information to eliminate or obtain new values ​​from the lower layer redis, that is, the Tacking function of Redis itself is used to ensure the validity and consistency of the cached data.

6. A caching method based on the REDIS-based multi-level caching system as claimed in claim 1, characterized in that: The steps include: Step 1: Application request: The application initiates a data request and first searches for data in the driver layer cache; Step 2: Driver layer cache query: If the driver layer cache hits, the result is returned directly; If it does not hit, forward the request to the proxy layer; Step 3: Proxy layer cache query: After receiving the request, the proxy layer searches for data in its cache. If it hits, it returns the result. If it does not hit, it initiates a request to the Redis database layer. Step 4: Redis database query: After the Redis database layer returns the data, the proxy layer caches the result and passes it to the driver layer. The driver layer updates the cache according to the cache strategy. Step 5: Data return: The final result is returned to the application.

7. The multi-level cache method based on REDIS as claimed in claim 6, characterized in that: The driver layer cache is located inside the application, close to the business logic. The data in the driver layer cache comes from Redis. When the data in Redis is updated or invalidated, the driver layer cache will keep it consistent with the data in Redis through a synchronization mechanism.

8. The multi-level cache method based on REDIS as claimed in claim 6, characterized in that: The proxy layer is used in the Redis distributed architecture, located between the application and the Redis server. It is responsible for managing the connection and request routing between the client and multiple Redis instances. The data cached in the proxy layer is synchronized with Redis. When the Redis data is invalid or updated, the proxy layer cache will be updated in time according to the Redis invalidation mechanism to ensure the validity of the data.

9. The multi-level cache method based on REDIS as claimed in claim 6, characterized in that: A second-level cache is introduced in the proxy server to cache shared hotspot data from multiple applications.

10. The multi-level cache method based on REDIS as claimed in claim 6, characterized in that: The cache database layer is implemented based on Redis cluster or single-node instance. When a piece of data in Redis expires or is updated, Redis will promptly notify the driver layer and proxy layer to update or clear the corresponding data through the invalidation notification mechanism to ensure the validity and consistency of the cached data. Based on the Redis Tracking mechanism, when the cache key expires or changes, Redis will push the invalidation information. The driver cache layer or proxy cache layer will parse the invalidation information to eliminate or obtain new values ​​from the lower layer redis, that is, the Tacking function of Redis itself is used to ensure the validity and consistency of the cached data.

Citation Information

Cited By

  • Policy scheduling method and system, electronic equipment and storage medium

    CN121935029A