Redis dynamic configuration method, device and equipment and storage medium
Patent Information
- Application Number
- CN202510725333.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-30
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2045-05-30
AI Technical Summary
[0003]为了解决采用Redis配置需要经过重启生效,配置不灵活的问题,本申请提供以下技术方案:
[0040]通过实施本申请实施例公开的一种Redis动态配置方法、装置、设备及存储介质,能够利用配置中心实现监听和自动更新Redis节点配置;动态调整租户与Redis节点的映射关系,支持租户间的资源调整和灵活扩展,动态调整Redis配置参数而无需重启服务器,是配置生效。
Smart Images

Figure CN120780716B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a Redis dynamic configuration method, device, and storage medium. Background Technology
[0002] In a multi-tenant SaaS environment, some tenants need to use independent Redis instances. To meet the high concurrency and isolation requirements of the service, the service typically needs to manage multiple Redis connections. However, traditional Redis connection management methods have many limitations. Traditional Redis connection management uses static configuration files to manage Redis node connections and connection pool parameters. For example, the configuration file contains the URL address of each Redis node and related connection parameters. If a new Redis node needs to be added or connection pool parameters need to be adjusted, the configuration file must be manually modified and the service restarted for the configuration to take effect. This makes adding or removing nodes highly limited, connection pool adjustments inflexible, and the maintainability of the mapping relationship between tenants and Redis nodes poor. Summary of the Invention
[0003] To address the issue of Redis configuration requiring a restart to take effect and its inflexibility, this application provides the following technical solution:
[0004] Firstly, a method for dynamic Redis configuration is provided, including:
[0005] Monitor updates to configuration parameters for any Redis node in Nacos, as well as updates to the user-Redis mapping relationship. Configuration parameters are used to adjust the performance of Redis, and the mapping relationship is used to configure the correspondence between users and Redis.
[0006] Based on the updates to configuration parameters and mapping relationships, determine the update information corresponding to the Redis node;
[0007] The update information is broadcast to any Redis node so that the configuration center can receive the update information;
[0008] The configuration center updates the settings of the corresponding Redis nodes based on the updated information.
[0009] Furthermore, before monitoring updates to configuration parameters for any Redis node in Nacos and updates to the user-Redis mapping, the following steps are also included:
[0010] Associate Nacos with the service items of the Redis node;
[0011] Configure the Nacos connection information and listening rules in the Redis node's configuration file;
[0012] Connect Nacos to the Redis node to obtain the Redis configuration file template, so that Nacos can collect and update the configuration parameters and mapping relationships according to the configuration file template.
[0013] Start Naco listener on the Redis node.
[0014] Furthermore, monitor updates to configuration parameters for any Redis node in Nacos, as well as updates to the user-Redis mapping relationship, including:
[0015] The callback function is triggered when configuration parameters and / or mapping relationships are updated;
[0016] The updated configuration parameters and / or updated mapping relationships are parsed through callback functions;
[0017] Extract the Redis nodes corresponding to the updated configuration parameters and / or updated mapping relationships.
[0018] Furthermore, after broadcasting the update information to any Redis node so that the configuration center can receive the update information, it also includes:
[0019] The configuration center parses the update information to obtain the updated configuration parameters and the updated mapping relationships.
[0020] Furthermore, the configuration center updates the settings of the corresponding Redis nodes based on the updated information, including:
[0021] Initialize the Redis configuration parameters with the updated configuration parameters to make the Redis configuration parameters take effect;
[0022] Replace the original mapping in Redis with the updated mapping to make the Redis mapping take effect.
[0023] Furthermore, the configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time;
[0024] Initialize Redis configuration parameters with the updated configuration parameters to make the Redis configuration parameters take effect, including:
[0025] Update the URL of the Redis node;
[0026] Update the maximum and minimum number of connections for each Redis node;
[0027] Initialize the Redis node configuration with the updated URL address, updated maximum number of connections, and minimum number of connections to make the configuration parameters of the Redis node effective.
[0028] Furthermore, the configuration center performs Redis settings based on the updated configuration parameters and the updated mapping relationships, including:
[0029] Update the user corresponding to the Redis node in the connection pool corresponding to the Redis node, so as to update the user-Redis mapping relationship;
[0030] Based on the updated user-Redis mapping, new users are routed to this Redis node.
[0031] Secondly, a Redis dynamic configuration device is provided, including:
[0032] The monitoring module is used to monitor updates to the configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship. The configuration parameters are used to adjust the performance of Redis, and the mapping relationship is used to configure the correspondence between users and Redis.
[0033] The information generation module is used to determine the update information corresponding to the Redis node based on the updates to configuration parameters and mapping relationships.
[0034] The broadcast module is used to broadcast update information to any Redis node so that the configuration center can receive the update information;
[0035] The update module is used to update the settings of the corresponding Redis nodes in the configuration center based on the update information.
[0036] Thirdly, a computer program product is provided, including a computer program that, when executed by a processor, implements the Redis dynamic configuration method described in the first aspect.
[0037] Fourthly, a computer-readable storage medium is provided, on which a Redis dynamic configuration program is stored, wherein when the Redis dynamic configuration program is executed by a processor, the Redis dynamic configuration method described in the first aspect is implemented.
[0038] Fifthly, a computer device is provided, including a memory, a processor, and a Redis dynamic configuration program stored in the memory and executable on the processor. When the processor executes the Redis dynamic configuration program, it implements the Redis dynamic configuration method described in the first aspect.
[0039] The beneficial effects of the technical solutions provided in this application are:
[0040] By implementing the Redis dynamic configuration method, apparatus, device, and storage medium disclosed in the embodiments of this application, it is possible to use the configuration center to monitor and automatically update the Redis node configuration; dynamically adjust the mapping relationship between tenants and Redis nodes, support resource adjustment and flexible expansion between tenants, and dynamically adjust Redis configuration parameters without restarting the server, so that the configuration takes effect. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 This is a schematic diagram of a Redis dynamic configuration method provided in an embodiment of this application;
[0043] Figure 2 This is a schematic diagram of a Redis dynamic configuration device provided in an embodiment of this application;
[0044] Figure 3 This is a schematic diagram of a computer device provided in an embodiment of this application. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0046] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms “first,” “second,” and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an,” “a,” or “the,” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The numbers in the accompanying drawings are only used to distinguish individual functional parts or modules and do not indicate logical relationships between parts or modules. The terms “comprising,” “including,” or “including,” and similar terms mean that the element or object preceding the term encompasses the element or object listed following the term and its equivalents, without excluding other elements or objects. The terms “connected,” “linked,” and similar terms are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. “Above,” “below,” “left,” “right,” etc., are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0047] The various embodiments according to this disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that in the drawings, the same reference numerals are assigned to components having substantially the same or similar structure and function, and repeated descriptions of them will be omitted.
[0048] To address the issue that Redis configurations require a restart to take effect and are inflexible, this application provides the following embodiments.
[0049] In some embodiments, such as Figure 1 As shown, a Redis dynamic configuration method includes:
[0050] S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the mapping relationship between users and Redis. Configuration parameters are used to adjust the performance of Redis, and mapping relationships are used to configure the correspondence between users and Redis.
[0051] S200: Determine the update information corresponding to the Redis node based on the update of configuration parameters and the update of mapping relationships;
[0052] S300: Broadcasts update information to any Redis node so that the configuration center can receive the update information;
[0053] S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information.
[0054] Node configuration parameters are obtained from stress test results.
[0055] Schematically, for a Redis configured with 1 core and 2GB of memory, and a server configured with 4 cores and 8GB of memory, the single-machine performance of the server is shown in Table 1.
[0056] Table 1 Single-machine performance of server
[0057] 8 150 90 110 16 280 95 120 32 450 105 135 64 600 125 160 128 700 160 220
[0058] From Table 1, the configuration parameters corresponding to the optimal performance can be obtained.
[0059] For example: when the number of connections is 8 and 16: Redis is under low pressure, the response time remains close to the normal level, and QPS increases linearly with the rise of the number of connections; when the number of connections is 32 and 64: Redis begins to approach the bottleneck, and the response time rises significantly; when the number of connections is 128: Redis is obviously overloaded, although the number of connections is large, the growth of QPS slows down, and the response time and TP95 deteriorate significantly.
[0060] Preferably, before S100: monitoring the update of configuration parameters of any Redis node and the update of the mapping relationship between users and Redis in Nacos, the method further comprises:
[0061] S010: associating Nacos with the service item of the Redis node;
[0062] S020: setting the connection information and monitoring rules of Nacos in the configuration file of the Redis node;
[0063] S030: connecting Nacos with the Redis node, acquiring the configuration file template of Redis, so that Nacos can collect the updated configuration parameters and the updated mapping relationship corresponding to the configuration file template;
[0064] S040: starting Nacos monitoring on the Redis node.
[0065] In the server-side project, introduce the dependencies of Nacos service discovery and configuration management, and configure relevant parameters.
[0066] Schematically, the association is performed in the following manner:
[0067] spring:
[0068] cloud:
[0069] nacos:
[0070] discovery:
[0071] server-addr:<Nacos server address>
[0072] config:
[0073] server-addr:<Nacos server address>
[0074] file-extension: yaml,
[0075] A configuration file template related to Redis is set. The configuration file template contains basic information such as node URLs and connection pool parameters.
[0076] In addition, independent connection pool parameters are configured for each Redis node separately, and the connection pool parameters include: maximum number of connections, number of idle connections.
[0077] Illustratively, the configuration method for the connection pool parameters is as follows:
[0078] redis:
[0079] nodes:
[0080] -name:node1
[0081] url:redis: / / 192.168.1.10:6379
[0082] pool:
[0083] max-active:50
[0084] max-idle:10
[0085] min-idle:5
[0086] -name:node2
[0087] url:redis: / / 192.168.1.11:6379
[0088] pool:
[0089] max-active:100
[0090] max-idle:20
[0091] min-idle:10
[0092] tenant-mapping:
[0093] tenant1:node1
[0094] tenant2:node2
[0095] Specifically, S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, including:
[0096] S110: Trigger a callback function when configuration parameters and / or mapping relationships are updated;
[0097] S120: Parse the updated configuration parameters and / or updated mapping relationships through callback functions;
[0098] S130: Extract the Redis node corresponding to the updated configuration parameters and / or the updated mapping relationship.
[0099] By listening, the server can obtain Nacos configuration change events and update the connection pool parameters independently for each Redis node.
[0100] To illustrate, the listening mechanism is implemented as follows:
[0101] @NacosConfigListener(dataId="redis-config",groupId="DEFAULT_GROUP",
[0102] timeout=3000)
[0103] public void onConfigChange(String configContent){
[0104] / / Parse configuration content
[0105] RedisConfig redisConfig=parseConfig(configContent);
[0106] / / Update the connection pool configuration for each Redis node
[0107] for(RedisNode node:redisConfig.getNodes()){
[0108] RedisConnectionPool pool =
[0109] redisConnectionManager.getPool(node.getName());
[0110] pool.setMaxActive(node.getPool().getMaxActive());
[0111] pool.setMaxIdle(node.getPool().getMaxIdle());
[0112] pool.setMinIdle(node.getPool().getMinIdle());
[0113] }
[0114] / / Update the mapping between tenants and Redis nodes
[0115] updateTenantMapping(redisConfig.getTenantMapping());
[0116] }
[0117] Specifically, S300: After broadcasting the update information to any Redis node so that the configuration center can receive the update information, it also includes:
[0118] S310: The configuration center parses the update information to obtain the updated configuration parameters and the updated mapping relationships.
[0119] Specifically, S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information, including:
[0120] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective;
[0121] S420: Replaces the original mapping in Redis with the updated mapping, making the Redis mapping effective.
[0122] Specifically, the configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time;
[0123] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective, including:
[0124] S411: Update the URL address of the Redis node;
[0125] S412: Update the maximum and minimum number of connections for a Redis node;
[0126] S413: Initialize the Redis node configuration with the updated URL address, updated maximum number of connections, and minimum number of connections, and make the configuration parameters of the Redis node effective.
[0127] The connection pool parameters for each Redis node are managed through the Nacos configuration center. The server dynamically adjusts the corresponding connection pool configuration based on detected changes. For example, if the workload of a node increases, its `maxactive` parameter can be adjusted from 50 to 100 in Nacos, and the change will take effect immediately on the server. If a node needs to reduce resource consumption, its `max-idle` and `min-idle` parameters can be adjusted, and the server will update them synchronously.
[0128] Specifically, S400: The configuration center performs Redis settings based on the updated configuration parameters and the updated mapping relationships, and also includes:
[0129] S451: Update the user corresponding to the Redis node in the connection pool corresponding to the Redis node, so as to update the user-Redis mapping relationship;
[0130] S452: Based on the updated user-Redis mapping, route new users to this Redis node.
[0131] If you need to adjust the Redis node corresponding to a tenant, simply update the `tenantmapping` field in the Nacos configuration center. The server will then detect the update and modify the mapping relationship between the tenant and the Redis node in real time. For example:
[0132] tenant-mapping:
[0133] tenant1:node3# This sets the Redis node of tenant1 to node3.
[0134] In Nacos, modifications to connection pool parameters (such as maximum number of connections, idle time, etc.) are automatically applied by the server upon detecting the changes. The automatic application process is illustrated below:
[0135] private void updateConnectionPool(PoolConfig poolConfig){
[0136] redisConnectionPool.setMaxActive(poolConfig.getMaxActive());
[0137] redisConnectionPool.setMaxIdle(poolConfig.getMaxIdle());
[0138] redisConnectionPool.setMinIdle(poolConfig.getMinIdle());
[0139] }
[0140] It should be understood that, although Figure 1 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0141] In other embodiments, such as Figure 2 As shown, a Redis dynamic configuration device includes:
[0142] The monitoring module is used to monitor updates to the configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship. The configuration parameters are used to adjust the performance of Redis, and the mapping relationship is used to configure the correspondence between users and Redis.
[0143] The information generation module is used to determine the update information corresponding to the Redis node based on the updates to configuration parameters and mapping relationships.
[0144] The broadcast module is used to broadcast update information to any Redis node so that the configuration center can receive the update information;
[0145] The update module is used to update the settings of the corresponding Redis nodes in the configuration center based on the update information.
[0146] For specific limitations regarding the Redis dynamic configuration device described above, please refer to the limitations of the Redis dynamic configuration method above, which will not be repeated here. Each module in the aforementioned Redis dynamic configuration device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0147] In other embodiments, such as Figure 3As shown, a computer device includes a memory, a processor, and a Redis dynamic configuration program stored in the memory and executable on the processor. When the processor executes the Redis dynamic configuration program, it implements the Redis dynamic configuration method described in the preceding embodiments, specifically including:
[0148] S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the mapping relationship between users and Redis. Configuration parameters are used to adjust the performance of Redis, and mapping relationships are used to configure the correspondence between users and Redis.
[0149] S200: Determine the update information corresponding to the Redis node based on the update of configuration parameters and the update of mapping relationships;
[0150] S300: Broadcasts update information to any Redis node so that the configuration center can receive the update information;
[0151] S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information.
[0152] Preferably, before monitoring updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, S100 further includes:
[0153] S010: Associate Nacos with the service items of the Redis node;
[0154] S020: Configure the Nacos connection information and listening rules in the Redis node's configuration file;
[0155] S030: Connect Nacos to the Redis node and obtain the Redis configuration file template so that Nacos can collect and update the configuration parameters and the updated mapping relationship according to the configuration file template.
[0156] S040: Start Naco listener on the Redis node.
[0157] Specifically, S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, including:
[0158] S110: Trigger a callback function when configuration parameters and / or mapping relationships are updated;
[0159] S120: Parse the updated configuration parameters and / or updated mapping relationships through callback functions;
[0160] S130: Extract the Redis node corresponding to the updated configuration parameters and / or the updated mapping relationship.
[0161] Specifically, S300: After broadcasting the update information to any Redis node so that the configuration center can receive the update information, it also includes:
[0162] S310: The configuration center parses the update information to obtain the updated configuration parameters and the updated mapping relationships.
[0163] Specifically, S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information, including:
[0164] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective;
[0165] S420: Replaces the original mapping in Redis with the updated mapping, making the Redis mapping effective.
[0166] Specifically, the configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time;
[0167] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective, including:
[0168] S411: Update the URL address of the Redis node;
[0169] S412: Update the maximum and minimum number of connections for a Redis node;
[0170] S413: Initialize the Redis node configuration with the updated URL address, updated maximum number of connections, and minimum number of connections, and make the configuration parameters of the Redis node effective.
[0171] Specifically, S400: The configuration center performs Redis settings based on the updated configuration parameters and the updated mapping relationships, and also includes:
[0172] S451: Update the user corresponding to the Redis node in the connection pool corresponding to the Redis node, so as to update the user-Redis mapping relationship;
[0173] S452: Based on the updated user-Redis mapping, route new users to this Redis node.
[0174] In other embodiments, a computer program product includes a computer program that, when executed by a processor, implements the Redis dynamic configuration method described in the preceding embodiments, specifically including:
[0175] S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the mapping relationship between users and Redis. Configuration parameters are used to adjust the performance of Redis, and mapping relationships are used to configure the correspondence between users and Redis.
[0176] S200: Determine the update information corresponding to the Redis node based on the update of configuration parameters and the update of mapping relationships;
[0177] S300: Broadcasts update information to any Redis node so that the configuration center can receive the update information;
[0178] S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information.
[0179] Preferably, before monitoring updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, S100 further includes:
[0180] S010: Associate Nacos with the service items of the Redis node;
[0181] S020: Configure the Nacos connection information and listening rules in the Redis node's configuration file;
[0182] S030: Connect Nacos to the Redis node and obtain the Redis configuration file template so that Nacos can collect and update the configuration parameters and the updated mapping relationship according to the configuration file template.
[0183] S040: Start Naco listener on the Redis node.
[0184] Specifically, S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, including:
[0185] S110: Trigger a callback function when configuration parameters and / or mapping relationships are updated;
[0186] S120: Parse the updated configuration parameters and / or updated mapping relationships through callback functions;
[0187] S130: Extract the Redis node corresponding to the updated configuration parameters and / or the updated mapping relationship.
[0188] Specifically, S300: After broadcasting the update information to any Redis node so that the configuration center can receive the update information, it also includes:
[0189] S310: The configuration center parses the update information to obtain the updated configuration parameters and the updated mapping relationships.
[0190] Specifically, S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information, including:
[0191] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective;
[0192] S420: Replaces the original mapping in Redis with the updated mapping, making the Redis mapping effective.
[0193] Specifically, the configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time;
[0194] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective, including:
[0195] S411: Update the URL address of the Redis node;
[0196] S412: Update the maximum and minimum number of connections for a Redis node;
[0197] S413: Initialize the Redis node configuration with the updated URL address, updated maximum number of connections, and minimum number of connections, and make the configuration parameters of the Redis node effective.
[0198] Specifically, S400: The configuration center performs Redis settings based on the updated configuration parameters and the updated mapping relationships, and also includes:
[0199] S451: Update the user corresponding to the Redis node in the connection pool corresponding to the Redis node, so as to update the user-Redis mapping relationship;
[0200] S452: Based on the updated user-Redis mapping, route new users to this Redis node.
[0201] In other embodiments, a computer-readable storage medium stores a Redis dynamic configuration program thereon. When executed by a processor, the Redis dynamic configuration program implements the Redis dynamic configuration method described in the preceding embodiments, specifically including:
[0202] S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the mapping relationship between users and Redis. Configuration parameters are used to adjust the performance of Redis, and mapping relationships are used to configure the correspondence between users and Redis.
[0203] S200: Determine the update information corresponding to the Redis node based on the update of configuration parameters and the update of mapping relationships;
[0204] S300: Broadcasts update information to any Redis node so that the configuration center can receive the update information;
[0205] S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information.
[0206] Preferably, before monitoring updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, S100 further includes:
[0207] S010: Associate Nacos with the service items of the Redis node;
[0208] S020: Configure the Nacos connection information and listening rules in the Redis node's configuration file;
[0209] S030: Connect Nacos to the Redis node and obtain the Redis configuration file template so that Nacos can collect and update the configuration parameters and the updated mapping relationship according to the configuration file template.
[0210] S040: Start Naco listener on the Redis node.
[0211] Specifically, S100: Monitors updates to configuration parameters of any Redis node in Nacos and updates to the user-Redis mapping relationship, including:
[0212] S110: Trigger a callback function when configuration parameters and / or mapping relationships are updated;
[0213] S120: Parse the updated configuration parameters and / or updated mapping relationships through callback functions;
[0214] S130: Extract the Redis node corresponding to the updated configuration parameters and / or the updated mapping relationship.
[0215] Specifically, S300: After broadcasting the update information to any Redis node so that the configuration center can receive the update information, it also includes:
[0216] S310: The configuration center parses the update information to obtain the updated configuration parameters and the updated mapping relationships.
[0217] Specifically, S400: The configuration center updates the settings of the corresponding Redis nodes based on the updated information, including:
[0218] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective;
[0219] S420: Replaces the original mapping in Redis with the updated mapping, making the Redis mapping effective.
[0220] Specifically, the configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time;
[0221] S410: Initializes Redis configuration parameters with the updated configuration parameters, making the Redis configuration parameters effective, including:
[0222] S411: Update the URL address of the Redis node;
[0223] S412: Update the maximum and minimum number of connections for a Redis node;
[0224] S413: Initialize the Redis node configuration with the updated URL address, updated maximum number of connections, and minimum number of connections, and make the configuration parameters of the Redis node effective.
[0225] Specifically, S400: The configuration center performs Redis settings based on the updated configuration parameters and the updated mapping relationships, and also includes:
[0226] S451: Update the user corresponding to the Redis node in the connection pool corresponding to the Redis node, so as to update the user-Redis mapping relationship;
[0227] S452: Based on the updated user-Redis mapping, route new users to this Redis node.
[0228] By implementing the Redis dynamic configuration method, apparatus, device, and storage medium disclosed in the embodiments of this application, it is possible to use the configuration center to monitor and automatically update the Redis node configuration; dynamically adjust the mapping relationship between tenants and Redis nodes, support resource adjustment and flexible expansion between tenants, and dynamically adjust Redis configuration parameters without restarting the server, so that the configuration takes effect.
[0229] All of the above-mentioned optional technical solutions can be combined in any way to form the optional embodiments of this application, and will not be described in detail here.
[0230] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program loaded on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from memory, or installed from ROM. When the computer program is executed by an external processor, it performs the functions defined in the methods of embodiments of this application.
[0231] It should be noted that the computer-readable medium in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the embodiments of this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the embodiments of this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (Radio Frequency), etc., or any suitable combination thereof.
[0232] The aforementioned computer-readable medium may be included in the aforementioned server; or it may exist independently and not assembled into the server. The aforementioned computer-readable medium carries one or more programs that, when executed by the server, cause the server to: in response to detecting that the peripheral mode of the terminal is not activated, acquire the frame rate of the application on the terminal; when the frame rate meets the screen-off condition, determine whether the user is acquiring the terminal's screen information; and in response to the determination that the user is not acquiring the terminal's screen information, control the screen to enter an immediate dimming mode.
[0233] Computer program code for performing the operations of the embodiments of this application can be written in one or more programming languages or a combination thereof. Programming languages include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0234] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0235] The technical solutions provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. Furthermore, those skilled in the art will recognize that, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this application.
[0236] The above description is only a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A Redis dynamic configuration method, characterized in that, include: Associate Nacos with the service items of the Redis node; Configure the Nacos connection information and listening rules in the Redis node's configuration file; Connect Nacos to the Redis node to obtain the Redis configuration file template, so that Nacos can collect and update the configuration parameters and mapping relationships according to the configuration file template. Start Nacos listener on the Redis node; Monitor updates to configuration parameters of any Redis node in Nacos and updates to the mapping relationship between users and Redis nodes. The configuration parameters are used to adjust the performance of Redis, and the mapping relationship is used to configure the correspondence between users and Redis nodes. Based on the updates to the configuration parameters and the mapping relationships, determine the update information corresponding to the Redis node; The update information is broadcast to any Redis node so that the configuration center can receive the update information; The configuration center updates the settings of the corresponding Redis nodes based on the update information; The monitoring of updates to configuration parameters of any Redis node and updates to the user-Redis mapping relationship in Nacos includes: A callback function is triggered when the configuration parameters and / or the mapping relationship are updated; The updated configuration parameters and / or updated mapping relationships are parsed through the callback function; Extract the Redis nodes corresponding to the updated configuration parameters and / or updated mapping relationships, obtain Nacos configuration change events by listening, and update the connection pool parameters of each Redis node independently. The configuration center updates the settings of the corresponding Redis nodes based on the update information, including: Initialize the Redis configuration parameters with the updated configuration parameters to make the Redis configuration parameters take effect; Replace the original mapping in Redis with the updated mapping to make the Redis mapping take effect; The configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time; Initialize Redis configuration parameters with the updated configuration parameters to make the Redis configuration parameters take effect, including: Update the URL of the Redis node; Update the maximum and minimum number of connections for the Redis node; The Redis node configuration is initialized with the updated URL address, updated maximum number of connections, and minimum number of connections to make the configuration parameters of the Redis node effective.
2. The Redis dynamic configuration method according to claim 1, characterized in that, After broadcasting the update information to any Redis node so that the configuration center can receive the update information, the method further includes: The configuration center parses the update information to obtain the updated configuration parameters and the updated mapping relationship.
3. The Redis dynamic configuration method according to claim 1, characterized in that, The configuration center configures Redis based on the updated configuration parameters and the updated mapping relationships, and also includes: Update the user corresponding to the Redis node in the connection pool corresponding to the Redis node, so as to update the user-Redis mapping relationship; Based on the updated user-Redis mapping, new users are routed to this Redis node.
4. A Redis dynamic configuration device, characterized in that, The device includes: The listening module is used to associate Nacos with the service items of Redis nodes; to set the connection information and listening rules of Nacos in the configuration file of the Redis node; to connect Nacos to the Redis node and obtain the Redis configuration file template so that Nacos can collect updated configuration parameters and updated mapping relationships according to the configuration file template; to start Nacos listening on the Redis node; and to listen for updates to the configuration parameters of any Redis node and updates to the user-Redis mapping relationship in Nacos. The configuration parameters are used to adjust the working performance of Redis, and the mapping relationship is used to configure the correspondence between users and Redis. The monitoring of updates to configuration parameters of any Redis node and updates to the user-Redis mapping relationship in Nacos includes: A callback function is triggered when the configuration parameters and / or the mapping relationship are updated; The updated configuration parameters and / or updated mapping relationships are parsed through the callback function; Extract the Redis nodes corresponding to the updated configuration parameters and / or updated mapping relationships, obtain Nacos configuration change events by listening, and update the connection pool parameters of each Redis node independently. The information generation module is used to determine the update information corresponding to the Redis node based on the update of the configuration parameters and the update of the mapping relationship; The broadcast module is used to broadcast the update information to any Redis node so that the configuration center can receive the update information; The update module is used to update the settings of the corresponding Redis nodes in the configuration center according to the update information; The configuration center updates the settings of the corresponding Redis nodes based on the update information, including: Initialize the Redis configuration parameters with the updated configuration parameters to make the Redis configuration parameters take effect; Replace the original mapping in Redis with the updated mapping to make the Redis mapping take effect; The configuration parameters include at least one of the following: URL address, maximum number of connections, minimum number of connections, and operation time; Initialize Redis configuration parameters with the updated configuration parameters to make the Redis configuration parameters take effect, including: Update the URL of the Redis node; Update the maximum and minimum number of connections for the Redis node; The Redis node configuration is initialized with the updated URL address, updated maximum number of connections, and minimum number of connections to make the configuration parameters of the Redis node effective.
5. A computer 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, it implements the Redis dynamic configuration method as described in any one of claims 1 to 3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the Redis dynamic configuration method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Redis cluster information monitoring device and method
CN106453512A