Data cache configuration method and cache implementation method combining relational database drive with non-relational database, computer equipment and storage medium

By combining Redis in relational database drivers for data cache, the problem of slow query speed of relational databases is solved. The high performance characteristics of Redis are used to improve query speed and simplify the application's complexity of use of Redis.

CN119884256APending Publication Date: 2025-04-25JIANGSU DAMENG DATABASE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411806235.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-10
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

Due to the reliability and strong consistency of data, existing relational databases require data to be stored on disk, resulting in slow query speed of the result set being affected by factors such as disk, data complexity and table size.

Method used

Data cache is cached through relational database driver combined with non-relational database Redis. The high concurrency and low latency characteristics of Redis are used to cache the result set in Redis. The configuration methods include configuration files and commands, dynamically update cache parameters, and reduce query pressure for relational databases.

Benefits of technology

The query speed of relational databases is improved, especially in the SQL scenarios where frequent access but not frequently modified, the high performance characteristics of Redis are fully utilized, the query pressure of relational databases is reduced, and the complexity of application use of Redis is simplified.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119884256A_ABST
    Figure CN119884256A_ABST
Patent Text Reader

Abstract

The invention discloses a data cache configuration method combining a relational database driver with a non-relational database, a cache implementation method, computer equipment and a storage medium. The method comprises the following steps: initializing and starting the relational database driver; the cache configuration is completed by analyzing the configuration file in which the cache parameters are stored; the relational database driver judges whether the current sql statement is contained in an sql statement list in the configuration file or not, and if not, the relational database driver sends the sql statement to the relational database and obtains result set information from the relational database so as to construct a result set; if the result set information of the current sql statement is contained, the relational database drives to query whether the result set information of the current sql statement is cached in a non-relational database, and if the result set information of the current sql statement is cached in the non-relational database, the existing result set information is used for constructing a result set; and if the result set information is not cached, obtaining the result set information from the relational database so as to construct a result set, and storing the obtained result set information in a non-relational database at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of databases, and in particular relates to a data cache configuration method, a cache implementation method, a computer device and a storage medium that combines a relational database driver with a non-relational database. Background Art

[0002] Traditional relational database drivers send SQL statements to relational databases (Structured Query Language, a standard language used to communicate with relational databases, used to access data and query, update and manage relational database systems), and then perform a series of complex steps such as syntax parsing, query optimization, execution plan generation, executor execution, and result set construction to obtain the execution result set (an object containing all rows that meet the conditions in the SQL statement). Relational databases often store data on disk for data reliability and strong consistency. The access speed of the result set is affected by many factors such as disk, data complexity, and table size. Summary of the invention

[0003] Purpose of the invention: To solve the problem that existing relational databases often store data on disk for data reliability and strong consistency, and the access speed of result sets is affected by many factors such as disk, data complexity, table size, etc., the present invention proposes a data cache configuration method, cache implementation method, computer device and storage medium that combines a relational database driver with a non-relational database.

[0004] Technical solution: A data cache configuration method for a relational database driver combined with a non-relational database, including:

[0005] Initialize and start the relational database driver;

[0006] The relational database driver completes the cache configuration by parsing a configuration file storing cache parameters; the cache parameters include: the SQL statement of the result set to be cached, the non-relational database server address, the user name for connecting to the non-relational database, and the password for connecting to the non-relational database;

[0007] Verify whether the cache parameters are legal. Only after verification, the relational database driver can execute result set caching.

[0008] Further, the relational database driver completes the cache configuration by parsing the configuration file storing the configuration cache parameters, which can be replaced by the following steps:

[0009] The relational database driver configures cache parameters online in the form of commands.

[0010] Furthermore, it includes: when the relational database driver executes the result set cache, it starts a monitoring thread to regularly monitor whether the configuration file has been modified. Only when the configuration file is modified, it reloads and parses the configuration file and updates the SQL statement of the result set to be cached.

[0011] Furthermore, the basic configuration attributes also include: result set cache time, maximum number of result set caches, and result set cache request timeout.

[0012] The present invention also discloses a data cache implementation method of a relational database driver combined with a non-relational database, comprising the following steps:

[0013] Step 1: Start the relational database driver, complete the cache configuration, and establish a connection with the non-relational database;

[0014] Step 2: Determine whether the relational database driver has enabled result set caching. If not, the relational database driver sends a SQL statement to the relational database, obtains result set information from the relational database, constructs a result set, and returns the constructed result set to the client. If it is enabled, execute step 3.

[0015] Step 3: The relational database driver determines whether the current SQL statement is included in the SQL statement list in the configuration file. If so, step 4 is executed; if not, the relational database driver sends the SQL statement to the relational database, obtains the result set information from the relational database, constructs the result set, and returns the constructed result set to the client;

[0016] Step 4: The relational database driver queries whether the result set information of the current SQL statement has been cached in the non-relational database. If so, the existing result set information is used to construct the result set, and the constructed result set is returned to the client. If not, the relational database driver sends the SQL statement to the relational database, obtains the result set information from the relational database, constructs the result set, returns the constructed result set to the client, and stores the obtained result set information in the non-relational database.

[0017] The cache configuration is completed by parsing the configuration file according to a data cache configuration method that combines a relational database driver with a non-relational database.

[0018] The present invention also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the processor implements the steps of a data cache configuration method that combines a relational database driver with a non-relational database.

[0019] The present invention also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the processor implements the steps of a data cache implementation method of a relational database driver combined with a non-relational database.

[0020] The present invention also discloses a storage medium, wherein the storage medium stores a data cache configuration program, and when the data cache configuration program is executed by at least one processor, the steps of a data cache configuration method of a relational database driver combined with a non-relational database are implemented.

[0021] The present invention also discloses a storage medium storing a data cache implementation program. When the data cache implementation program is executed by at least one processor, the steps of a data cache implementation method of a relational database driver combined with a non-relational database are implemented.

[0022] Beneficial effects: Compared with the prior art, the present invention has the following advantages:

[0023] (1) Cache the result set of SQL executed by the relational database in the non-relational database Redis, and use the high concurrency and low latency characteristics of the non-relational database Redis to improve the query speed of the SQL result set driven by the relational database. In particular, for SQL that is frequently accessed but not frequently modified and in scenarios where there are more reads and fewer writes, the high performance of the non-relational database Redis can be fully utilized to greatly reduce the query pressure on the relational database;

[0024] (2) The present invention provides a convenient way to configure cached SQL statements, which can dynamically batch configure SQL statements to cache result sets at any time according to business needs. The driver can automatically update the corresponding configuration information without the application itself being aware of it.

[0025] (3) The present invention uniformly processes the use of non-relational database Redis to cache result sets in relational database drivers, so that users do not need to plan the use of non-relational database Redis in advance in applications, and do not need to worry about how to efficiently access data from non-relational database Redis, thereby reducing the application's attention to non-relational database Redis. By utilizing the high performance and simple use of non-relational database Redis, the performance of relational database driver query result sets can be improved by using non-relational database Redis without modifying the application, thereby reducing the query pressure of the relational database. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 Flowchart for initializing configuration of result set cache driven by relational database;

[0027] Figure 2 This is a flow chart of the relational database driver monitoring and loading sql file in combination with the result set cache of the non-relational database Redis in the first embodiment of the present invention;

[0028] Figure 3 This is an execution flow chart of the relational database driver in Embodiment 2 of the present invention combined with the non-relational database Redis cache result set. DETAILED DESCRIPTION

[0029] The technical terms involved in the embodiments are explained as follows:

[0030] The non-relational database Redis is an open source log-type, Key-Value database written in ANSI C language, supporting the network, and can be based on memory or persistence. It is referred to as Redis below. The non-relational database Redis uses memory as the main storage medium, supports multiple data structures, provides high-speed data access, has high concurrency, low latency, easy scalability, supports data backup, data persistence, simpler transactions, etc. It is simple to use and efficient.

[0031] The present invention proposes a method for caching SQL result sets by combining a relational database driver with Redis, which reduces the application's own attention to Redis. The application does not need to plan the use of Redis in advance, and does not need to worry about when to store data in Redis, when to read from Redis, and how to efficiently access data from Redis. It only needs to perform simple parameter configuration in the relational database driver to store the relational database query result set in Redis, thereby utilizing the advantages of high concurrency and low latency of Redis to improve the access speed of SQL result sets, reduce the query pressure of the relational database, and eliminate the time-consuming series of complex processes such as syntax parsing, optimization, and execution when querying SQL in the relational database.

[0032] And storing the SQL statement query result set returned by the relational database in the high-performance non-relational database Redis can eliminate the time-consuming complex processes of SQL statement syntax parsing, optimization, and execution when the relational database queries SQL. If the SQL result set that is frequently accessed but seldom modified is cached in Redis, the access speed of these SQL result sets can be greatly improved by utilizing the high-performance characteristics of Redis such as memory access, high concurrency, and low latency, thereby sharing the query load of the relational database and reducing the query pressure of the relational database itself. In the first aspect, the present invention provides a configuration method for a relational database driver combined with Redis cache SQL result set, which generally includes the following steps:

[0033] The basic properties that need to be configured when combining the relational database driver with Redis result set cache include but are not limited to the following parameters: SQL statement to cache the result set, result set cache time, maximum number of result set caches, result set cache request timeout, Redis server address, user name and password for connecting to Redis, cache connection reconnection interval, etc.

[0034] In this embodiment, the configuration parameters are divided into two ways: configuration file and configuration command. The configuration file method loads the configuration parameters in the configuration file when the driver is initialized, and then verifies and assigns values. All cache-related parameters can be configured at one time, including: after the relational database driver is started, the SQL statement in the configuration file will be loaded, and the configuration file will be continuously monitored to see if it has been modified. If the file has been modified, the configuration file content will be reloaded to update the SQL statement. This method can make it easier for applications to configure a large number of SQL statements to cache result sets at one time without modifying the application business code.

[0035] The configuration command method is to configure the required cache parameters online through a series of commands after the driver is initialized. The configuration is flexible and the parameter values ​​can be changed online.

[0036] In a second aspect, the present invention provides a method for implementing a cache result set of a relational database driver combined with Redis, comprising the following steps:

[0037] Once the relational database driver is configured, a connection is established with Redis.

[0038] When the relational database driver queries SQL, it first checks whether the result set cache is enabled. If the cache is not enabled, the driver directly queries the relational database result set information (used to build the row and column information required by the client result set) to build the result set and return it to the client. If the cache is enabled, first match whether the SQL to be cached contains the SQL statement of the current query. If the match fails, it means that the SQL statement is not configured in the cache, so there is no need to cache the result set information of the SQL statement in Redis, and directly query the result set from the relational database and return it. If the match is successful, it means that the SQL has been configured in the driver to cache the result set information in Redis, then the driver first queries whether the result set information of the SQL has been cached in Redis. If it exists, the result set information is used to build the result set and return it to the client; if it does not exist, the result set information of the relational database is queried, and then the result set information of the successful query is built and returned to the client, and the result set information of this successful query is stored in Redis, and the expiration time is set.

[0039] The technical solution of the present invention is now further described in conjunction with the accompanying drawings and embodiments.

[0040] Embodiment 1:

[0041] This embodiment is used to describe the process of dynamically configuring SQL statements by combining a relational database driver with a Redis cache result set. Figure 1 and Figure 2 This is a flowchart of the relational database driver combined with Redis dynamic configuration sql statement in the first embodiment of the present invention. Figure 1 and Figure 2 As shown, the method specifically comprises the following steps:

[0042] S101, initialize and start the relational database driver;

[0043] S102, the relational database driver parses the configuration file storing the configuration cache parameters, and the cache parameters can also be configured online in the form of commands; the configuration cache parameters include but are not limited to the SQL statement to cache the result set, the Redis server address, the user name to connect to Redis, the password to connect to Redis, the maximum number of cached SQL statements, the timeout period for the cached result set, and other parameters. For example:

[0044] Cache online to add the sql command to cache the result set: CACHE ADD sql1 sql2...

[0045] Cache online configuration connection Redis address: CACHE CONFIG SET ADDR 127.0.0.1:6379

[0046] Cache online configuration connection Redis username: CACHE CONFIG SET USER default

[0047] Cache online configuration connection Redis password: CACHE CONFIG SET AUTH 12345678

[0048] Cache online configuration result set expiration time (in seconds): CACHE CONFIG SET EXPIRE 30

[0049] The maximum number of cached online configuration result sets: CACHE CONFIG SET COUNT 100

[0050] Cache online configuration reconnection time (unit: s): CACHE CONFIG SET RECONNECTION 5S103. After the cache is configured, you need to verify whether the parameters are legal. If the parameters are illegal, an exception will be thrown and the cache will not work properly.

[0051] S104, after the cache configuration verification is passed, the cache can be started to execute the result set caching function.

[0052] In actual use, the relational database driver starts a monitoring thread to periodically monitor whether the configuration file has been modified. If the configuration file has been modified, the configuration file content is reloaded and the SQL statement to cache the result set in the driver memory is updated. If the configuration file has not been modified, the driver does not need to be updated and the timer enters the next cycle.

[0053] Note: The command definitions, parameters, etc. listed in this embodiment are only used to explain the present invention and for reference.

[0054] Embodiment 2:

[0055] This embodiment is used to further illustrate the execution process of the relational database driver combined with the Redis cache result set. Figure 3 As shown, the method specifically comprises the following steps:

[0056] The following takes the relational database driving JDBC to query the result set of the SQL statement (select name from t_test where id=1) from MySql as an example.

[0057] S201, when JDBC queries the result set of the SQL statement, first determine whether the result set cache is enabled.

[0058] S202, if the result set cache is not enabled, then execute step S205. If it is enabled, first check whether the SQL exists in the SQL list of the result set to be cached.

[0059] S203: If no match is found, execute step S205. If the match is successful, query the result set information in Redis.

[0060] S204, after obtaining the result set information of the sql from Redis, if the result set information is not empty, then construct the result set. If the result set information is empty, then execute step S205.

[0061] S205, obtain result set information from MySql, and then construct the result set.

[0062] S206, returning the constructed result set information to the client.

[0063] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0064] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0065] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A data cache configuration method for a relational database driver combined with a non-relational database, characterized in that: include: Initialize and start the relational database driver; The relational database driver completes the cache configuration by parsing the configuration file that stores the cache parameters; The cache parameters include: the SQL statement of the result set to be cached, the non-relational database server address, the user name for connecting to the non-relational database, and the password for connecting to the non-relational database; Verify whether the cache parameters are legal. Only after verification, the relational database driver can execute result set caching.

2. According to claim 1, a data cache configuration method for a relational database driver combined with a non-relational database is characterized by: include: The relational database driver completes the cache configuration by parsing the configuration file storing the configuration cache parameters, which can be replaced by the following steps: The relational database driver configures cache parameters online in the form of commands.

3. According to claim 1, a data cache configuration method for a relational database driver combined with a non-relational database is characterized by: include: When executing result set caching, the relational database driver starts a monitoring thread to periodically monitor whether the configuration file has been modified. Only when the configuration file is modified, it reloads and parses the configuration file and updates the SQL statement for caching the result set.

4. According to claim 1, a data cache configuration method for a relational database driver combined with a non-relational database is characterized by: The basic configuration attributes also include: result set cache time, maximum number of result set caches, and result set cache request timeout.

5. A data cache implementation method for a relational database driver combined with a non-relational database, characterized in that: The following steps are involved: Step 1: Start the relational database driver, complete the cache configuration, and establish a connection with the non-relational database; Step 2: Determine whether the relational database driver has enabled result set caching. If not, the relational database driver sends a SQL statement to the relational database, obtains result set information from the relational database, constructs a result set, and returns the constructed result set to the client. If it is enabled, execute step 3. Step 3: The relational database driver determines whether the current SQL statement is included in the SQL statement list in the configuration file. If so, step 4 is executed; if not, the relational database driver sends the SQL statement to the relational database, obtains the result set information from the relational database, constructs the result set, and returns the constructed result set to the client; Step 4: The relational database driver queries whether the result set information of the current SQL statement has been cached in the non-relational database. If so, the existing result set information is used to construct the result set, and the constructed result set is returned to the client. If not, the relational database driver sends the SQL statement to the relational database, obtains the result set information from the relational database, constructs the result set, returns the constructed result set to the client, and stores the obtained result set information in the non-relational database. The cache configuration is completed by parsing the configuration file according to a data cache configuration method of a relational database driver combined with a non-relational database as described in any one of claims 1 to 4.

6. A computer device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of a data cache configuration method of a relational database driver combined with a non-relational database as described in any one of claims 1 to 4 are implemented.

7. A computer device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method implements the steps of a data cache implementation method of a relational database driver combined with a non-relational database as described in claim 5.

8. A storage medium, characterized in that: The storage medium stores a data cache configuration program, and when the data cache configuration program is executed by at least one processor, the steps of the data cache configuration method of a relational database driver combined with a non-relational database as described in any one of claims 1 to 4 are implemented.

9. A storage medium, characterized in that: The storage medium stores a data cache implementation program, and when the data cache implementation program is executed by at least one processor, the steps of the data cache implementation method of a relational database driver combined with a non-relational database described in claim 5 are implemented.