CN110611687A - Remote procedure call implementation method based on Redis and related device - Google Patents

Remote procedure call implementation method based on Redis and related device Download PDF

Info

Publication number
CN110611687A
CN110611687A CN201810618188.4A CN201810618188A CN110611687A CN 110611687 A CN110611687 A CN 110611687A CN 201810618188 A CN201810618188 A CN 201810618188A CN 110611687 A CN110611687 A CN 110611687A
Authority
CN
China
Prior art keywords
call
synchronous
asynchronous
request
redis
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810618188.4A
Other languages
Chinese (zh)
Inventor
刘穿时
马志远
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Antian Information Technology Co Ltd
Original Assignee
Wuhan Antian Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Antian Information Technology Co Ltd filed Critical Wuhan Antian Information Technology Co Ltd
Priority to CN201810618188.4A priority Critical patent/CN110611687A/en
Publication of CN110611687A publication Critical patent/CN110611687A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Telephonic Communication Services (AREA)

Abstract

The embodiment of the invention discloses a remote procedure call implementation method and device for Redis, computer equipment and a computer storage medium, and relates to the technical field of networks. The remote procedure call implementation method thoroughly decouples the RPC client and the RPC server, interacts through the Redis server, shields the communication details of the network bottom layer for a service caller, and has strong applicability. The RPC client side initiates the call request without depending on the RPC server, so addressing is not required to be processed, and the RPC call process is simplified. In addition, problems such as transmission layer receiving and sending packets, TCP sticky packets and the like are all processed by the Redis server, and compared with the existing method that the problems are processed by a code writer, the efficiency of processing the service logic is greatly improved. In addition, for a large number of call requests, the RPC server processes the call requests through the Redis server, and the burden of the RPC server is greatly reduced.

Description

Remote procedure call implementation method based on Redis and related device
Technical Field
The present application relates to the field of network technologies, and in particular, to a remote procedure call implementation method and apparatus based on Redis, a computer device, and a computer storage medium.
Background
RPC (Remote Procedure Call), which is a Protocol for requesting a service from a Remote computer program through a network without knowing underlying network technology, makes it easier to develop an application including a network distributed multi-program. The RPC client requests services (functions or methods are generally called as services)) on the RPC server through the network under the RPC architecture, Socket communication or Http communication does not need to be directly processed, underlying network protocol details can be hidden for a caller, and remote services can be called conveniently as local services in the use form.
The existing remote procedure call implementation method is that an RPC client calls a process to send a call request with process parameters to an RPC server, and then waits for response information; the process of the RPC server keeps a sleep state until a call request sent by the RPC client is received, when the call request arrives, the RPC server obtains process parameters, calculates a result, returns a reply response to the RPC client, and then waits for the next call request; and the RPC client calls the process to receive the reply response returned by the RPC server, obtains the process result, then continuously sends a call request to the RPC server, and the call execution is continuously carried out.
The remote procedure call implementation method has the following defects:
when the remote procedure call is realized, a direct communication link needs to be established between the RPC client and the RPC Server, so that on one hand, the RPC client initiates a call request depending on the Server Server, and if the RPC Server is not started or crashed, the normal use of the RPC client is influenced; on the other hand, the direct communication between the RPC client and the RPC server causes complex problems that a code writer is needed to process transmission layer receiving and sending packets, TCP sticky packets, connection recovery after network timeout and the like for realizing communication, and on the one hand, the code writer is required to have strong control capability on a network and a protocol stack, and on the other hand, various processing operations of the code writer reduce the efficiency of processing service logic; moreover, for a large number of call requests, the RPC server is overloaded and is very easy to crash in direct processing. In addition, the conventional method needs to develop an RPC client and a server of the TCP separately, is complex in development, consumes a great deal of energy of developers on one hand, and has high requirements on service callers on the other hand, so that the applicability of the RPC is limited. Moreover, the traditional server is inconvenient to expand, when the performance of a single machine reaches a bottleneck, a plurality of RPC servers with a distributed architecture are required to realize RPC calling, however, in this situation, when an RPC client sends a calling request to an RPC server, a free RPC server needs to be confirmed firstly, and then the calling request is sent to the free RPC server, and the RPC client is inconvenient to address due to the calling method, so that the RPC calling process becomes complicated.
Disclosure of Invention
The embodiment of the invention provides a remote procedure call implementation method and device based on Redis, computer equipment and a computer storage medium, which are used for solving the technical problems in the prior art.
In a first aspect, an embodiment of the present invention provides a remote procedure call implementation method based on Redis, which is applicable to an RPC client.
Specifically, the method comprises the following steps:
establishing connection with a Redis server;
receiving a calling instruction sent by an application layer;
when the calling instruction is a synchronous calling instruction, generating a synchronous calling request, and storing the synchronous calling request to the Redis server; then, the process enters blocking until a synchronous calling response corresponding to the synchronous calling request exists in the Redis server, and the synchronous calling response is sent to an application layer;
when the calling instruction is an asynchronous calling instruction, generating an asynchronous calling request, and storing the asynchronous calling request to the Redis server; and then returning a calling result inquiry credential message to the application layer and executing a next calling instruction, or acquiring an asynchronous calling response stored in the Redis server according to the previous calling result inquiry credential message.
In a second aspect, an embodiment of the present invention provides a remote procedure call implementation method based on Redis, which is applicable to an RPC server.
Specifically, the method comprises the following steps:
establishing connection with a Redis server;
acquiring a call request stored in the Redis server;
when the calling request is a synchronous calling request, generating a synchronous calling response, wherein the synchronous calling response comprises legal condition information and calling execution condition information of the synchronous calling request, and storing the synchronous calling response to the Redis server; then the process enters blocking until the synchronous call response stored in the Redis server is acquired by the RPC server;
and when the calling request is a synchronous calling request, generating an asynchronous calling response, wherein the asynchronous calling response comprises legal condition information and calling execution condition information of the asynchronous calling request, storing the asynchronous calling response to the Redis server, and then executing the next calling request.
In a third aspect, an embodiment of the present invention provides a remote procedure call implementation apparatus based on Redis, which is located on an RPC client side.
Specifically, the apparatus comprises:
the first connection establishing module is used for establishing connection with a Redis server;
the calling instruction receiving module is used for receiving a calling instruction sent by the application layer;
the synchronous call request generating and storing module is used for generating a synchronous call request when the call instruction is a synchronous call instruction, and storing the synchronous call request to the Redis server;
the first synchronous call post-processing module is used for blocking the RPC client process until the synchronous call response corresponding to the synchronous call request exists in the Redis server and acquiring the synchronous call response;
the asynchronous call request generating and storing module is used for generating an asynchronous call request when the call instruction is an asynchronous call instruction, and storing the asynchronous call request to the Redis server;
and the first asynchronous call post-processing module is used for returning a call result query credential message to the application layer according to the asynchronous call request, and executing a next call instruction, or acquiring an asynchronous call response stored in the Redis server according to a previous call result query credential message.
In a fourth aspect, an embodiment of the present invention provides a remote procedure call implementation apparatus based on Redis, which is located on an RPC server side.
Specifically, the apparatus comprises:
the second connection establishing module is used for establishing connection with the Redis server;
the calling request acquisition module is used for acquiring a calling request stored in the Redis server;
the synchronous call response generation and storage module is used for generating a synchronous call response when the call request is the synchronous call request, wherein the synchronous call response comprises legal condition information and call execution condition information of the synchronous call request, and the synchronous call response is stored to the Redis server;
the second synchronous call post-processing module is used for blocking the RPC server process until the synchronous call response stored in the Redis server is acquired by the RPC server;
the asynchronous call response generation and storage module is used for generating an asynchronous call response when the call request is a synchronous call request, wherein the asynchronous call response comprises legal condition information and call execution condition information of the asynchronous call request, and the asynchronous call response is stored to the Redis server;
and the second asynchronous call post-processing module is used for notifying the call request acquisition module to acquire a next call request after the asynchronous call response generation and storage module stores the asynchronous call response to the Redis server.
In a fifth aspect, an embodiment of the present invention provides a computer device.
In particular, the computer device comprises a processor and a memory for storing a computer program. Wherein the processor is configured to execute the computer program stored in the memory to implement the remote procedure call implementation method based on Redis according to the first aspect or the second aspect.
In a sixth aspect, embodiments of the present invention provide a computer storage medium.
In particular, the computer storage medium has stored therein a computer program which, when executed by a processor, implements the remote procedure call implementation method based on Redis according to the first or second aspect.
The remote procedure call implementation method and device based on Redis, the computer equipment and the computer storage medium thoroughly decouple the RPC client and the RPC server and interact with each other through the Redis server, so that the RPC client does not depend on the RPC server when initiating a synchronous call request or an asynchronous call request, and only needs to send the RPC call request to the Redis server without concerning the condition of the RPC server, such as the state and the number of the RPC servers, so that the RPC client does not need to process addressing, and the RPC call process is simplified. In addition, even if the RPC server is not started or crashed, the call request of the RPC client is not lost, and at the moment, the call request can be processed as long as the RPC server is recovered.
In addition, the RPC client and the RPC server realize communication through the Redis server, the problems of receiving and sending packets of a transmission layer, sticking packets of TCP and connection recovery after network overtime are solved by processing through the Redis server, and a code writer is not needed to participate, so that the efficiency of processing service logic is greatly improved. The RPC implementation method shields the communication details of the network bottom layer for the service caller in the actual service code, and has strong applicability.
In addition, for a large number of call requests, the RPC server is processed by the Redis server, so that the burden of the RPC server is reduced, the stability of the RPC server is facilitated, the expansion and the deployment of the RPC server are facilitated, and the service capacity of the RPC server can be horizontally expanded as long as the same RPC server code is run on a distributed machine.
It should be noted that Redis is used in the data storage field at the beginning of design, and the present invention innovatively applies Redis to the communication field, i.e., uses storage to implement communication, and specifically, uses the channel, hash, and list data structures of Redis, and the server and the client achieve the purpose of communication by continuously modifying these data structures, which is different from the traditional cache mechanism using Redis, and when caching, more servers store hot data, and the client reads the hot data. Meanwhile, because Redis is a memory type database, the communication efficiency is qualitatively improved compared with that of a relational database.
These and other aspects of the invention are apparent from and will be elucidated with reference to the embodiments described hereinafter.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly described below, and it is obvious that the drawings in the description below are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
FIG. 1 is a flowchart of a remote procedure call implementation method based on Redis in method embodiment 1 of the present invention;
FIG. 2 is a flowchart of a remote procedure call implementation method based on Redis in method embodiment 2 of the present invention;
FIG. 3 is a flowchart of a remote procedure call implementation method based on Redis in method embodiment 3 of the present invention;
FIG. 4 is a flowchart of a remote procedure call implementation method based on Redis in method embodiment 4 of the present invention;
FIG. 5 is a schematic diagram of a remote procedure call implementation apparatus based on Redis according to embodiment 1 of the present invention;
FIG. 6 is a schematic diagram of a remote procedure call implementation apparatus based on Redis in embodiment 2 of the present invention;
FIG. 7 is a schematic diagram of a remote procedure call implementation apparatus based on Redis according to embodiment 3 of the present invention;
fig. 8 is a schematic diagram of a remote procedure call implementation apparatus based on Redis in embodiment 4 of the apparatus in the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention.
In some of the flows described in the present specification and claims and in the above figures, a number of operations are included that occur in a particular order, but it should be clearly understood that these operations may be performed out of order or in parallel as they occur herein, with the reference numbers such as 102, 104, etc. merely being used to distinguish between the various operations, and the reference numbers themselves do not represent any order of performance. Additionally, the flows may include more or fewer operations, and the operations may be performed sequentially or in parallel. It should be noted that, the descriptions of "first", "second", etc. in this document are used for distinguishing different messages, devices, modules, etc., and do not represent a sequential order, nor limit the types of "first" and "second" to be different.
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without inventive effort based on the examples of the present invention, are within the scope of the present invention.
[ METHOD EXAMPLE 1 ]
Fig. 1 is a flowchart of a remote procedure call implementation method based on Redis according to embodiment 1 of the method of the present invention, and is suitable for an RPC client to indicate a synchronous call. Referring to fig. 1, in the present embodiment, the method includes:
step S11, establishing connection with a Redis server;
specifically, the Redis server is an efficient TCP server based on a Reactor model, and the RPC client establishes connection with the Redis server through a TCP protocol. In this embodiment, the synchronization call uses a publish-subscribe schema in the Redis server.
Step S13, receiving a calling instruction sent by an application layer;
step S15, when the calling instruction is synchronous calling instruction, generating synchronous calling request;
step S17, storing the synchronous calling request to a Redis server;
step S19, the process enters blocking until it is monitored that a synchronous call response corresponding to the synchronous call request exists in the Redis server, and at this time, the synchronous call response is sent to the application layer.
In this embodiment, the synchronous call request generated by the RPC client may be in a json structure format, and the specific structure is { "req _ id", "function", "args", "kwards", "type", "req _ time" }, where a req _ id field identifies the call request of this time; the function field indicates that the RPC client needs to call the function name of the RPC server; the args field indicates a position parameter corresponding to the function name; the kwarges field indicates the keyword parameter corresponding to the function name; the type field is an enumerated value, either sync (synchronous call) or async (asynchronous call); the req _ time field indicates the time of initiation of this call, in the form of a unix timestamp. In the present embodiment, the type field is sync.
Further, before step S17, the method further includes:
and performing deserialization processing on the synchronous call request.
Preferably, in this embodiment, the synchronization call request is stored in a data structure (Redis list) message queue of the Redis server, so that the RPC server can utilize a brpop API provided by the data structure message queue of the Redis server to implement enqueue and dequeue operations of the synchronization request message in the data structure message queue. At this point, the synchronous call request enters from the left side of the data structure message queue and dequeues from the right side of the data structure message queue.
Still further, after step S15, the method further includes:
and constructing a preset channel (channel) corresponding to the synchronous calling request in the Redis server, so that after the RPC server carries out calling judgment processing according to the synchronous calling request stored in the Redis server, the generated synchronous calling response is stored in the preset channel of the Redis server. Under the condition, the RPC client enters a subscriber mode, the subscribed preset channel is the only channel generated according to the synchronous call request, and therefore the preset channel can be guaranteed to be subscribed only by the subscriber.
According to the technical scheme, the RPC client and the RPC server are thoroughly decoupled and interacted through the Redis server, so that the RPC client does not depend on the RPC server when initiating the synchronous call request or the asynchronous call request, only the RPC call request needs to be sent to the Redis server, the condition of the RPC server does not need to be concerned, for example, the state and the number of the RPC server, the RPC client does not need to process addressing, and the RPC call process is simplified. In addition, even if the RPC server is not started or crashed, the call request of the RPC client is not lost, and at the moment, the call request can be processed as long as the RPC server is recovered.
In addition, the RPC client and the RPC server realize communication through the Redis server, the problems of receiving and sending packets of a transmission layer, sticking packets of TCP and connection recovery after network overtime are solved by processing through the Redis server, and a code writer is not needed to participate, so that the efficiency of processing service logic is greatly improved. The RPC implementation method shields the communication details of the network bottom layer for the service caller in the actual service code, and has strong applicability.
[ METHOD EXAMPLE 2 ]
Fig. 2 is a flowchart of a remote procedure call implementation method based on Redis according to embodiment 2 of the method of the present invention, and is suitable for an RPC server to respond to a synchronous call. Referring to fig. 2, in the present embodiment, the method includes:
step S21, establishing connection with a Redis server;
specifically, the RPC server is registered with a plurality of functions that need to be externally provided with a service. In addition, the Redis server is an efficient TCP server based on a Reactor model, and the RPC server establishes connection with the Redis server through a TCP protocol. In this embodiment, the asynchronous call uses the Redis enqueue lightweight API lpush.
Step S23, obtaining a call request stored in the Redis server;
step S25, when the call request is a synchronous call request, generating a synchronous call response according to the synchronous call request, wherein the synchronous call response comprises legal condition information of the synchronous call request and call execution condition information;
step S27, storing the synchronous calling response to the Redis server;
step S29, the process enters blocking until the synchronization call response stored in the Redis server is acquired by the RPC server.
Further, step S23 may include:
monitoring a built-in data structure message queue of a Redis server through message circulation;
when any calling request is not monitored, a brpop API provided by a data structure message queue of the Redis server causes the RPC server process to be blocked, and at the moment, the Redis server monitors all the time, polls for waiting messages and does not perform the next operation until the calling request exists in the data structure message queue;
when a call request is monitored, the call request at the head of the queue in the data structure message queue is obtained by utilizing a brpop API provided by the data structure message queue of the Redis server.
This operation of the RPC server is specifically a background daemon.
Further, step S25 may include:
when the function name contained in the synchronous calling request is registered in the RPC server and the function parameter field is legal, executing a local call to generate a synchronous calling response, wherein the synchronous calling response contains calling execution result information;
and when the function name contained in the synchronous call request is not registered in the RPC server or the function parameter field is illegal, generating a synchronous call response, wherein the synchronous call response contains illegal information of the synchronous call request and call execution failure information.
The synchronous call response generated by the RPC server, here in json format for example, has a structure of { "state",
"info", "finish _ time", "req _ time", "data", wherein the state field takes a value of 0 (indicating that the call request is still in process), or 1 (indicating that the call request is normal and the call request has successfully responded), or 2 (indicating that the synchronous call request is not normal, and the following info field gives detailed abnormal information); the info field gives the detailed information of the call; the finish _ time field indicates the end time of the call, in the form of unix timestamp; the req _ time field indicates the initiation time of the call, in the form of unix timestamp; the data field indicates the result of this process (when the process fails, the value is None).
Further, step S27 is specifically: and storing the synchronous call response to a preset channel of the Redis server, wherein the preset channel is in one-to-one correspondence with the synchronous call response.
It should be noted that the RPC server will try to issue multiple synchronous call responses to the Redis server to prevent the subscriber from not receiving the message, and certainly, the RPC client will only subscribe to the message once and then cancel the subscription.
Further, after step S23, the method further includes:
and performing deserialization processing on the acquired call request, and judging whether the call request subjected to deserialization processing is a synchronous call request or an asynchronous call request.
It can be understood that the call request after the deserialization processing by the RPC server is the call request before the serialization processing generated by the RPC client. And judging whether the calling request is synchronous or asynchronous calling according to the type field in the calling request.
In addition to the advantages of the method embodiment 1, for a large number of call requests, the RPC server processes the call requests through the Redis server, so that the burden of the RPC server is reduced, the stability of the RPC server is facilitated, and the RPC server is convenient to expand and deploy.
[ METHOD EXAMPLE 3 ]
Fig. 3 is a flowchart of a remote procedure call implementation method based on Redis according to embodiment 3 of the method of the present invention, and is applicable to an RPC client to indicate an asynchronous call. Referring to fig. 3, in the present embodiment, the method includes:
step S31, establishing connection with a Redis server;
step S33, receiving a calling instruction sent by an application layer;
step S35, when the calling instruction is asynchronous calling instruction, generating asynchronous calling request;
step S37, storing the asynchronous calling request to a Redis server;
step S39, returns the call result query credential message to the application layer and executes the next call instruction, or obtains the asynchronous call response stored in the Redis server according to the previous call result query credential message.
Further, the asynchronous call request generated by the RPC client is in a json structure format, and the structure of the asynchronous call request is the same as that of the synchronous call request of the json structure in method embodiment 1, but in this embodiment, the type field is sync.
Further, before step S37, the method further includes:
and performing deserialization processing on the asynchronous call request.
Preferably, step S37 specifically includes: the asynchronous call request is stored to a data structure message queue of the Redis server.
Further, after step S35, the method further includes:
generating an asynchronous call reference response corresponding to the asynchronous call request;
constructing a specific channel corresponding to the asynchronous call request in a Redis server;
and storing the asynchronous call reference response to the specific channel of the Redis server.
Specifically, the RPC client generates an asynchronous call reference response with a hash structure according to the req _ id field of the asynchronous call request, where the asynchronous call reference response structure is consistent with the field of the synchronous call response returned by the RPC server in method embodiment 2. In detail, the structure of the asynchronous call reference response is: { "state", "info", "finish _ time", "req _ time", "data" }. Wherein, the state field takes a value of 0; the info field is null; the finish _ time field is null; the req _ time field indicates the initiation time of this call (same as the req _ time in the asynchronous call request), in the form of a unix timestamp; the data field is empty.
In this embodiment, after step S37, the RPC client process is not blocked, and asynchronously waits for the call response returned by the RPC server, but returns a call result query credential message to the application layer and executes the next call instruction, or obtains the asynchronous call response stored in the Redis server according to the previous call result query credential message, where the call result query credential message is used to subsequently request the RPC client to view the asynchronous call response stored in the Redis server, and obtain the execution condition of the call, such as the completion condition and the call result.
In this embodiment, the invocation result query credential message may be an asyncreant object, the RPC client may determine whether this asynchronous invocation is completed through isdone (true or false) provided in the asyncreant object, and obtain a result of this asynchronous invocation (None is returned when not completed) through a result field.
The implementation of the RPC asynchronous call by the RPC client in this embodiment has the same advantages as those of the method embodiment 1, and is not described herein again.
[ METHOD EXAMPLE 4 ]
Fig. 4 is a flowchart of a remote procedure call implementation method based on Redis according to embodiment 4 of the method of the present invention, and is adapted to respond to an asynchronous call by an RPC server. Referring to fig. 4, in the present embodiment, the method includes:
step S41, establishing connection with a Redis server;
step S43, obtaining a call request stored in the Redis server;
step S45, when the call request is asynchronous call request, generating asynchronous call response according to the asynchronous call request, the asynchronous call response contains legal condition information of synchronous call request and call execution condition information;
step S47, the asynchronous call response is stored to the Redis server, and the step S43 is switched to.
It should be noted that, the generation of the synchronous call response according to the synchronous call request in this embodiment is similar to the generation of the synchronous call response according to the synchronous call request in embodiment 2, and details are not described here.
Further, step S47 is specifically: and updating the asynchronous call reference response stored on the specific channel of the Redis server by using the asynchronous call response.
The asynchronous call reference response may be a response generated by the PRC client and stored in a specific channel in the Redis server, which corresponds to the asynchronous call request one to one. Specifically, the RPC server updates the "state", "info", "finish _ time", and data "fields in the asynchronous call reference response stored in the Redis server after the normal local call is ended, to fill in the state of the process, detailed process information, process time, and process result information.
At this point, the RPC server completes processing of an asynchronous call request without waiting for the Client to receive a result.
The RPC server in this embodiment has the same advantages as the method in embodiment 2 when implementing RPC asynchronous call, and is not described herein again.
[ DEVICE EXAMPLE 1 ]
Fig. 5 is a schematic diagram of a remote procedure call implementation device based on Redis according to embodiment 1 of the present invention, where the remote procedure call implementation device is located on an RPC client side and responds to a synchronous call. Referring to fig. 5, in the present embodiment, the apparatus includes:
a first connection establishing module 51, configured to establish a connection with a Redis server;
a calling instruction receiving module 52, configured to receive a calling instruction sent by an application layer;
a synchronous call request generation and storage module 53, configured to generate a synchronous call request when the call instruction is a synchronous call instruction, and store the synchronous call request to the Redis server;
and the first synchronous call post-processing module 54 is configured to block the RPC client process until it is monitored that a synchronous call response corresponding to the synchronous call request exists in the Redis server, and obtain the synchronous call response.
In this embodiment, the synchronous call request generated by the synchronous call request generating and storing module 53 may be in a json structure format.
Further, the remote procedure call implementation device further comprises:
and the predetermined channel building module is used for building a predetermined channel corresponding to the synchronous calling request in the Redis server, so that after the RPC server carries out calling judgment processing according to the synchronous calling request stored in the Redis server, the generated synchronous calling response is stored in the predetermined channel of the Redis server. Under the condition, the RPC client enters a subscriber mode, the subscribed preset channel is the only channel generated according to the synchronous call request, and therefore the preset channel can be guaranteed to be subscribed only by the subscriber. .
Further, the synchronization call request generating and storing module 53 is specifically configured to store the synchronization call request to a data structure message queue of the Redis server, so that the RPC server can utilize a brpop API provided by the data structure message queue of the Redis server to implement enqueue and dequeue operations of the synchronization request message in the data structure message queue. At this point, the synchronous call request enters from the left side of the data structure message queue and dequeues from the right side of the data structure message queue. .
[ DEVICE EXAMPLE 2 ]
Fig. 6 is a schematic diagram of a remote procedure call implementation device based on Redis according to embodiment 2 of the present invention, where the remote procedure call implementation device is located on an RPC server side and responds to a synchronous call. Referring to fig. 6, in the present embodiment, the apparatus includes:
a second connection establishing module 61, configured to establish a connection with a Redis server;
a calling request obtaining module 62, configured to obtain a calling request stored in a Redis server;
a synchronous call response generation and storage module 63, configured to generate a synchronous call response when the call request is a synchronous call request, where the synchronous call response includes legal condition information and call execution condition information of the synchronous call request, and store the synchronous call response to the Redis server;
and the second synchronous call post-processing module 64 is used for blocking the RPC server process until the synchronous call response stored in the Redis server is acquired by the RPC server.
Further, the synchronous call response generation and storage module 63 is specifically configured to execute a local call when the function name included in the synchronous call request is registered in the RPC server and the function parameter field is legal, and generate a synchronous call response, where the synchronous call response includes call execution result information; and when the function name contained in the synchronous call request is not registered in the RPC server or the function parameter field is illegal, generating a synchronous call response, wherein the synchronous call response contains illegal information of the synchronous call request and call execution failure information.
Further, the synchronization call response generation and storage module 63 is further specifically configured to store the synchronization call response to a predetermined channel of the Redis server.
Further, the invocation request obtaining module 62 includes:
the monitoring unit is used for monitoring a data structure message queue of the Redis server through message circulation;
the process blocking unit is used for entering the process into blocking when no call request of the data structure message queue is monitored;
and the call request acquisition unit is used for acquiring a call request at the head of the data structure message queue by using a brpop API provided by the data structure message queue of the Redis server when the call request is monitored to be in the data structure message queue.
[ DEVICE EXAMPLE 3 ]
Fig. 7 is a schematic diagram of a remote procedure call implementation device based on Redis according to embodiment 3 of the present invention, where the remote procedure call implementation device is located on the RPC client side and responds to asynchronous calls. Referring to fig. 7, in the present embodiment, the apparatus includes:
a first connection establishing module 51, configured to establish a connection with a Redis server;
a calling instruction receiving module 52, configured to receive a calling instruction sent by an application layer;
an asynchronous call request generation and storage module 73, configured to generate an asynchronous call request when the call instruction is an asynchronous call instruction, and store the asynchronous call request to a Redis server;
and the first asynchronous call post-processing module 74 is configured to return a call result query credential message to the application layer according to the asynchronous call request, and notify the call instruction receiving module 52 to receive a next call instruction, or obtain an asynchronous call response stored in the Redis server according to a previous call result query credential message.
Further, the remote procedure call implementation device further comprises:
the asynchronous call reference response generation module is used for generating an asynchronous call reference response corresponding to the asynchronous call request;
the specific channel building module is used for building a specific channel corresponding to the asynchronous call request in the Redis server;
and the asynchronous call reference response storage module is used for storing the asynchronous call reference response to a specific channel of the Redis server.
Further, the asynchronous call request generating and storing module 71 is specifically configured to store the asynchronous call request to a data structure message queue of the Redis server.
[ DEVICE EXAMPLE 4 ]
Fig. 8 is a schematic diagram of a remote procedure call implementation device based on Redis according to an embodiment 4 of the present invention, where the remote procedure call implementation device is located on the RPC server side and responds to asynchronous calls. Referring to fig. 8, in the present embodiment, the apparatus includes:
a second connection establishing module 61, configured to establish a connection with a Redis server;
a calling request obtaining module 62, configured to obtain a calling request stored in a Redis server;
an asynchronous call response generation and storage module 83, which generates an asynchronous call response when the call request is a synchronous call request, the asynchronous call response including legal condition information and call execution condition information of the asynchronous call request, and stores the asynchronous call response to the Redis server;
the second asynchronous call post-processing module 84 is configured to notify the call request obtaining module 62 to obtain a next call request after the asynchronous call response generating and storing module 83 stores the asynchronous call response to the Redis server.
Further, the asynchronous call response generation and storage module 83 is specifically configured to update the asynchronous call reference response stored on the particular channel of the Redis server with the asynchronous call response.
An embodiment of the present invention further provides a computer device, including a processor and a memory, where the memory stores a computer program, and the processor is configured to execute the computer program stored in the memory to implement any one of the methods for implementing remote procedure call based on Redis mentioned above, or to implement processing performed by any one of the devices for implementing remote procedure call based on Redis mentioned above.
Furthermore, an embodiment of the present invention further provides a computer storage medium, in which a computer program is stored, where the computer program, when executed by a processor, implements any one of the methods for implementing remote procedure call based on Redis mentioned above, or implements processing performed by any one of the devices for implementing remote procedure call based on Redis mentioned above.
The storage medium and the computer equipment realize the remote procedure call realization method based on Redis, and the RPC client and the RPC server are thoroughly decoupled in the same way, interact through the Redis server, shield the communication details of the network bottom layer for a service caller, and have strong applicability. The RPC client side initiates the call request without depending on the RPC server, so addressing is not required to be processed, and the RPC call process is simplified. In addition, problems such as transmission layer receiving and sending packets, TCP sticky packets and the like are all processed by the Redis server, and compared with the existing method that the problems are processed by a code writer, the efficiency of processing the service logic is greatly improved. In addition, for a large number of call requests, the RPC server processes the call requests through the Redis server, and the burden of the RPC server is greatly reduced.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts in the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus and device embodiments, since they are substantially similar to the method embodiments, they are described relatively simply, and reference may be made to some descriptions of the method embodiments for relevant points.
Those skilled in the art will clearly understand that the present invention may be implemented entirely in software, or by a combination of software and a hardware platform. With this understanding in mind, all or part of the technical solutions of the present invention that contribute to the background can be embodied in the form of a software product, which can be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes instructions for causing a computer device (which can be a personal computer, a server, a smart phone, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments of the present invention.
As used herein, the term "software" or the like refers to any type of computer code or set of computer-executable instructions in a general sense that is executed to program a computer or other processor to perform various aspects of the present inventive concepts as discussed above. Furthermore, it should be noted that according to one aspect of the embodiment, one or more computer programs implementing the method of the present invention when executed do not need to be on one computer or processor, but may be distributed in modules in multiple computers or processors to execute various aspects of the present invention.
Computer-executable instructions may take many forms, such as program modules, executed by one or more computers or other devices. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. In particular, the operations performed by the program modules may, in various embodiments, be combined or divided as desired in various different embodiments.
Also, technical solutions of the present invention may be embodied as a method, and at least one example of the method has been provided. The actions may be performed in any suitable order and may be presented as part of the method. Thus, embodiments may be configured such that acts may be performed in an order different than illustrated, which may include performing some acts simultaneously (although in the illustrated embodiments, the acts are sequential).
In various embodiments of the invention, the described features, architectures or functions may be combined in any combination in one or more embodiments, where well-known processes of operation, program modules, elements and their interconnection, linking, communication or operation with each other are not shown or described in detail. It will be understood by those skilled in the art that the various embodiments described below are illustrative only and are not intended to limit the scope of the present invention. Those skilled in the art will also readily appreciate that the program modules, elements, or steps of the various embodiments described herein and illustrated in the accompanying drawings may be combined and arranged in a wide variety of different configurations.
Technical terms not specifically described in the present specification should be construed in the broadest sense in the art unless otherwise specifically indicated. The definitions given and used herein should be understood with reference to dictionaries, definitions in documents incorporated by reference, and/or their ordinary meanings. The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application.
As used in the claims and in the specification above, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. The term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items. It is to be understood that, although the terms first, second, third, etc. may be used herein to describe various information and/or modules, these information should not be limited by these terms. These terms are only used to distinguish one type of information and/or module from another. For example, a first information and/or module may also be referred to as a second information and/or module, and similarly, a second information and/or module may also be referred to as a first information and/or module without departing from the scope hereof. Additionally, the word "if" as used herein, whose meaning depends on context, may be interpreted as "at … …" or "at … …" or "in response to a determination".
In the claims, as well as in the specification above, all transitional phrases such as "comprising," "having," "containing," "carrying," "having," "involving," "consisting essentially of …," and any other variations thereof, are to be understood to be open-ended, i.e., to include, but not be limited to, non-exclusive inclusions, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The terms and expressions used in the specification of the present invention have been set forth for illustrative purposes only and are not meant to be limiting. It will be appreciated by those skilled in the art that changes could be made to the details of the above-described embodiments without departing from the underlying principles thereof. The scope of the invention is, therefore, indicated by the appended claims, in which all terms are intended to be interpreted in their broadest reasonable sense unless otherwise indicated.

Claims (14)

1. A remote procedure call implementation method based on Redis is suitable for RPC clients, and comprises the following steps:
establishing connection with a Redis server;
receiving a calling instruction sent by an application layer;
when the calling instruction is a synchronous calling instruction, generating a synchronous calling request, and storing the synchronous calling request to the Redis server; then, the process enters blocking until a synchronous calling response corresponding to the synchronous calling request exists in the Redis server, and the synchronous calling response is sent to an application layer;
when the calling instruction is an asynchronous calling instruction, generating an asynchronous calling request, and storing the asynchronous calling request to the Redis server; and then returning a calling result inquiry credential message to the application layer and executing a next calling instruction, or acquiring an asynchronous calling response stored in the Redis server according to the previous calling result inquiry credential message.
2. The Redis-based remote procedure call implementation method of claim 1, wherein after the generating of the synchronous call request, further comprising:
constructing a predetermined channel corresponding to the synchronous call request in the Redis server, and/or,
after the generating of the asynchronous call request, the method further comprises:
generating an asynchronous call reference response corresponding to the asynchronous call request;
constructing a specific channel corresponding to the asynchronous call request in the Redis server;
storing the asynchronous call reference response to a specific channel of the Redis server.
3. The Redis-based remote procedure call implementation method according to claim 2, wherein the synchronous call request and/or the asynchronous call request are stored to a data structure message queue of the Redis server.
4. A remote procedure call implementation method based on Redis is applicable to an RPC server, and comprises the following steps:
establishing connection with a Redis server;
acquiring a call request stored in the Redis server;
when the calling request is a synchronous calling request, generating a synchronous calling response, wherein the synchronous calling response comprises legal condition information and calling execution condition information of the synchronous calling request, and storing the synchronous calling response to the Redis server; then the process enters blocking until the synchronous call response stored in the Redis server is acquired by the RPC server;
and when the calling request is a synchronous calling request, generating an asynchronous calling response, wherein the asynchronous calling response comprises legal condition information and calling execution condition information of the asynchronous calling request, storing the asynchronous calling response to the Redis server, and then executing the next calling request.
5. The remote procedure call implementation method according to claim 4, wherein the storing the synchronous call response to the Redis server specifically includes:
storing the synchronization call response to a predetermined channel of the Redis server, and/or,
the storing the asynchronous call response to the Redis server specifically includes:
and updating the asynchronous call reference response stored on the specific channel of the Redis server by using the asynchronous call response.
6. The remote procedure call implementation method of claim 5, wherein the obtaining the call request stored in the Redis server comprises:
monitoring a data structure message queue of the Redis server through message circulation;
when no call request of the data structure message queue is monitored, the process enters blocking; and when a call request is monitored in the data structure message queue, obtaining the call request at the head of the data structure message queue by using a brpop API provided by the data structure message queue of the Redis server.
7. A remote procedure call implementation apparatus based on Redis, located on an RPC client side, comprising:
the first connection establishing module is used for establishing connection with a Redis server;
the calling instruction receiving module is used for receiving a calling instruction sent by the application layer;
the synchronous call request generating and storing module is used for generating a synchronous call request when the call instruction is a synchronous call instruction, and storing the synchronous call request to the Redis server;
the first synchronous call post-processing module is used for blocking the RPC client process until the synchronous call response corresponding to the synchronous call request exists in the Redis server and acquiring the synchronous call response;
the asynchronous call request generating and storing module is used for generating an asynchronous call request when the call instruction is an asynchronous call instruction, and storing the asynchronous call request to the Redis server;
and the first asynchronous call post-processing module is used for returning a call result query credential message to the application layer according to the asynchronous call request, and executing a next call instruction, or acquiring an asynchronous call response stored in the Redis server according to a previous call result query credential message.
8. The Redis-based remote procedure call implementation apparatus according to claim 7, wherein the remote procedure call implementation apparatus further comprises:
a predetermined channel construction module for constructing a predetermined channel corresponding to the synchronous call request in the Redis server, and/or,
the remote procedure call implementation device further comprises:
the asynchronous call reference response generation module is used for generating an asynchronous call reference response corresponding to the asynchronous call request;
the specific channel building module is used for building a specific channel corresponding to the asynchronous call request in the Redis server;
and the asynchronous call reference response storage module is used for storing the asynchronous call reference response to a specific channel of the Redis server.
9. The Redis-based remote procedure call implementation apparatus according to claim 8, wherein the synchronous call request generation and storage module specifically stores the synchronous call request to a data structure message queue of the Redis server, and/or the asynchronous call request generation and storage module specifically stores the asynchronous call request to a data structure message queue of the Redis server.
10. A remote procedure call implementation device based on Redis, located on the RPC server side, includes:
the second connection establishing module is used for establishing connection with the Redis server;
the calling request acquisition module is used for acquiring a calling request stored in the Redis server;
a synchronous call response generation and storage module, configured to generate a synchronous call response when the call request is a synchronous call request, where the synchronous call response includes legal condition information and call execution condition information of the synchronous call request, and store the synchronous call response to the Redis server;
the second synchronous call post-processing module is used for blocking the RPC server process until the synchronous call response stored in the Redis server is acquired by the RPC server;
the asynchronous call response generation and storage module is used for generating an asynchronous call response when the call request is a synchronous call request, wherein the asynchronous call response comprises legal condition information and call execution condition information of the asynchronous call request, and the asynchronous call response is stored to the Redis server;
and the second asynchronous call post-processing module is used for notifying the call request acquisition module to acquire a next call request after the asynchronous call response generation and storage module stores the asynchronous call response to the Redis server.
11. The remote procedure call implementation device according to claim 10, wherein the synchronization call response generation and storage module is specifically configured to store the synchronization call response to a predetermined channel of the Redis server, and/or,
the asynchronous call response generation and storage module is specifically configured to update an asynchronous call reference response stored on a particular channel of the Redis server with the asynchronous call response.
12. The remote procedure call implementation device of claim 11, wherein the call request acquisition module comprises:
a monitoring unit, configured to monitor a data structure message queue of the Redis server through message circulation;
the process blocking unit is used for entering the process into blocking when no call request of the data structure message queue is monitored;
and the call request acquisition unit is used for acquiring a call request of the head of the data structure message queue by using a brpop API provided by the data structure message queue of the Redis server when the call request is monitored to be in the data structure message queue.
13. A computer device, comprising:
a processor; and
a memory for storing a computer program for executing a computer program,
wherein the processor is configured to execute the computer program stored in the memory to implement the remote procedure call implementation method of any one of claims 1 to 6.
14. A computer storage medium, wherein a computer program is stored in the computer storage medium, and wherein the computer program, when executed by a processor, implements the remote procedure call implementation method of any one of claims 1 to 6.
CN201810618188.4A 2018-06-15 2018-06-15 Remote procedure call implementation method based on Redis and related device Pending CN110611687A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810618188.4A CN110611687A (en) 2018-06-15 2018-06-15 Remote procedure call implementation method based on Redis and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810618188.4A CN110611687A (en) 2018-06-15 2018-06-15 Remote procedure call implementation method based on Redis and related device

Publications (1)

Publication Number Publication Date
CN110611687A true CN110611687A (en) 2019-12-24

Family

ID=68887936

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810618188.4A Pending CN110611687A (en) 2018-06-15 2018-06-15 Remote procedure call implementation method based on Redis and related device

Country Status (1)

Country Link
CN (1) CN110611687A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111752720A (en) * 2020-06-27 2020-10-09 武汉众邦银行股份有限公司 Asynchronous request disguising synchronous request method
CN112929431A (en) * 2021-02-01 2021-06-08 深圳市科漫达智能管理科技有限公司 Message synchronous and asynchronous response conversion method and device based on micro-service framework
CN114422570A (en) * 2021-12-31 2022-04-29 深圳市联软科技股份有限公司 Cross-platform multi-module communication method and system
CN114584500A (en) * 2022-02-25 2022-06-03 网易(杭州)网络有限公司 Asynchronous communication testing method and device and electronic equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140215057A1 (en) * 2013-01-28 2014-07-31 Rackspace Us, Inc. Methods and Systems of Monitoring Failures in a Distributed Network System
CN105592164A (en) * 2016-01-25 2016-05-18 珠海格力电器股份有限公司 Distributed system and method for data processing
CN106888218A (en) * 2017-04-01 2017-06-23 网易(杭州)网络有限公司 Message treatment method, device, client and service end

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140215057A1 (en) * 2013-01-28 2014-07-31 Rackspace Us, Inc. Methods and Systems of Monitoring Failures in a Distributed Network System
CN105592164A (en) * 2016-01-25 2016-05-18 珠海格力电器股份有限公司 Distributed system and method for data processing
CN106888218A (en) * 2017-04-01 2017-06-23 网易(杭州)网络有限公司 Message treatment method, device, client and service end

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111752720A (en) * 2020-06-27 2020-10-09 武汉众邦银行股份有限公司 Asynchronous request disguising synchronous request method
CN111752720B (en) * 2020-06-27 2023-07-07 武汉众邦银行股份有限公司 Asynchronous request disguising synchronous request method
CN112929431A (en) * 2021-02-01 2021-06-08 深圳市科漫达智能管理科技有限公司 Message synchronous and asynchronous response conversion method and device based on micro-service framework
CN112929431B (en) * 2021-02-01 2022-12-20 深圳市科漫达智能管理科技有限公司 Message synchronous and asynchronous response conversion method and device based on micro-service framework
CN114422570A (en) * 2021-12-31 2022-04-29 深圳市联软科技股份有限公司 Cross-platform multi-module communication method and system
CN114422570B (en) * 2021-12-31 2024-05-14 深圳市联软科技股份有限公司 Cross-platform multi-module communication method and system
CN114584500A (en) * 2022-02-25 2022-06-03 网易(杭州)网络有限公司 Asynchronous communication testing method and device and electronic equipment
CN114584500B (en) * 2022-02-25 2024-03-22 网易(杭州)网络有限公司 Asynchronous communication testing method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN110611687A (en) Remote procedure call implementation method based on Redis and related device
CN109284197B (en) Distributed application platform based on intelligent contract and implementation method
CN102377686B (en) Message subscription system, method and device
CN111580995B (en) Synchronous communication method and system of distributed cloud platform and Internet of things intelligent terminal based on MQTT asynchronous communication scene
CN106453288A (en) Asynchronous mode supporting distributed micro service framework system and implementation method thereof
CN106980543A (en) The distributed task dispatching method and device triggered based on event
CN109753364A (en) A kind of implementation method, equipment and the medium of network-based distributed lock
CN110995797B (en) Multilayer B/S and C/S mixed software system and asynchronous real-time communication method between layers
US20040199611A1 (en) Method and system for remote configuration of network devices
CN112597249B (en) Synchronous distribution storage method and system for service data
CN110377431B (en) Service calling method and device under multi-registry scene
US20070016673A1 (en) Information exchange system and management server, terminal unit, and method for reducing network load used in the same
CN111770172A (en) Message middleware consumption proxy method, device, proxy server and storage medium
CN111258723B (en) Transaction processing method, device, system, medium and equipment of distributed system
CN110166730B (en) Request processing method, device, equipment and readable storage medium
WO2015100646A1 (en) Implementation method and implementation platform for software architecture
CN111212085A (en) Internet of things platform synchronous calling method, Internet of things system and network equipment
CN112583895B (en) TCP communication method, system and device
CN109450711A (en) The choosing method of host node, device, system and storage medium in distributed system
CN109788036B (en) Distributed computing method and device based on cloud network and cloud server with distributed computing method and device
CN110674172A (en) Data query method and device
CN113342503B (en) Real-time progress feedback method, device, equipment and storage medium
CN106293970B (en) Asynchronous processing method and system between a kind of process based on IPC
CN115550354A (en) Data processing method and device and computer readable storage medium
CN115696366A (en) Digital twin subsystem and service providing device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20191224