An input/output proxy method for a mimic Redis database, comprising a mimic Redis database, a mimic input/output proxy container and an arbiter, wherein the mimic Redis database comprises at least three database containers running Redis server processes;
- the mimic input/output proxy container comprises a pseudo server module, an arbiter interaction module, and no less than three database interaction modules;
- the arbiter interaction module is connected with the arbiter;
- the database interaction module is connected with the database container;
- the method specifically comprises the following steps:
- S1, initialization phase:
- enabling the pseudo server module, the arbiter interaction module and the database interaction modules to run as independent processes, and establishing data transmission channels for inter-process communication between the pseudo server module and the arbiter interaction module and the database interaction modules;
- S2, receiving, by the pseudo server module, a connection establishment request initiated by a user, creating a socket bound to the user and establishing a connection while maintaining the state information of the user connection;
- S3, receiving, by the pseudo server module, a command request initiated by the user, updating the state information of the user connection, obtaining the type of the command request according to a definition mode of the type of the command request, and starting a response mode corresponding to the type of the command request;
- performing, by a pseudo server module, a corresponding operation according to the response mode;
- and
- S4, performing, by the pseudo server module, dynamic data synchronization;
- specifically comprising the following steps:
- S41, maintaining, by the pseudo server module, a public key space, wherein the public key space stores a series of key-value pairs, keys in the key-value pairs are in one-to-one correspondence to keys in an actual Redis database, and values in the key-value pairs store a synchronization state;
- S42, maintaining, by the pseudo server module, an iterator of a public key space, wherein the iterator is configured to traverse key-value pairs in the public key space;
- and
- S43, calling, by the pseudo server module, the iterator periodically to obtain key-value pairs in the public key space and determining whether to perform a synchronization action according to the synchronization state stored in the values in the key-value pairs;
- wherein
- the judgment standard of determining whether to perform synchronization according to the synchronization state is to employ a random credit attenuation mechanism, and the random credit attenuation mechanism specifically comprises the following steps:
- S431, when a key-value pair is newly added to the public key space maintained by the pseudo server module, calling a random number generator to generate a random number, and storing the random number in the synchronization state corresponding to the keys;
- S432, obtaining, by the pseudo server module, the key-value pair to be processed in the public key space through the iterator and attenuating the random number stored in the synchronization state according to a specific step size;
- S433, synchronizing the keys to be processed if the value of the attenuated random number is less than a set threshold, regenerating a random number after synchronization is completed, and storing the random number in the synchronization state;
- and
- S434, calling, by the pseudo server module, the iterator to obtain the next key-value pair to be processed if the value of the attenuated random number is not less than the set threshold;
- and
- S44, obtaining, by the pseudo server module, data values, corresponding to the keys needing to be synchronized, in the databases through a plurality of database interaction modules respectively, sending, by the pseudo server module, the corresponding data values in the databases to the arbiter for arbitration through the arbiter interaction module and obtaining an arbitration result, and updating, by the pseudo server module, the corresponding data values in the databases according to the arbitration result to complete the data synchronization.