Redis proxy service implementation method, system, electronic device and computer storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN LANYOU TECHNOLOGY CO LTD
- Filing Date
- 2022-05-23
- Publication Date
- 2026-06-19
Smart Images

Figure CN117155999B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of proxy service technology, and more specifically, to a method, system, electronic device, and computer storage medium for implementing Redis proxy services. Background Technology
[0002] For better performance, applications typically use Redis as a cache to avoid the performance overhead of direct I / O operations. Redis is an open-source, network-enabled, in-memory key-value database. Traditionally, applications are deployed across separate servers, with each project independently deploying a Redis cluster to serve its individual application. However, with the maturation of cloud-native architectures driving application services to the cloud, the traditional approach of using Redis has revealed drawbacks such as redundant deployment, fragmented management, and resource waste due to the inability to share resources.
[0003] In practical applications, in cloud-native environments, centralized management of application services requires a transparent, multi-tenant proxy service that can globally manage and allocate Redis, enabling cloud-native applications to use Redis as a cache more easily and with less resource consumption. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a specific design and implementation method for a transparent Redis proxy service, in order to solve the problem that traditional applications in cloud-native environments, SaaS services, etc., can better access and manage Redis service resources without making any architectural changes.
[0005] A first aspect of the present invention provides a method for implementing a Redis proxy service, the method comprising:
[0006] S1 connects to the Redis proxy server using a long TCP connection and checks whether the network connection between the application server and the Redis proxy server is successful by sending a ping request.
[0007] S2 sends an authentication request message to the Redis proxy server and creates the first request object. If authentication is successful, it returns an authentication success message to the application server.
[0008] S3, create a second request object, the second request object executes the pass-through processing strategy, the second request object includes task execution content;
[0009] Based on the second request object, a task execution request is sent to the Redis proxy server so that the Redis proxy server can execute the task content;
[0010] S4, the task is completed, and the Redis proxy server calls the decoder to construct a status response object and return it to the application server.
[0011] Furthermore, S2 also includes:
[0012] When sending an authentication request message to the Redis proxy server, a first request object is created through the encoder; the first request object executes the local processing strategy.
[0013] If authentication is successful, the authentication process is performed based on the first request object. The authentication process includes obtaining the Redis instance resources of the tenant corresponding to the authenticated user.
[0014] Furthermore, the second request object executes a pass-through processing strategy, including:
[0015] Select a tenant based on context, then select the Redis instance configured for that tenant, select either a master Redis instance or a slave Redis instance based on the load balancing algorithm, and then perform the task content allocation and execution.
[0016] After receiving the Redis response data packet, the client's I / O worker thread calls the decoder to construct a status response object based on the packet type and length. Then, it forwards the response to the business thread to encapsulate a callback task (callbackTask), calls the callback function to process the returned data, and finally calls Netty's ChannelHandlerContext's writeAndFlush to push the response to the application's Redis client.
[0017] Furthermore, the encoder performs encoding operations based on the RESP protocol; the creation of a first request object through the encoder includes:
[0018] Create a Request object; skip requests that do not conform to the RESP request format and skip empty bytes;
[0019] Determine the number of message commands and save it to a property of the Request object.
[0020] Furthermore, the decoder performs decoding operations based on the RESP protocol; the step of calling the decoder, constructing a status response object according to the message type and length, includes:
[0021] By reading the first byte of the message, different response object information is created based on the characters in the first byte;
[0022] Based on the preset response content mapping relationship, select the appropriate response to process; after the encoding and parsing are completed, create a response object RedisResponesCommand, and then add it to the output queue out. Push it onto the Netty task queue and send it to the application server.
[0023] Furthermore, a second aspect of the present invention provides a Redis proxy service implementation system, the method comprising:
[0024] The connection module connects to the Redis proxy server using a long TCP connection and checks whether the network connection between the application server and the Redis proxy server is successful by sending a ping request.
[0025] The authentication module sends an authentication request message to the Redis proxy server and creates the first request object. If the authentication is successful, it returns an authentication success message to the application server.
[0026] The execution module creates a second request object, which executes a pass-through processing strategy. The second request object includes task execution content. Based on the second request object, it sends a task execution request to the Redis proxy server so that the Redis proxy server executes the task content.
[0027] Upon returning to the module, the task execution is complete, and the Redis proxy server calls the decoder to construct a status response object and return it to the application server.
[0028] Furthermore, the authentication module is also used to create a first request object through the encoder when sending an authentication request message to the Redis proxy server; the first request object executes a local processing strategy.
[0029] If authentication is successful, the authentication process is performed based on the first request object. The authentication process includes obtaining the Redis instance resources of the tenant corresponding to the authenticated user.
[0030] Furthermore, the second request object executes a pass-through processing strategy, including selecting a tenant through context, then selecting the Redis instance configured by the tenant, selecting a master Redis instance or a slave Redis instance according to a load balancing algorithm, and performing the task content allocation and execution.
[0031] After receiving the Redis response data packet, the client's I / O worker thread calls the decoder to construct a status response object based on the packet type and length. Then, it forwards the response to the business thread to encapsulate a callback task (callbackTask), calls the callback function to process the returned data, and finally calls Netty's ChannelHandlerContext's writeAndFlush to push the response to the application's Redis client.
[0032] Furthermore, a third aspect of the present invention provides an electronic device comprising: one or more processors, and a memory for storing one or more computer programs; characterized in that the computer programs are configured to be executed by the one or more processors, and the programs include steps for performing the Redis proxy service implementation method as described above.
[0033] Furthermore, a fourth aspect of the present invention provides a computer storage medium storing a program; the program is loaded and executed by a processor to implement the Redis proxy service implementation method steps as described above.
[0034] In this invention, a TCP long connection is used to connect to the Redis proxy server, and a ping request is sent to check if the network connection between the application server and the Redis proxy server is successful. An authentication request message is sent to the Redis proxy server, and a first request object is created. If authentication is successful, an authentication success message is returned to the application server. A second request object is created, which executes a transparent processing strategy and includes task execution content. Based on the second request object, a task execution request is sent to the Redis proxy server, causing the Redis proxy server to execute the task content. After task execution is complete, the Redis proxy server calls a decoder to construct a status response object and returns it to the application server. By requesting commands to be executed by the Redis proxy service and encoding and decoding based on the Redis communication protocol, a transparent Redis proxy service is achieved. This allows for better access and management of Redis service resources without requiring any changes to the server architecture. Attached Figure Description
[0035] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 This is a flowchart illustrating the Redis proxy service implementation method disclosed in an embodiment of the present invention;
[0037] Figure 2 This is a flowchart illustrating the overall architecture design and execution process of the Redis proxy service implementation disclosed in this embodiment of the invention.
[0038] Figure 3 This is a diagram of the encoder executing RESP encoding sequence disclosed in an embodiment of the present invention;
[0039] Figure 4 This is a flowchart of the execution logic for the new RESP protocol disclosed in an embodiment of the present invention;
[0040] Figure 5 This is a flowchart of the execution logic for a compatible RESP protocol disclosed in an embodiment of the present invention;
[0041] Figure 6 This is a decoder execution ESP decoding sequence diagram disclosed in an embodiment of the present invention;
[0042] Figure 7 This is a schematic diagram of the Redis proxy service implementation system structure disclosed in an embodiment of the present invention. Detailed Implementation
[0043] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.
[0044] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a thorough understanding of embodiments of this application. However, those skilled in the art will recognize that the technical solutions of this application can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this application.
[0045] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0046] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0047] It should be noted that "multiple" as mentioned in this article refers to two or more.
[0048] The implementation details of the technical solutions in the embodiments of this application are described in detail below:
[0049] Please see Figure 1 , Figure 1 This is a flowchart illustrating a Redis proxy service implementation method disclosed in an embodiment of the present invention. Figure 1 As shown in the figure, an embodiment of the present invention provides a Redis proxy service implementation method, applied to an application server. The method includes:
[0050] S1 connects to the Redis proxy server using a long TCP connection and checks whether the network connection between the application server and the Redis proxy server is successful by sending a ping request.
[0051] In this embodiment, when the application server connects to the Redis proxy service via a TCP long connection, it sends a ping request to check whether the network data transmission between the application server and the Redis proxy service is valid. The Redis proxy service receives the ping message, uses a request encoder to construct a request object with a local processing strategy, and constructs a reply object with the content PONG to return to the application server, completing one request.
[0052] S2 sends an authentication request message to the Redis proxy server and creates the first request object. If authentication is successful, it returns an authentication success message to the application server.
[0053] Furthermore, S2 also includes: when sending an authentication request message to the Redis proxy server, creating a first request object through an encoder; the first request object executing a local processing strategy; if authentication is successful, processing authentication business based on the first request object, the authentication business including obtaining the Redis instance resources of the tenant corresponding to the authenticated user.
[0054] Specifically, in this embodiment, after the application server completes the connection, it sends an authentication request `auth[password]`. When the Redis proxy server receives the message, it also uses the encoder to create an authentication request object with a local processing strategy. If authentication is successful, it processes authentication-related business, including obtaining the Redis instance resources of the tenant corresponding to the authenticated user, and then storing them in the global context for use throughout the connection request process. A status reply object with the content "+OK" is constructed and returned to the application server. If authentication fails, an error reply object with the content "-NOAUTHAuthentication required" is constructed and returned to the application server.
[0055] S3, create a second request object, the second request object executes the pass-through processing strategy, the second request object includes task execution content;
[0056] Based on the second request object, a task execution request is sent to the Redis proxy server so that the Redis proxy server can execute the task content;
[0057] Specifically, in this embodiment, once authentication is complete, the task can be executed. For example, taking a task involving storing data, the request processing process is as follows: Taking an application service issuing a `set key value` request as an example, the Redis proxy service receives the message and similarly uses the encoder to create a `request` object with a transparent processing strategy. It then sends the message content to Redis for execution via a long TCP connection. After Redis completes the execution, it returns the message content + `OK` to the Redis proxy service, calls the decoder to construct a `Reply` object, and returns it to the application server. This completes the storage operation.
[0058] If the application server sends a data retrieval process, similarly, let's take the `get key` command as an example. The Redis proxy service receives the message and similarly uses the encoder to create a `request` object with a pass-through processing strategy. It then sends the message content to Redis for execution via a long TCP connection. After Redis completes the execution, it returns a message containing data. Taking the data stored in step 3 as an example, the returned message content would be `$5\r\nvalue\r\n`. The Redis proxy service receives this message, calls the decoder to construct a multi-line `Reply` object, and returns it to the application server. This completes the storage operation.
[0059] S4, the task is completed, and the Redis proxy server calls the decoder to construct a status response object and return it to the application server.
[0060] It should be noted that in this embodiment, the local processing strategy, such as communication Connection commands like ping and auth, does not actually require communication with Redis. The proxy service only needs to perform corresponding processing based on the command characteristics, then construct a Redis response object (Reply) and convert it into a response message. For example, ping -> +OK; for the auth authentication command, tenant information can also be obtained based on the account and bound to the business processing in the channel's global context to determine if the current application can obtain the Redis configuration information corresponding to the tenant.
[0061] Furthermore, the second request object executes a pass-through processing strategy, including:
[0062] Select a tenant based on context, then select the Redis instance configured for that tenant, select either a master Redis instance or a slave Redis instance based on the load balancing algorithm, and then perform the task content allocation and execution.
[0063] After receiving the Redis response data packet, the client's I / O worker thread calls the decoder to construct a status response object based on the packet type and length. Then, it forwards the response to the business thread to encapsulate a callback task (callbackTask), calls the callback function to process the returned data, and finally calls Netty's ChannelHandlerContext's writeAndFlush to push the response to the application's Redis client.
[0064] Specifically, in this embodiment, the pass-through processing strategy is as follows: commands for data operations such as `set key value` and `get key` are passed through to Redis for execution. After selecting the tenant through the context, the Redis instance configured for the tenant is selected. The load balancing algorithm selects either the master or slave Redis instance, and then the command is sent to the Redis instance for execution. Upon receiving the Redis response data packet, the client's I / O worker thread calls the decoding program to construct a `Reply` object based on the packet type and length. This object is then forwarded to the business thread to encapsulate a callback task (`callbackTask`). The callback function is called to process the returned data, and finally, `Netty's ChannelHandlerContext.writeAndFlush` is called to push the response to the application's Redis client.
[0065] Another important function of the Redis proxy service is to provide a specific design and implementation for encoding and decoding of Redis protocol communication (RESP, Redis Serialization Protocol).
[0066] Furthermore, the encoder performs encoding operations based on the RESP protocol; the creation of a first request object through the encoder includes: creating a Request object; skipping requests that do not conform to the RESP request format and skipping null bytes; determining the value of the number of message commands and saving it to the attribute of the Request object.
[0067] like Figure 2 The diagram shows the overall architecture and execution flowchart of the Redis proxy service implementation in this embodiment. It provides a method for sending messages to the Redis proxy server. The Redis proxy server receives messages through the I / O worker interface, parses the Redis protocol messages, converts them into Request objects, forwards the request to the server-executor thread pool, determines whether it should be processed locally, and if so, processes the login command, obtains the tenant's bound Channel global attributes, completes the business processing, and constructs the Redis response protocol. Further, if it is not processed locally, it obtains the tenant attributes from the Channel, selects the Redis instance group configuration, uses a hash-consistent algorithm to select the primary Redis instance, and determines whether the Request is named "Redis". If so, it assigns the task to the tenant Redis instance based on the I / O worker interface; otherwise, it uses a random algorithm to select a secondary Redis instance and assigns the task to the tenant Redis instance based on the I / O worker interface. After the task is processed, it returns to the Redis proxy server, parses the Redis response, constructs a Reply object, forwards the response, and executes subsequent reply processing on the application server based on the callback thread.
[0068] Specifically, in this embodiment, as Figure 3 The diagram shows the RESP encoding sequence executed by the encoder in this embodiment. Step 1: decode is the entry method for encoding, creating a Request object; Step 1.1: skipChar is for error handling, skipping requests that do not conform to the RESP request format and skipping null bytes; Step 1.2: readInt reads an integer, representing the number of message commands, and saves it to the Request object's property; Step 1.3: getInstance retrieves the request command content processing instance IRedisRequestDecoder. Because it supports both the new and old RESP protocols, it can support two concrete implementation classes for both protocols.
[0069] Furthermore, `readArg` is the specific method for processing the encoded content, and the processing logic is as follows:
[0070] (1) As Figure 4The diagram shown is the execution logic flowchart for the new RESP protocol in this embodiment. The new RESP protocol obtains the number of commands through 1.2, and takes the integer after the first byte '$' as the length value of the content to be read. Based on this length value, the content is read; and the processing strategy is obtained based on the first command.
[0071] Call 1: the `readArg(ByteBuf in, RedisCommand request)` function. The parameter `in` is the unread message buffer, and the parameter `request` has a `count` attribute, which is the number of commands read in step 1.2: `readInt`. Loop `count` times to get the first byte, check if it's a '$' value, then proceed to the next step; otherwise, throw an exception and end the process.
[0072] Calling `1:1readInt` reads a string of numbers to obtain the length of the command. Then, a byte array of the same length is created based on this length value. Finally, the command content is read from the `in` parameter (`1.1`) and cached in the byte array.
[0073] Calling `1:2getPolicy`, `getPolicy` retrieves the first segment of command bytes after the loop finishes reading the command and data content of the `count` segment, using it as the corresponding processing policy object; `1:2:1<` <create>> indicates that when retrieving the processing strategy, if the parameter is empty, a default processing strategy is created; otherwise, a 1:2:2 strategy is used. <create>> Retrieve the corresponding strategy object based on the input parameters;
[0074] After processing is complete, the cached byte array is added to the command property of the Request object, and the strategy is added to the strategy property of the Request object.
[0075] (2) Figure 5 The diagram shows the execution logic flowchart for RESP-compatible protocols. It obtains the content length value by looping through the message end-of-line character, either a space or a newline character ( / r / n). Then it reads the content.
[0076] Call 1: readArg(ByteBuf in, RedisCommand request) function, where the parameter in is the message buffer that has not yet been read, and the parameter request is the request command object.
[0077] Because when dealing with messages like `auth\r\n`, there's no numerical value to read the message length. To ensure compatibility with interpreting protocol messages, the length of the first segment is read in a loop, either with a space or a newline (`\r\n`), before the command content is read. Similarly: 1. The first segment of command bytes is used as the object to obtain the corresponding processing strategy; 1:1< <create>> indicates that when obtaining the processing strategy, if the parameter is empty, a default processing strategy is created; otherwise, a 1:2 strategy is used. <create>> Retrieve the corresponding strategy object based on the input parameters.
[0078] The `readInt` function (1:3) reads alphanumeric characters, starting from the index already read and ending at the value read by `readInt`, thus obtaining the second segment of the command content. This process is repeated to read the remaining command content until it becomes unreadable.
[0079] After processing is complete, the cached byte array is added to the command property of the Request object, and the strategy is added to the strategy property of the Request object.
[0080] Furthermore, the decoder performs decoding operations based on the RESP protocol; the step of calling the decoder, constructing a status response object according to the message type and length, includes:
[0081] By reading the first byte of the message, different response object information is created based on the characters in the first byte;
[0082] Based on the preset response content mapping relationship, select the appropriate response to process; after the encoding and parsing are completed, create a response object RedisResponesCommand, and then add it to the output queue out. Push it onto the Netty task queue and send it to the application server.
[0083] Specifically, in this embodiment, as Figure 6 The diagram shown is a sequence diagram of the decoder performing ESP decoding in this embodiment.
[0084] Step 1: `decode` is the entry point for decoding; it sets the state to the initial state.
[0085] Step 1: 1: buildReply reads the first byte and creates different mappings based on different characters as follows:
[0086] * Create multiple batch reply objects;
[0087] Create a batch reply object;
[0088] Create an integer response object;
[0089] + Create a status response object;
[0090] - Create an error response object;
[0091] Step 1.2: After step 1.1 is completed, set the state to the reply state.
[0092] Step 1.3: The handler is a different instance that specifically processes the reply content.
[0093] Reply with an integer, read content, and continue reading until the last character is \r\n.
[0094] Status update, read content, continue reading until the read character is \r\n
[0095] Error response, read content until the character read is \r\n.
[0096] Batch reply: The process ends by reading the length of the integer following the dollar sign ($), and then reading the content within that length value.
[0097] Multiple batch replies: Read the last integer reply value, loop through the reply values, analyze the specific processing situation of replies 1 to 4, and then select the specific implementation to execute the processing.
[0098] Step 1.4: After step 1.3 is completed, the state is set to the initial state.
[0099] Step 1.5: <create>Once the encoding and parsing are complete, a response object `RedisResponesCommand` is created and added to the output queue `out`. This is then pushed onto the Netty task queue and sent to the application server.
[0100] In addition, such as Figure 7 As shown in the embodiments of this application, a Redis proxy service implementation system is also disclosed, the method including:
[0101] Connection module 10 connects to the Redis proxy server via a long TCP connection and checks whether the network connection between the application server and the Redis proxy server is successful by sending a ping request.
[0102] The authentication module 20 sends an authentication request message to the Redis proxy server and creates a first request object. If the authentication is successful, it returns an authentication success message to the application server.
[0103] Execution module 30 creates a second request object, which executes a pass-through processing strategy. The second request object includes task execution content. Based on the second request object, a task execution request is sent to the Redis proxy server so that the Redis proxy server executes the task content.
[0104] Returning to module 40, the task execution is complete. The Redis proxy server calls the decoder to construct a status response object and returns it to the application server.
[0105] Furthermore, the authentication module is also used to create a first request object through the encoder when sending an authentication request message to the Redis proxy server; the first request object executes a local processing strategy.
[0106] If authentication is successful, the authentication process is performed based on the first request object. The authentication process includes obtaining the Redis instance resources of the tenant corresponding to the authenticated user.
[0107] Furthermore, the second request object executes a pass-through processing strategy, including selecting a tenant through context, then selecting the Redis instance configured by the tenant, selecting a master Redis instance or a slave Redis instance according to a load balancing algorithm, and performing the task content allocation and execution.
[0108] After receiving the Redis response data packet, the client's I / O worker thread calls the decoder to construct a status response object based on the packet type and length. Then, it forwards the response to the business thread to encapsulate a callback task (callbackTask), calls the callback function to process the returned data, and finally calls Netty's ChannelHandlerContext's writeAndFlush to push the response to the application's Redis client.
[0109] Furthermore, embodiments of this application also disclose an electronic device comprising: one or more processors, and a memory for storing one or more computer programs; characterized in that the computer programs are configured to be executed by the one or more processors, and the programs include steps for performing the Redis proxy service implementation method as described above.
[0110] Furthermore, this application embodiment also provides a computer storage medium storing a program; the program is loaded and executed by a processor to implement the Redis proxy service implementation method steps as described above.
[0111] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0112] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices or units, or may be electrical, mechanical or other forms of connection.
[0113] The units described as separate components may or may not be physically separate. As will be appreciated by those skilled in the art, the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0114] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0115] If the integrated unit is implemented as 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 technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or grid device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0116] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.< / create> < / create> < / create> < / create> < / create>
Claims
1. A Redis proxy service implementation method, characterized in that, The method includes: S1 connects to the Redis proxy server using a long TCP connection and checks whether the network connection between the application server and the Redis proxy server is successful by sending a ping request. S2 sends an authentication request message to the Redis proxy server and creates the first request object. If authentication is successful, it returns an authentication success message to the application server. S3, create a second request object, the second request object executes the pass-through processing strategy, the second request object includes task execution content; based on the second request object, send a task execution request to the Redis proxy server so that the Redis proxy server executes the task content; S4, the task is completed, and the Redis proxy server calls the decoder to construct a status response object and return it to the application server; S2 further includes: When sending an authentication request message to the Redis proxy server, a first request object is created through the encoder; the first request object executes the local processing strategy. If authentication is successful, the authentication process is performed based on the first request object. The authentication process includes obtaining the Redis instance resources of the tenant corresponding to the authenticated user. The second request object executes a pass-through processing strategy, including: Select a tenant based on context, then select the Redis instance configured for that tenant, select either a master Redis instance or a slave Redis instance based on the load balancing algorithm, and then perform the task content allocation and execution. After receiving the Redis response data packet, the client's I / O worker thread calls the decoder to construct a status response object based on the packet type and length. Then, it forwards the response to the business thread to encapsulate a callback task (callbackTask), calls the callback function to process the returned data, and finally calls Netty's ChannelHandlerContext's writeAndFlush to push the response to the application's Redis client.
2. The Redis proxy service implementation method according to claim 1, characterized in that, The encoder performs encoding operations based on the RESP protocol; the encoder creates a first request object, including: Create a Request object; skip requests that do not conform to the RESP request format and skip empty bytes; Determine the number of message commands and save it to a property of the Request object.
3. The Redis proxy service implementation method of claim 1, wherein, The decoder performs decoding operations based on the RESP protocol; The call to the decoder constructs a status response object based on the message type and length, including: By reading the first byte of the message, different response object information is created based on the characters in the first byte; Based on the preset response content mapping relationship, select the appropriate response to process; after the encoding and parsing are completed, create a response object RedisResponesCommand, and then add it to the output queue out. Push it onto the Netty task queue and send it to the application server.
4. A Redis proxy service implementation system for performing the method of any one of claims 1 to 3, characterized by The system includes: The connection module connects to the Redis proxy server using a long TCP connection and checks whether the network connection between the application server and the Redis proxy server is successful by sending a ping request. The authentication module sends an authentication request message to the Redis proxy server and creates the first request object. If the authentication is successful, it returns an authentication success message to the application server. The execution module creates a second request object, which executes a pass-through processing strategy. The second request object includes task execution content. Based on the second request object, it sends a task execution request to the Redis proxy server so that the Redis proxy server executes the task content. Upon returning to the module, the task execution is complete, and the Redis proxy server calls the decoder to construct a status response object and return it to the application server. The authentication module is also used to create a first request object through the encoder when sending an authentication request message to the Redis proxy server; the first request object executes a local processing strategy. If authentication is successful, the authentication process is performed based on the first request object. The authentication process includes obtaining the Redis instance resources of the tenant corresponding to the authenticated user. The second request object executes a pass-through processing strategy, including selecting a tenant through context, then selecting the Redis instance configured for the tenant, selecting a master Redis instance or a slave Redis instance according to a load balancing algorithm, and performing the task content allocation and execution. After receiving the Redis response data packet, the client's I / O worker thread calls the decoder to construct a status response object based on the packet type and length. Then, it forwards the response to the business thread to encapsulate a callback task (callbackTask), calls the callback function to process the returned data, and finally calls Netty's ChannelHandlerContext's writeAndFlush to push the response to the application's Redis client.
5. An electronic device comprising: One or more processors, a memory for storing one or more computer programs; characterized in that the computer programs are configured to be executed by the one or more processors, the programs including steps for performing the Redis proxy service implementation method as described in any one of claims 1-3.
6. A computer storage medium storing a program; the program is loaded and executed by a processor to implement the steps of the Redis proxy service implementation method as described in any one of claims 1-3.