Communication method and device compatible with redis singleton mode and cluster mode

By performing compatibility detection and index value rewrite on the data communication instructions sent by the client in singleton mode, Redis is compatible with cluster mode in singleton mode, solving the cache performance problem in singleton mode, and improving the performance of Redis system.

CN114238202BActive Publication Date: 2025-05-02PING AN SECURITIES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111549354.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-17
Publication Date
2025-05-02
Estimated Expiration
2041-12-17

AI Technical Summary

Technical Problem

Historical business systems are prone to performance problems in cache middleware, such as excessive connection count, poor data storage scalability, and excessive technical cost to migrate to clusters or even impossible to migrate. Existing middleware products focus on native support based on redis cluster mode, which fails to effectively solve the scalability problem of singleton mode cache.

Method used

It provides a communication method that is compatible with redis singleton mode and cluster mode. By performing compatibility detection on the data communication instructions sent by the client in singleton mode, if it is incompatible, the index value is obtained and the index value is rewrite according to the preset rewrite rules, making it compatible with singleton mode and cluster mode in the Redis server. According to the rewritten index value, the corresponding access address is obtained from the cluster mapping of the Redis server for data communication processing.

Benefits of technology

It realizes the distributed cache connection in singleton working mode, is compatible with redis singleton mode and cluster mode, improves the performance of Redis system, solves the data storage and CPU limitation problems of singleton mode, and supports multi-node parallel master library read and write services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114238202B_ABST
    Figure CN114238202B_ABST
Patent Text Reader

Abstract

The present application is applicable to the field of data processing technology, and provides a communication method and device compatible with redis singleton mode and cluster mode, and the method includes: performing compatibility detection on the data communication instruction sent by the client in the singleton mode, and determining whether the data communication instruction is compatible with the singleton mode and cluster mode in the Redis server; if not compatible, obtaining the index value carried in the data communication instruction, and rewriting the index value according to the preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and cluster mode in the Redis server based on the rewritten index value; according to the rewritten index value in the data communication instruction, obtaining the access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server, and performing data communication processing according to the access address. In the scenario of singleton working mode, it can be achieved through distributed cache docking, compatible with singleton mode and cluster mode, and improve system performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a communication method and device compatible with Redis singleton mode and cluster mode, and also to an electronic device and a storage medium for executing the communication method compatible with Redis singleton mode and cluster mode. Background Art

[0002] For legacy business systems, at the beginning of system design, due to objective factors such as design issues, cost issues, and the version restrictions of Redis (Redis is essentially a key-value type storage database) at the time, the business system usually chooses a single-instance working mode scenario due to low cache version or non-cluster mode. In the single-instance working mode scenario, Redis implements limited data sub-library isolation by specifying the Redis db database attributes. It usually provides a master-slave mode and has high requirements for cache data consistency, and can only use the master node to provide services.

[0003] With the development of business systems, such legacy business systems that use a singleton working mode are prone to performance problems in cache middleware, such as too high a number of connections, poor data storage scalability, and too high a technical cost to migrate to a cluster or even the inability to migrate. At present, existing middleware products that solve problems such as too high a number of redis connections and poor scalability focus more on providing native support based on the redis cluster mode, such as redis client sharding, twemproxy, codis, redis cluster, corvus, etc., and rarely consider the scalability of singleton mode cache. Moreover, the existing related middleware monitors the cache basically based on redibim information, and does not provide too much monitoring capabilities for the middleware. Such monitoring is likely to cause performance pressure on the redis server. Therefore, there is an urgent need to provide a cache expansion solution that is compatible with redis singleton mode and cluster mode for legacy business systems. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a communication method and device compatible with redis singleton mode and cluster mode, which can realize Redis docking through distributed cache in the scenario of singleton working mode, is compatible with redis singleton mode and cluster mode, and improves the performance of Redis system.

[0005] A first aspect of an embodiment of the present application provides a communication method compatible with redis singleton mode and cluster mode, including:

[0006] Perform compatibility detection on the data communication instructions sent by the client in the singleton mode to determine whether the data communication instructions are compatible with the singleton mode and the cluster mode in the Redis server;

[0007] If not, the index value carried in the data communication instruction is obtained, and the index value is rewritten according to a preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value;

[0008] According to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value is obtained from the cluster mapping preset by the Redis server, so as to perform data communication processing according to the access address.

[0009] In combination with the first aspect, in a first possible implementation manner of the first aspect, the step of performing compatibility detection on a data communication instruction sent by the client in the singleton mode to determine whether the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server includes:

[0010] Intercepting the data communication instruction based on a preset proxy middleware, and obtaining an index value carried in the data communication instruction;

[0011] Identify the number of db databases in the singleton mode of the Redis server. If the number of db databases is more than one, traverse each db database according to the index value to determine whether at least two db databases have the index value.

[0012] If at least two db databases have the index value, it is determined that the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server.

[0013] In combination with the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, the step of intercepting the data communication instruction based on a preset proxy middleware includes:

[0014] A communication channel is established between the proxy middleware and the client to monitor the client through the communication channel and intercept data communication instructions sent by the client in singleton mode, and maintain the db database attributes corresponding to the access of the data communication instructions in the communication channel.

[0015] In combination with the second possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, the db database attribute includes at least one of the following: a tcp channel attribute and a database index context attribute.

[0016] In combination with the first aspect, in a fourth possible implementation manner of the first aspect, the step of obtaining the index value carried in the data communication instruction and rewriting the index value according to a preset rewriting rule so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value includes:

[0017] Performing content parsing processing on the data communication instruction to obtain the index value carried in the data communication instruction and the db database attribute accessed by the data communication instruction;

[0018] The index value is rewritten by using the db database attribute as an index value prefix, and the rewritten index value is configured as a new index value of the data communication instruction, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value.

[0019] In combination with the first aspect or the first, second, third or fourth possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, before the step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, further includes:

[0020] On the Redis server, for all data stored in the first db databases set in the original singleton mode, add the db database attribute corresponding to the first db database where each data is located to the original index value of each data to generate a composite index value corresponding to each data, and store each data in the second db database according to the composite index value to form a single cluster mapping, wherein a mapping relationship is established between the composite index value and the data in the second db database;

[0021] The step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, includes:

[0022] According to the rewritten index value, query the composite index value in the second db database to determine the target composite index value in the second db database that is consistent with the rewritten index value;

[0023] According to the target composite index value, target data having a mapping relationship with the target composite index value is obtained from the second db database, and the target data is used for data communication processing.

[0024] In combination with the first aspect or the first, second, third or fourth possible implementation manner of the first aspect, in a sixth possible implementation manner of the first aspect, before the step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, further includes:

[0025] On the Redis server, several db databases originally set in the singleton mode are respectively mapped to the master nodes set in the distributed storage database to form a multi-cluster mapping, wherein, in the distributed storage database, one db database corresponds to one master node;

[0026] The step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, includes:

[0027] According to the db database attribute contained in the rewritten index value, locate the corresponding target master node in the distributed storage database;

[0028] Target data having a mapping relationship with the original index value contained in the rewritten index value is obtained from the data stored in the target master node in the distributed storage database, and the target data is used for data communication processing.

[0029] A second aspect of an embodiment of the present application provides a communication device compatible with redis singleton mode and cluster mode, the communication device compatible with redis singleton mode and cluster mode comprising:

[0030] A compatibility detection module is used to perform compatibility detection on the data communication instructions sent by the client in the singleton mode, and determine whether the data communication instructions are compatible with the singleton mode and the cluster mode in the Redis server;

[0031] An index value rewriting module, used for obtaining the index value carried in the data communication instruction if it is incompatible, and rewriting the index value according to a preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value;

[0032] The data communication processing module is used to obtain an access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server according to the rewritten index value in the data communication instruction, so as to perform data communication processing according to the access address.

[0033] A third aspect of an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the electronic device, wherein when the processor executes the computer program, each step of the communication method compatible with Redis singleton mode and cluster mode provided in the first aspect is implemented.

[0034] The fourth aspect of an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the communication method compatible with Redis singleton mode and cluster mode provided in the first aspect are implemented.

[0035] The embodiments of the present application provide a communication method and device compatible with redis singleton mode and cluster mode, which have the following beneficial effects:

[0036] On the one hand, by performing compatibility detection on the data communication instructions sent by the client in the singleton mode, determine whether the data communication instructions are compatible with the singleton mode and cluster mode in the Redis server; if not compatible, obtain the index value carried in the data communication instruction, and rewrite the index value according to the preset rewriting rules, so that the data communication instruction is compatible with the singleton mode and cluster mode in the Redis server based on the rewritten index value; according to the rewritten index value in the data communication instruction, obtain the access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server, so as to perform data communication processing according to the access address. The front end uses the standard singleton Redis interface to support data communication instructions, and the back end uses the Redis cluster mode and is compatible with all Redis operation instructions sent by the client, realizing the expansion of the singleton db instruction through Redis to cluster data operations, and transparently supporting singleton to cluster.

[0037] On the other hand, in a system compatible with singleton mode and cluster mode, it is a standard singleton for the front-end client, but for the back-end Redis server, it can actively expand the distribution rules of any data, realize the distributed cluster migration of Redis, solve the data storage problem of Redis singleton mode and the CPU limitation of single-core single-process mode, and improve the performance of Redis system; support multi-node parallel master library read and write services, breaking the limitation of single IP port of Redis single-case master node. Moreover, by simulating db, it effectively solves the disadvantage that traditional single-case Redis data cannot be horizontally expanded, and realizes distributed cache docking. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0039] Figure 1 A flow chart of an implementation of a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0040] Figure 2 A flow chart of a method for performing compatibility detection on data communication instructions in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0041] Figure 3 A flow chart of a method for rewriting index values ​​in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0042] Figure 4 A flow chart of a method for performing data communication processing in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0043] Figure 5 A flow chart of another method for performing data communication processing in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0044] Figure 6 A basic structural block diagram of a communication device compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0045] Figure 7 A first detailed structural block diagram of a communication device compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0046] Figure 8 A second detailed structural block diagram of a communication device compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0047] Fig. 9 A third detailed structural block diagram of a communication device compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0048] Fig.10 A fourth detailed structural block diagram of a communication device compatible with redis singleton mode and cluster mode provided in an embodiment of the present application;

[0049] Fig.11 A basic structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0051] See also Figure 1 , Figure 1 The following is a flowchart of a communication method compatible with redis singleton mode and cluster mode provided in the embodiment of the present application.

[0052] S11: Perform compatibility detection on the data communication instruction sent by the client in the singleton mode to determine whether the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server.

[0053] In this embodiment, for the legacy business system, the client uses the original code and connection in the singleton mode to implement the use of the standard singleton Redis interface in the singleton mode to send data communication instructions to access the Redis server. Exemplarily, the data communication instruction can be specifically set to a select db (db database selection) instruction, and the select db instruction carries an index value for accessing the Redis server.

[0054] Db (full name of data base in English) is a database, which is a collection of data organized according to a certain data model and stored in a secondary storage. In singleton mode, different db databases in the Redis server can have the same index value (key value), and the Redis server can identify data with the same key value through db database isolation, thereby avoiding conflicts between the same index values ​​during access. In cluster mode, since a db database is used together, the Redis server no longer supports db database attributes, and data is stored on different nodes of the network according to hash slot partitions. At this time, there is only one db database, that is, there are only db database attributes, which leads to the situation that the key value is not unique when the client uses the selectdb command to access the Redis server in cluster mode, resulting in key conflicts and access errors. In this embodiment, a compatibility check operation on the data communication instruction is specifically performed in a pre-built proxy middleware. Through the compatibility check, it is determined whether the index value carried in the data communication instruction is unique in the cluster mode of the redis server. If it is unique, it is determined that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server. Otherwise, it is determined that the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server.

[0055] For example, please refer to Figure 2 , Figure 2 A flow chart of a method for performing compatibility detection on data communication instructions in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application. Details are as follows:

[0056] S21: intercepting the data communication instruction based on a preset proxy middleware, and obtaining an index value carried in the data communication instruction;

[0057] S22: Identify the number of db databases in the singleton mode of the Redis server. If the number of db databases is more than one, traverse each db database according to the index value to determine whether at least two db databases have the index value.

[0058] S23: If at least two db databases have the index value, it is determined that the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server.

[0059] In this embodiment, the data communication instruction sent in the client singleton mode is intercepted by the proxy middleware, and the index value carried in the data communication instruction is obtained by performing content parsing on the data communication instruction, and then the index value is determined whether the data communication instruction is compatible with the singleton mode and the cluster mode according to the index value. Exemplarily, in this embodiment, the data communication instruction is first intercepted based on the preset proxy middleware, and the index value carried in the data communication instruction is obtained by performing content parsing on the data communication instruction. After obtaining the index value carried in the data communication instruction, by identifying the number of db databases in the singleton mode of the Redis server, if the number of db databases is more than one, each db database is traversed according to the index value to determine whether at least two db databases have the index value. Finally, if at least two db databases have the index value, it is determined that the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server.

[0060] Exemplarily, in some embodiments of the present application, a communication channel can be established between the preset proxy middleware and the client. When the client sends a data communication instruction to implement the operation of accessing the specified database, the client makes the data communication instruction sent by the client sent to the preset proxy middleware through the communication channel, so that the preset proxy middleware has the function of intercepting the data communication instruction sent by the client. After the communication channel is established, the client is monitored for information based on the communication channel to monitor whether the client has sent a data communication instruction to the Redis server in singleton mode. If so, the data communication instruction sent by the client in singleton mode is intercepted and sent to the proxy middleware. After the proxy middleware obtains the data communication instruction, the proxy middleware simulates the response operation of the data communication instruction, generates a response data packet matching the data communication instruction, and returns the response data packet to the client, so as to shield the data communication instruction from the background Redis server, thereby achieving the effect of interception. In addition, based on the channel serial command mode of Redis, when the data communication instruction is intercepted to the proxy middleware through the communication channel, the db database attribute corresponding to the access of the data communication instruction is maintained in the communication channel. The db database attributes include but are not limited to Tcp channel (Transmission Control Protocol channel) attributes, db index (database index context) attributes, etc., so that the client and the proxy middleware need to maintain a connection.

[0061] S12: If the data communication instruction is not compatible with the singleton mode and the cluster mode in the Redis server, obtain the index value carried in the data communication instruction, and rewrite the index value according to a preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value.

[0062] In this embodiment, when the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server, the index value carried in the data communication instruction that is incompatible with the singleton mode and the cluster mode is rewritten, so that the index value carried in the data communication instruction is a unique index value in the cluster mode of the Redis server, thereby making the data communication instruction compatible with the singleton mode and the cluster mode in the Redis server.

[0063] For example, please refer to Figure 3 , Figure 3 A flow chart of a method for rewriting index values ​​in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application. Details are as follows:

[0064] S31: performing content parsing processing on the data communication instruction to obtain an index value carried in the data communication instruction and a database attribute of a db accessed by the data communication instruction;

[0065] S32: rewrite the index value by using the db database attribute as an index value prefix, and configure the rewritten index value as a new index value of the data communication instruction, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value.

[0066] In this embodiment, a rewrite rule for rewriting the index value can be pre-set so that when the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server, the index value is rewritten according to the preset rewrite rule to ensure that the rewritten index value is unique in the cluster mode of the redis server. In this embodiment, the preset rewrite rule includes adding the database attribute corresponding to the data to be accessed in the data communication instruction as an index value prefix to the original index value of the data communication instruction. In this embodiment, the cluster mapping of the Redis server in the cluster mode can be established in advance on the Redis server according to the data distribution characteristics of the original Redis. In the cluster mapping, the unique corresponding access address can be obtained through the index value carried in the data communication instruction and the db database attribute corresponding to the access of the data communication instruction, so that the Redis server still supports responding to the data communication instruction in the cluster mode. For data communication instructions that are detected as incompatible by the proxy middleware, the index value used to access the database in the communication data instruction is rewritten, and a prefix containing the db database attribute is added to the original index value, so that the rewritten index value is accompanied by the db database attribute (i.e., db+key), thereby ensuring that the rewritten index value is unique in the cluster mode of the redis server. Exemplarily, in this embodiment, the database attribute corresponding to the data to be accessed in the data communication instruction is represented as the db database attribute corresponding to the data communication instruction maintained in the communication channel.

[0067] S13: According to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value is obtained from the cluster mapping preset by the Redis server, so as to perform data communication processing according to the access address.

[0068] In this embodiment, after the data communication instruction is made compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value, the cluster mapping preset by the Redis server can be traversed according to the rewritten index value, and the data access address corresponding to the rewritten index value can be obtained from the cluster mapping based on the mapping relationship between the index value in the cluster mapping and the data access address. In this embodiment, for the operation instruction detected as compatible by the proxy middleware, it can be directly forwarded to the Redis server, and the corresponding target cluster can be found from the cluster reallocated in the cluster mode of the back-end Redis server according to the index value in the operation instruction for connection, so as to obtain the data access address corresponding to the rewritten index value, thereby reducing the performance overhead of the system.

[0069] As can be seen from the above, in the communication method compatible with redis singleton mode and cluster mode provided by the present embodiment, a compatibility check is performed on the data communication instructions sent by the client in the singleton mode. For the data communication instructions that are incompatible with the singleton mode and the cluster mode in the Redis server, the index value carried in the data communication instruction is obtained, and the index value carried in the data communication instruction is rewritten according to the preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value, so that Redis can be connected through the distributed cache in the singleton working mode scenario, is compatible with the redis singleton mode and the cluster mode, improves the performance of the Redis system, and solves the problems of data storage in the Redis singleton mode, single-core single-process mode CPU (full name Central Processing Unit) limitation, and single-instance Redis data cannot be horizontally expanded.

[0070] In some embodiments of this application, please refer to Figure 4 , Figure 4 A flow chart of a method for data communication processing in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application. Details are as follows:

[0071] S41: querying the composite index value in the second db database according to the rewritten index value, and determining a target composite index value in the second db database that is consistent with the rewritten index value;

[0072] S42: According to the target composite index value, target data having a mapping relationship with the target composite index value is obtained from the second db database, and the target data is used for data communication processing.

[0073] In this embodiment, on the Redis server side, for all data stored in several first db databases set in the original singleton mode, the db database attribute corresponding to the first db database where each data is located is added to the original index value of each data to generate a composite index value corresponding to each data. In this embodiment, the composite index value is expressed in the form of db+key, where db is the db database attribute corresponding to the first db database where the data is originally located, and key is the index value corresponding to the data when it is stored in the first db database where the data is originally located. After the corresponding composite index value is generated for each data, the data can be uniformly stored in the second db database according to the composite index value of the data, so as to form a preset single cluster mapping based on the second db database on the Redis server side. In the second db database, a mapping relationship is established between the composite index value and the data. Based on the preset single cluster mapping, when obtaining the access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server, the composite index value in the second db database can be specifically determined by querying the composite index value in the second db database according to the rewritten index value. The target composite index value consistent with the rewritten index value in the second db database. In this embodiment, the rewritten index value is consistent with the target composite index value, which is manifested by the consistency of the db database attributes and the key. After determining the target composite index value, according to the target composite index value, the target data having a mapping relationship with the target composite index value is obtained from the second db database. The location of the target data in the second db database is the access address. After the target data is obtained from the access address, the target data can be used for data communication processing.

[0074] In some embodiments of this application, please refer to Figure 5 , Figure 5 A flow chart of another method for performing data communication processing in a communication method compatible with redis singleton mode and cluster mode provided in an embodiment of the present application. Details are as follows:

[0075] S51: According to the db database attribute contained in the rewritten index value, the corresponding target master node is located in the distributed storage database;

[0076] S52: Obtain target data having a mapping relationship with the original index value included in the rewritten index value from the data stored in the target master node in the distributed storage database, and use the target data for data communication processing.

[0077] In the present embodiment, the redis cluster mechanism is a distributed storage technology of redis, which is used for distributed management of data. There are 16384 fixed hash slots in the redis cluster mechanism. By writing multiple master nodes (main nodes) in the redis cluster, each master node holds part of the hash slots, such as writing 3 master nodes, then each master node holds more than 5000 hash slots, when adding master nodes, a part of the hash slots held by other master nodes will be moved to the newly added master node, and when reducing master nodes, the hash slots held by the reduced master nodes will be moved to other master nodes. Based on the redis cluster mechanism, each stored data can only exist in one master node, and different master nodes store different data, so as to realize the distributed storage of data. Exemplary, assuming that there are 100w data stored in 5 master nodes, each master is responsible for storing 20w data. Under the redis cluster mechanism, the master node can be expanded arbitrarily, and when the system needs to support a larger read throughput, write throughput or data volume, it can be expanded horizontally by directly adding master nodes.

[0078] In this embodiment, on the Redis server side, based on the number of several db databases set in the original singleton mode, a distributed storage database including several master nodes is established by using the redis cluster mechanism, wherein the number of master nodes is the same as the number of several db databases set in the original singleton mode. Then, the several db databases set in the original singleton mode are respectively mapped to the master nodes set in the distributed storage database, wherein, in the distributed storage database, one db database corresponds to one master node, so as to form a preset multi-cluster mapping based on the distributed storage database on the Redis server side. Based on the preset multi-cluster mapping, when obtaining the access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server side, specifically, according to the db database attribute contained in the rewritten index value, in the distributed storage database, by the correspondence between the db database set in the original singleton mode and the master node, the master node corresponding to the db database attribute in the distributed storage database can be queried, and the master node is the target master node, thereby locating the corresponding target master node. After locating the target master node, the target data stored in the target master node is searched in the distributed storage database according to the original index value contained in the rewritten index value, so as to obtain the target data having a mapping relationship with the original index value contained in the rewritten index value. The location of the target data at the target master node in the distributed storage database is the access address. After obtaining the target data at the access address, the target data can be used for data communication processing.

[0079] In this embodiment, by using the redis cluster mechanism, in a system compatible with singleton mode and cluster mode, it is a standard singleton for the front-end client, but for the back-end Redis server, it can actively expand the distribution rules of any data, realize the distributed cluster migration of Redis, solve the data storage problem of Redis singleton mode and the CPU limitation of single-core single-process mode, and improve the performance of Redis system; support multi-node parallel master library read and write services, breaking through the limitation of single IP port of Redis single-case master node. Moreover, by simulating db, it effectively solves the disadvantage that traditional single-case redis data cannot be horizontally expanded, and realizes distributed cache docking.

[0080] It is understandable that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0081] In some embodiments of this application, please refer to Figure 6 , Figure 6 The basic structure block diagram of a communication device compatible with redis singleton mode and cluster mode provided in the embodiment of the present application. The various units included in the device in this embodiment are used to execute the various steps in the above method embodiment. Please refer to the relevant description in the above method embodiment for details. For ease of explanation, only the parts related to this embodiment are shown. Figure 6 As shown, the communication device compatible with redis singleton mode and cluster mode includes: a compatibility detection module 61, an index value rewriting module 62 and a data communication processing module 63. Among them: the compatibility detection module 61 is used to perform compatibility detection on the data communication instruction sent by the client in the singleton mode, and determine whether the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server. The index value rewriting module 62 is used to obtain the index value carried in the data communication instruction if it is not compatible, and rewrite the index value according to the preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value. The data communication processing module 63 is used to obtain the access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server according to the rewritten index value in the data communication instruction, so as to perform data communication processing according to the access address.

[0082] In some embodiments of this application, please refer to Figure 7 , Figure 7 The first detailed structural block diagram of the communication device compatible with redis singleton mode and cluster mode provided in the embodiment of the present application. Figure 7 As shown, the communication device compatible with redis singleton mode and cluster mode also includes: a first acquisition submodule 71, a first judgment submodule 72 and a second judgment submodule 73. Among them, the first acquisition submodule 71 is used to intercept the data communication instruction based on the preset proxy middleware and obtain the index value carried in the data communication instruction. The first judgment submodule 72 is used to identify the number of db databases in the singleton mode of the Redis server. If the number of db databases is more than one, each db database is traversed according to the index value to determine whether at least two db databases have the index value. The second judgment submodule 73 is used to determine that the data communication instruction is not compatible with the singleton mode and cluster mode in the Redis server if at least two db databases have the index value.

[0083] In some embodiments of the present application, the communication device compatible with Redis singleton mode and cluster mode also includes a first establishment sub-module, which is used to establish a communication channel between the proxy middleware and the client, so as to monitor the client through the communication channel and intercept data communication instructions sent by the client in the singleton mode, and maintain the db database attributes corresponding to the access of the data communication instructions in the communication channel.

[0084] In some embodiments of this application, please refer to Figure 8 , Figure 8 The second detailed structural block diagram of the communication device compatible with redis singleton mode and cluster mode provided in the embodiment of the present application. Figure 8 As shown, the communication device compatible with redis singleton mode and cluster mode also includes: a second acquisition submodule 81 and a first rewriting submodule 82. Among them, the second acquisition submodule 81 is used to perform content parsing processing on the data communication instruction, and obtain the index value carried in the data communication instruction and the db database attribute corresponding to the data communication instruction. The first rewriting submodule 82 is used to rewrite the index value using the db database attribute as the index value prefix, and configure the rewritten index value as the new index value of the data communication instruction, so that the data communication instruction is compatible with the singleton mode and cluster mode in the Redis server based on the rewritten index value.

[0085] In some embodiments of this application, please refer to Fig. 9 , Fig. 9 The third detailed structural block diagram of the communication device compatible with redis singleton mode and cluster mode provided in the embodiment of the present application. Fig. 9 As shown, the communication device compatible with redis singleton mode and cluster mode also includes: a first query submodule 91 and a first communication submodule 92. The first query submodule 91 is used to query the composite index value in the second db database according to the rewritten index value, and determine the target composite index value in the second db database that is consistent with the rewritten index value. The first communication submodule 92 is used to obtain target data having a mapping relationship with the target composite index value from the second db database according to the target composite index value, and use the target data for data communication processing.

[0086] In some embodiments of this application, please refer to Fig.10 , Fig.10 The fourth detailed structural block diagram of the communication device compatible with redis singleton mode and cluster mode provided in the embodiment of the present application. Fig.10As shown, the communication device compatible with redis singleton mode and cluster mode also includes: a first positioning submodule 101 and a second communication submodule 102. Among them, the first positioning submodule 101 is used to locate the corresponding target master node in the distributed storage database according to the db database attribute contained in the rewritten index value. The second communication submodule 102 is used to obtain target data having a mapping relationship with the original index value contained in the rewritten index value from the data stored in the target master node in the distributed storage database, and use the target data for data communication processing.

[0087] In some embodiments of this application, please refer to Fig.11 , Fig.11 This is a basic structural block diagram of an electronic device provided in an embodiment of the present application. Fig.11 As shown, the electronic device 11 of this embodiment includes: a processor 111, a memory 112, and a computer program 113 stored in the memory 112 and executable on the processor 111, such as a program for a communication method compatible with redis singleton mode and cluster mode. When the processor 111 executes the computer program 113, the steps in each embodiment of the communication method compatible with redis singleton mode and cluster mode are implemented. Alternatively, when the processor 111 executes the computer program 113, the functions of each module in the embodiment corresponding to the communication device compatible with redis singleton mode and cluster mode are implemented. Please refer to the relevant description in the embodiment for details, which will not be repeated here.

[0088] Exemplarily, the computer program 113 may be divided into one or more modules (units), the one or more modules are stored in the memory 112, and are executed by the processor 111 to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 113 in the electronic device 11. For example, the computer program 113 may be divided into a color analysis module, a similarity comparison module, a label acquisition module, and a first image search module, and the specific functions of each module are as described above.

[0089] The electronic device may include, but is not limited to, a processor 111 and a memory 112. Those skilled in the art will appreciate that Fig.11 It is only an example of the electronic device 11 and does not constitute a limitation of the electronic device 11. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device may also include input and output devices, network access devices, buses, etc.

[0090] The processor 111 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0091] The memory 112 may be an internal storage unit of the electronic device 11, such as a hard disk or memory of the electronic device 11. The memory 112 may also be an external storage device of the electronic device 11, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 11. Further, the memory 112 may also include both an internal storage unit of the electronic device 11 and an external storage device. The memory 112 is used to store the computer program and other programs and data required by the electronic device. The memory 112 may also be used to temporarily store data that has been output or is to be output.

[0092] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0093] The embodiment of the present application also provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented. In this embodiment, the computer-readable storage medium can be non-volatile or volatile.

[0094] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0095] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0096] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0097] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0098] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A communication method compatible with redis singleton mode and cluster mode, characterized in that: include: Perform compatibility detection on the data communication instructions sent by the client in the singleton mode to determine whether the data communication instructions are compatible with the singleton mode and the cluster mode in the Redis server; If not, the index value carried in the data communication instruction is obtained, and the index value is rewritten according to a preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value; According to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value is obtained from the cluster mapping preset by the Redis server, so as to perform data communication processing according to the access address; Before the step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server, and performing data communication processing according to the access address, the step further includes: On the Redis server, several db databases originally set in the singleton mode are respectively mapped to the master nodes set in the distributed storage database to form a multi-cluster mapping, wherein, in the distributed storage database, one db database corresponds to one master node; The step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, includes: According to the db database attribute contained in the rewritten index value, locate the corresponding target master node in the distributed storage database; Target data having a mapping relationship with the original index value contained in the rewritten index value is obtained from the data stored in the target master node in the distributed storage database, and the target data is used for data communication processing.

2. The communication method compatible with redis singleton mode and cluster mode according to claim 1, characterized in that: The step of performing compatibility detection on the data communication instruction sent by the client in the singleton mode to determine whether the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server includes: Intercepting the data communication instruction based on a preset proxy middleware, and obtaining an index value carried in the data communication instruction; Identify the number of db databases in the singleton mode of the Redis server. If the number of db databases is more than one, traverse each db database according to the index value to determine whether at least two db databases have the index value. If at least two db databases have the index value, it is determined that the data communication instruction is incompatible with the singleton mode and the cluster mode in the Redis server.

3. The communication method compatible with redis singleton mode and cluster mode according to claim 2, characterized in that: The step of intercepting the data communication instruction based on the preset proxy middleware includes: A communication channel is established between the proxy middleware and the client to monitor the client through the communication channel and intercept data communication instructions sent by the client in singleton mode, and maintain the db database attributes corresponding to the access of the data communication instructions in the communication channel.

4. The communication method compatible with redis singleton mode and cluster mode according to claim 3, characterized in that: The db database attribute includes at least one of the following: a tcp channel attribute and a database index context attribute.

5. The communication method compatible with redis singleton mode and cluster mode according to claim 1, characterized in that: The step of obtaining the index value carried in the data communication instruction and rewriting the index value according to a preset rewriting rule so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value includes: Performing content parsing processing on the data communication instruction to obtain the index value carried in the data communication instruction and the db database attribute accessed by the data communication instruction; The index value is rewritten by using the db database attribute as an index value prefix, and the rewritten index value is configured as a new index value of the data communication instruction, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value.

6. The communication method compatible with redis singleton mode and cluster mode according to any one of claims 1 to 5, characterized in that: Before the step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server, and performing data communication processing according to the access address, the step further includes: On the Redis server, for all data stored in the first db databases set in the original singleton mode, add the db database attribute corresponding to the first db database where each data is located to the original index value of each data to generate a composite index value corresponding to each data, and store each data in the second db database according to the composite index value to form a single cluster mapping, wherein a mapping relationship is established between the composite index value and the data in the second db database; The step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, includes: According to the rewritten index value, query the composite index value in the second db database to determine the target composite index value in the second db database that is consistent with the rewritten index value; According to the target composite index value, target data having a mapping relationship with the target composite index value is obtained from the second db database, and the target data is used for data communication processing.

7. A communication device compatible with redis singleton mode and cluster mode, characterized in that: The communication device compatible with redis singleton mode and cluster mode includes: A compatibility detection module is used to perform compatibility detection on the data communication instructions sent by the client in the singleton mode, and determine whether the data communication instructions are compatible with the singleton mode and the cluster mode in the Redis server; An index value rewriting module, used for obtaining the index value carried in the data communication instruction if it is incompatible, and rewriting the index value according to a preset rewriting rule, so that the data communication instruction is compatible with the singleton mode and the cluster mode in the Redis server based on the rewritten index value; A data communication processing module, used to obtain an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server according to the rewritten index value in the data communication instruction, so as to perform data communication processing according to the access address; Before the step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from the cluster mapping preset by the Redis server, and performing data communication processing according to the access address, the step further includes: On the Redis server, several db databases originally set in the singleton mode are respectively mapped to the master nodes set in the distributed storage database to form a multi-cluster mapping, wherein, in the distributed storage database, one db database corresponds to one master node; The step of obtaining, according to the rewritten index value in the data communication instruction, an access address corresponding to the rewritten index value from a cluster mapping preset by the Redis server, and performing data communication processing according to the access address, includes: According to the db database attribute contained in the rewritten index value, locate the corresponding target master node in the distributed storage database; Target data having a mapping relationship with the original index value contained in the rewritten index value is obtained from the data stored in the target master node in the distributed storage database, and the target data is used for data communication processing.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Start-up smart cloud low-code platform

    CN112256248A

  • Master data management technologies

    US20210089512A1