CN111984663B - REDIS database updating method, REDIS database updating device, REDIS database updating computer equipment and REDIS database storage medium - Google Patents
REDIS database updating method, REDIS database updating device, REDIS database updating computer equipment and REDIS database storage medium Download PDFInfo
- Publication number
- CN111984663B CN111984663B CN202010861934.XA CN202010861934A CN111984663B CN 111984663 B CN111984663 B CN 111984663B CN 202010861934 A CN202010861934 A CN 202010861934A CN 111984663 B CN111984663 B CN 111984663B
- Authority
- CN
- China
- Prior art keywords
- redis
- data
- command
- row
- class
- 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.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 85
- 230000008859 change Effects 0.000 claims abstract description 41
- 230000003993 interaction Effects 0.000 claims abstract description 25
- 238000012545 processing Methods 0.000 claims abstract description 20
- 230000005540 biological transmission Effects 0.000 claims abstract description 9
- 239000002131 composite material Substances 0.000 claims description 9
- 238000012986 modification Methods 0.000 claims description 8
- 230000004048 modification Effects 0.000 claims description 8
- 238000004590 computer program Methods 0.000 claims description 7
- 238000012217 deletion Methods 0.000 claims description 7
- 230000037430 deletion Effects 0.000 claims description 7
- 230000003068 static effect Effects 0.000 claims description 6
- 238000007792 addition Methods 0.000 claims description 5
- 230000007246 mechanism Effects 0.000 abstract description 10
- 102100039371 ER lumen protein-retaining receptor 1 Human genes 0.000 abstract description 7
- 101000812437 Homo sapiens ER lumen protein-retaining receptor 1 Proteins 0.000 abstract description 7
- QOSSAOTZNIDXMA-UHFFFAOYSA-N Dicylcohexylcarbodiimide Chemical compound C1CCCCC1N=C=NC1CCCCC1 QOSSAOTZNIDXMA-UHFFFAOYSA-N 0.000 description 27
- 230000006870 function Effects 0.000 description 26
- 230000008569 process Effects 0.000 description 17
- 230000004044 response Effects 0.000 description 15
- 238000010586 diagram Methods 0.000 description 11
- 230000001360 synchronised effect Effects 0.000 description 10
- 238000013507 mapping Methods 0.000 description 7
- 238000005516 engineering process Methods 0.000 description 6
- 239000008186 active pharmaceutical agent Substances 0.000 description 5
- 238000006243 chemical reaction Methods 0.000 description 5
- 238000004458 analytical method Methods 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000013500 data storage Methods 0.000 description 3
- 238000013461 design Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 238000010276 construction Methods 0.000 description 2
- 238000005538 encapsulation Methods 0.000 description 2
- 238000003780 insertion Methods 0.000 description 2
- 230000037431 insertion Effects 0.000 description 2
- 238000011068 loading method Methods 0.000 description 2
- 230000010076 replication Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000013523 data management Methods 0.000 description 1
- 238000013499 data model Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000007667 floating Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000012544 monitoring process Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 239000000047 product Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 239000013589 supplement Substances 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2379—Updates performed during online database operations; commit processing
- G06F16/2386—Bulk updating operations
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/235—Update request formulation
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a REDIS database updating method, a REDIS database updating device, a REDIS database updating computer device and a REDIS database updating storage medium, wherein the REDIS database updating method comprises the steps of obtaining batch row data to be updated and operation identifiers; analyzing the batch line data to generate a data interaction structure, and converting the data interaction structure into REDIS commands according to the operation identifiers; adding information-designating channel transmission commands to the set of REDIS commands; and executing REDIS command in a channel mode, and returning execution success or failure according to the execution result. The method proposed by the embodiment of the present application uses the pipeline mechanism of REDIS to convert batches of row and column data into multiple HMSET and HDEL commands. The batch change data sequence can be converted into a specified format, and other homonymous table objects are notified by issuing commands so as to realize batch data update, improve data update efficiency, avoid the occurrence of processing failure as far as possible, and bring convenience to users.
Description
Technical Field
The present invention relates to the field of database technologies, and in particular, to a REDIS database updating method, apparatus, computer device, and storage medium.
Background
With the rapid development of internet technology, the distributed architecture system is continuously perfected, and higher requirements are put on the response speed of software and the overall performance of the system by users. The cache mechanism is adopted to solve the problems of high concurrent requests and hot spot data storage, and becomes a popular preferred scheme. The caching mechanism stores data in the memory by utilizing the high-speed read-write characteristic of the memory so as to improve the data access speed and reduce the performance loss of the system in the data read-write part.
Redis (Remote Dictionary Server) is a non-relational memory database which uses Key-Value as a data model, is free of source and supports high-performance concurrent reading and writing, can support various data storage structures such as character strings, lists, sets, ordered sets and hash tables, provides a publishing and subscribing message communication mode, and has strong data management capability widely applied to the scenes such as cache, data publishing and subscribing. REDIS hash types are mapping tables of fields and value fields of a string type, whose (key-field-value) structure is similar to that of an object (identifier-attribute name-attribute value), and can be used to store objects that are structurally simple and have no complex relationship query.
REDIS has the advantages of distributed storage of key values, no coupling between data, strong expandability, high searching speed and the like, but the stored data is unstructured and has no coupling, and the data is only of a binary type, so that the REDIS has a very obvious disadvantage. When a developer uses a language associated with a strong type such as C/c++, it is necessary to handle conversion between a programming language associated data type such as integer, floating point, boolean, etc. and REDIS data type, and it is not easy to understand the relevance and cohesiveness of service data. Meanwhile, redis provides a plurality of client commands for performing operations such as adding, deleting, checking and the like on the REDIS server, and provides client APIs of multiple programming languages so as to complete interaction with the Redis database in the software development process. Hirdis is a lightweight C language client function library accessing the Redis database, and basically realizes minimum support for the Redis protocol. The Hiredis comprises a synchronous API and an asynchronous API, and the use method of the native interface is flexible. The asynchronous API needs to work with a third party asynchronous event library. For example, libevent is an open source, lightweight, cross-platform, high performance event notification library written in C language, supporting event driven and multiple I/O multiplexing techniques, and is widely used as a bottom layer network library.
In summary, a great deal of time and effort are required for the software developer to learn the REDIS command and the application method of the client API before using the REDIS, so that the time and labor costs are high, the overall progress of software development is affected to a certain extent, and the complexity of the later maintenance of the software is increased.
For the above reasons, the applicant proposes an automatic table data synchronization method, but in the table synchronization method, when a database is updated, the problem of slow batch data processing and high failure probability exists, and inconvenience is brought to a user.
The information disclosed in this background section is only for enhancement of understanding of the general background of the invention and should not be taken as an acknowledgement or any form of suggestion that this information forms the prior art already known to a person skilled in the art.
For the above reasons, the applicant proposes a REDIS database updating method, apparatus, computer device, storage medium.
Disclosure of Invention
In order to meet the above requirements, a first object of the present invention is to provide a REDIS database updating method.
A second object of the present invention is to provide a REDIS database updating apparatus.
A third object of the present invention is to provide a computer device.
A fourth object of the present invention is to provide a non-transitory computer readable storage medium.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
in one aspect, an embodiment of the present application provides a REDIS database updating method, including the following steps:
acquiring batch line data to be updated and an operation identifier;
analyzing the batch line data to generate a data interaction structure, and converting the data interaction structure into REDIS commands according to the operation identifiers;
adding information-designating channel transmission commands to the REDIS command set;
and executing the REDIS command in a channel mode, and returning execution success or failure according to an execution result.
In one possible embodiment, the operation identifier includes an identifier of addition, deletion, or modification.
In one possible implementation, when the operation is identified as an add or modify, the corresponding REDIS command is a REDIS Hmset command.
In one possible implementation, the REDIS command is a REDIS Hdel command when the operation identification is delete.
In a possible implementation manner, the step of converting the data interaction structure into a REDIS command according to the operation identifier includes making the REDIS command include commands for operating all lines to be operated.
In a possible embodiment, the step of causing the REDIS command to include commands to operate on all rows to be operated includes, after the step of causing the REDIS command to include commands to operate on all rows to be operated on, serializing the data interaction structure.
In one possible embodiment, the step of adding the information-designating channel transmission command to the set of REDIS commands includes acquiring a table name and a serialized data interaction structure, and transmitting information to the designated channel.
In another aspect, an embodiment of the present application further provides a REDIS database updating apparatus, including:
the data acquisition unit is used for acquiring batch line data to be updated and operation identifiers;
the data command unit is used for analyzing the batch data to generate a data interaction structure, and converting the data interaction structure into REDIS commands according to the operation identification;
a change issuing command unit configured to assign a channel transmission command to the set of REDIS commands by adding information;
and the result acquisition unit is used for executing the REDIS command in a channel mode and returning execution success or failure according to an execution result.
In a third aspect, an embodiment of the present application further provides a computer device, including a memory, a processor, and a REDIS database update program stored on the memory and capable of running on the processor, where the REDIS database update program when executed by the processor implements a REDIS database update method as described in any one of the above.
In a fourth aspect, embodiments of the present application provide a non-transitory computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a REDIS database updating method as described in any of the above.
Compared with the prior art, the invention has the beneficial effects that: the REDIS database updating method provided by the embodiment of the application utilizes a REDIS pipeline mechanism to convert batch rows and column data into a plurality of HMSET and HDEL commands. The batch change data sequence can be converted into a specified format, and other homonymous table objects are notified by issuing commands so as to realize batch data update, improve data update efficiency, avoid the occurrence of processing failure as far as possible, and bring convenience to users.
The invention is further described below with reference to the drawings and specific embodiments.
Drawings
Fig. 1 is a flowchart of an embodiment of a REDIS database updating method according to an embodiment of the present application;
fig. 2 is a structural block diagram of a two-dimensional table of a specific application scenario of a REDIS database updating method according to an embodiment of the present application;
FIG. 3 is a schematic diagram of attributes and methods defined by the cell class of the table of FIG. 2;
FIG. 4 is a schematic diagram of attributes and methods defined by the cell set class of the table of FIG. 2;
FIG. 5 is a schematic diagram of attributes and methods defined by the data row class of the table of FIG. 2;
FIG. 6 is a schematic diagram of attributes and methods defined by the data line set class of the table of FIG. 2;
FIG. 7 is a schematic diagram of attributes and methods of class definition of the table of FIG. 2;
fig. 8 is a schematic block diagram of a REDIS database updating apparatus provided in an embodiment of the present application;
fig. 9 is a schematic block diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
It should be understood that the terms "comprises" and "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the present application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
Referring to fig. 1, fig. 1 is a flowchart of a specific embodiment of a REDIS database updating method according to an embodiment of the present application, including the following steps:
step S101, acquiring batch line data to be updated and operation identifiers;
specifically, in this embodiment, it is necessary to acquire data for updating the REDIS database and what operation is performed on the data in order to accurately implement the data updating.
Step S102, analyzing the batch line data to generate a data interaction structure, and converting the data interaction structure into REDIS commands according to the operation identifiers;
In this embodiment, each line of data needs to be parsed into a subscription publishing data structure (data interaction structure), and then the subscription publishing structure is converted into a REDIS command according to the operation identifier.
In one embodiment, a publish-subscribe data structure (data interaction structure) is defined as a composite type that includes an operation identifier, a database index, a table name, a table number, and change row data. The row data comprises a row number and a row attribute set; the line attribute data includes an attribute name and an attribute value. The table instance of the publish-subscribe composite structure is serialized into a JSON string, and the table instance of the subscribe-change notification is inversely serialized into a composite structure.
In some embodiments, if the operation is identified as an add or modify, the data is converted to a REDIS HMSET KEY F V1[ F2V 2 … ] command. If the operation is identified as delete, the data is converted into REDIS's HDEL KEY F1[ F2 … ] command, wherein KEY in the command is "table name: line number", and Fn and Vn correspond to the name and value of each cell in the line.
Step S103, adding information to the REDIS command set to specify a channel transmission command;
specifically, in order to implement batch data updating of each table with the same name, all lines to be operated need to be converted into REDIS commands according to rules, then the whole publishing and subscribing structure is serialized, and a PUBLISH CHANNEL MESSAGE command is added to a REDIS command set to be executed, wherein CHANNEL is a table name, and MESSAGE is the serialized publishing and subscribing data.
Step S104, executing the REDIS command in a channel mode, and returning execution success or failure according to an execution result.
In one embodiment, REDIS's pipeline mechanism may be utilized to convert batches of row and column data into a plurality of HMSET and HDEL commands. The pipeline has the following beneficial effects:
omitting the command queuing time due to single thread, the elapsed time of one command = one network time + command execution time;
with respect to command execution time, network time is likely to become a bottleneck of the system, and the role of pipeline is to package a batch of commands and then send the commands to a server, and the server completes the execution and returns the commands after the commands are packaged in sequence;
converting batches of row and column data into a plurality of HMSET and HDEL commands using REDIS pipeline can be accomplished using the method steps described above. Secondly, changing the batch change data sequence into a JSON format, and notifying other homonymous table objects through a PUBLISH command.
The following describes a specific implementation procedure of an embodiment of the present invention with a specific example:
referring to fig. 2-7, fig. 2 is a block diagram of a two-dimensional table in a specific application scenario according to an embodiment of the present application, fig. 3 is an attribute and a method defined by a cell class of the table of fig. 2 in this example, fig. 4 is an attribute and a method defined by a cell set class of the table of fig. 2 in this example, fig. 5 is an attribute and a method defined by a data line class of the table of fig. 2 in this example, fig. 6 is an attribute and a method defined by a data line set class of the table of fig. 2 in this example, and fig. 7 is an attribute and a method defined by a two-dimensional table class in this example.
The purpose of the embodiment is to realize a thread-safe distributed virtual two-dimensional table based on REDIS, namely, the specific application scenario of the table data automatic synchronization method provided by the embodiment of the invention aims to enable a developer not to learn REDIS related technologies, not to care about data storage details and bottom layer realization, not to define field names and formats for data to be stored in advance, and only to access the REDIS database through row and column operation of the table, thereby solving the problems of high REDIS learning and use cost, no data coupling and difficult understanding, and also needing to optimize the problems of slow batch data processing and higher failure probability when the database is updated in the table synchronization method.
The cells and rows provided in this example describe a two-dimensional tabular model, organizing data in rows and columns, and are logically more convenient for users to understand. The form is internally provided with a plurality of interfaces for users to use by realizing the integral function in cooperation with a plurality of classes. The functions provided by the table include creating the table, designing the table fields and indexes, adding in batches, modifying, deleting, querying row data, obtaining the number of rows and columns of the table, emptying the table, registering change notification callbacks, and the like.
In order to realize the table function, the technical scheme adopted by the embodiment comprises three modules, namely table definition, asynchronous subscription and REDIS operation. The table definition module comprises a cell class, a cell set class, a data row set class and a two-dimensional table class definition. The asynchronous subscription module uses Hiredis and Libevent open source software to connect REDIS server end in an asynchronous mode, executes SUBSCRIBE command to SUBSCRIBE channel data named by table names, starts event threads to asynchronously receive subscription response data, and timely informs outer users. The REDIS operation module comprises REDIS command class, synchronous client class and response analysis class definition, wherein the command class stores all parameters of one REDIS command; the response analysis class is responsible for completing the conversion from REDIS server side response to self-defined response structure; the synchronous client class uses Hiredis to connect with REDIS server in synchronous mode, execute multiple commands in pipeline mode, and return REDIS response parameters.
In this example, a REDIS-based implementation scheme for automatically synchronizing data tables is provided, where the scheme uses the C++ language to design related classes and encapsulates a series of interfaces that are available for external use.
The scheme also comprises design and encapsulation of REDIS command class, REDIS synchronous client class, REDIS response analysis class, REDIS asynchronous subscription class, cell collection class, data row class, row collection class, table class and the like.
The REDIS server is deployed as a master-slave environment in a single-machine mode, and REDIS synchronous client class encapsulates an interface for interaction between a synchronous mode and the REDIS server. The REDIS asynchronous subscription class realizes the connection of the REDIS server in an asynchronous mode, takes the name of the table as a channel name, executes the change notification of the REDIS subscription command subscription table, and notifies the table update data after receiving the change message.
Each row record of the created table may be mapped to a key value pair in the REDIS database whose value type is a hash table. The mapping relationship is explained as follows: assuming that a table instance dt_person storing personal information is named Person, three columns of Name, age, city are defined in the table, and information of two persons a and B, i.e., { a,10, sie }, { B,18, guangzhou }, are stored, the two information will be stored in the hash table of the REDIS database through the REDIS HMSET command. The command corresponding to the user A is: HMSET Person 1Name A Age 10 City Western An. Wherein the number 1 in the key Person 1 represents the row number of the record in the Person table. The mapping mode of the user B is the same as that of the user A.
The invention will be described in detail below with reference to the drawings and the detailed description.
REDIS command class is named REDIS Command, which stores all elements of a REDIS command in a dynamic string array, including command name, key name, and parameters thereof. Redis command uses template function technology to realize the function of converting non-character string types such as numerical value, boolean, etc. into character string types, defines dynamically adding parameters into REDIS command through reload < < and () > operators, and returns the interface of new Redis command instance, through which user can dynamically splice REDIS command parameters in an additional mode.
The REDIS synchronous client class is named as REDISHA, the REDIS server is connected in a synchronous mode, a series of REDIS commands are executed on the REDIS server in a pipeline mode, and the execution result returned by the REDIS server is analyzed.
REDIS response parsing class is responsible for uniformly converting response messages (redisReply) returned by Hiredis open source software into a self-defined response structure. The custom response structure is named Redis Reply and comprises a dynamic array of data types, integer values, string values and Redis Reply types. The data types correspond to 6 return types of character strings, arrays, integer, null, state and failure defined by REDIS protocol. When the response data type is integer, storing the value in an integer value attribute of the Redis reply class; when the response data type is character string, state or failure, storing the value in the character string value attribute of the Redis reply class; when the response data type is an array, the value is stored in the dynamic array attribute of the Redis Reply class, and the value of the array element Redis Reply type is stored according to the rule.
REDIS asynchronous subscription class is named Redis Subscriber, and defined core data members include a Libevent event object, a Hidis asynchronous object, an initialization notification callback, and a message notification callback. The subscription class initialization process needs to be completed as follows: firstly, a REDIS server is connected in an asynchronous mode to acquire a Hiredis asynchronous object, connection and disconnection callbacks are set, a Libevent event object instance is created and bound to the asynchronous object, and REDIS asynchronous callback is associated with an event; secondly, the user needs to register an initialization notification callback and a message notification callback to the subscription class; thirdly, starting independent thread to start event distribution processing; fourthly, the table name is taken as a channel name, the REDIS SUBSCRIBE command SUBSCRIBEs to the change notification of the table, and the command feedback callback is registered. And the command feedback callback is used for differentially processing the SUBSCRIBE command execution result and the subscription message. And after receiving the subscription information, calling the change callback registered by the outer layer user to notify the outer layer of the change data.
The cell class is named Datacell, abbreviated as DC in this document. The cells are basic data units in a two-dimensional table, and have attributes such as cell names (string types), stored values (string types), change flags (boolean types), and tables where the cells are located (weak_ptr types).
The interfaces provided by the cell classes are shown in table 1.
Table 1 cell class interface table
The DCI_3 is a DC class assignment operator reload interface, and the interface resets the internal data of the current object according to the parametering object. For a unique pointer data member within a DC class, i.e., the table to which it belongs, the assignment operation simply resets its value.
DCI_4 is a DC class copy construction function, and the interface directly calls the DCI_3 interface to realize the function.
DCI_8 is an interface for acquiring cell values of the DC class, and the interface uses a function template of C++ language and a reloading technology to realize the conversion of character string values stored in cells into various basic data types, so that a user can acquire values according to actual required types.
DCI_9 is an interface for setting cell values of a DC class, and the interface uses function templates, reloads and character streaming technologies to uniformly convert a plurality of different input parameter types into character string types for storage in order to support a plurality of C++ language basic data types input by a user.
Dci_14 is a comparison function interface of a cell class encapsulation, the function defining two arguments, argument 1 being a string type, for storing relational operators such as: ">", "> =", "<", "<=", |! = "," like "," betwen "," in "; the argument 2 is a string array type for storing relational operator parameters. The method calls a relationship operator interface of the internal reload of the DC class, and compares the relationship between the stored values in the two cells.
The cell collection class is named Datacell collection, abbreviated as DCC in this document. A set of cells consisting of a plurality of cells, the set being logically equivalent to a row or a column; the order and association container used within the DCC class stores a plurality of cell addresses (shared_ptr < DataCell >). The intelligent pointer is used for conveniently managing the dynamic memory and avoiding memory leakage. Storage in a sequential container may facilitate indexing cells with subscripts; the storage in the association container can establish a mapping relation between the column names and the cells, so that the cells can be conveniently searched according to the column names.
The interfaces provided by the cell collection class are shown in table 2.
Table 2 cell set class interface table
The DCCI_3 is a heavy load interface of a DCC class assignment operator, the DCCI_4 is a copy construction function interface of the DCC class, the two interfaces define a copy control mechanism of the DC class, and the class object copy process is required to construct completely independent copies, namely, a deep copy mode is required to be adopted for cell object pointers stored in the class.
Dcci_7 is an interface defined by DCC class that obtains its location index from the cell name. The position index of a cell within a collection is defined as the subscript of the cell object in the sequential container.
The dcci_8 interface detects whether a named cell exists within the set of cells.
Dcci_9 is the first add operation interface defined by DCC class, which mainly implements the function of inserting a specified cell at a specified location of a current object. The default parameter identification is only incremented on the current row. Assuming that the user invokes the dcci_9 interface through the DCC class object C, a DC object address a and an insertion position P are input, and the detailed processing procedure of the dcci_9 interface is as follows:
step 1, judging whether the table of the cell object A to be inserted is the same as the table of the set C to be inserted. If the same, a is considered to be already in C, and the process ends.
And 2, judging whether the insertion position P is out of range. If the boundary is exceeded, the process is terminated.
And 3, assigning the table address of the table associated with the C object to the A object. And acquiring the shared_ptr intelligent pointer of the C object. The dcci_10 interface is invoked.
And step 4, judging whether the C object is associated with the data table. If not, the process is terminated.
And 5, judging whether the data in the C object association data table exists or not. If not, the process is terminated.
And 6, inserting the reference cell object A in the appointed positions of all rows of the C object association table.
Dcci_10 is a second type of add operation interface defined by DCC class, which mainly implements a function of inserting a specified cell at a specified location of a specified cell collection object. The default parameter entering unit lattice, the inserting position and the parameter of the parameter entering unit lattice set of the interface are legal, and the parameter entering unit lattice object is added into the parameter entering unit lattice set by directly calling the insert method of the sequence container and the associated container.
Dcci_11 is a third add operation interface defined by DCC class, which appends cells to the set, i.e., inserts at the end position.
Dcci_12 is a fourth add operation interface defined by DCC class, and a designated name cell is added to the set, and the interface firstly constructs a cell object according to the name of the participating cell, and then invokes dcci_11 interface;
dcci_13 is the first delete operation interface defined by the DCC class that deletes a cell of a specified name in the collection. For example: the user calls the DCCI_13 interface through the DCC class object C, a cell name N is transmitted, the DCCI_13 interface firstly acquires a cell index from the container according to the cell name N, and then calls the DCCI_14 interface;
DCCI 14 is a second delete operation interface defined by DCC class that deletes cells in a set that specify an index. For example: the user calls the DCCI-14 interface through the DCC object C, a cell position index P is transmitted, the DCCI-14 interface judges whether the parameter entering index P is out of range, if so, the processing is terminated; the cell object pointer ObjPtr is obtained from the sequence container according to the index P. And searching the cell object name pointed by the ObjPtr in the association container, and if no corresponding element is found in the association container, deleting the designated index element from the sequence container. If found in the association container, it is also deleted from the association container. If the C object has associated a table, each row of the associated table invokes the DCCI_15 interface.
DCCI 15 is an internal delete operation interface defined by DCC class that deletes cells of a specified index in a specified set.
Dcci_16 is a third delete operation interface defined by DCC class that deletes a cell object in the current set that is named with the entry reference. For example: the user calls the DCCI_16 interface through the DCC class object C, a cell object Obj is transmitted in, the DCCI_16 interface obtains a cell name N through the cell object Obj, and then calls the DCCI_13 interface;
DCCI 17 is a copy interface of DCC class definitions that enables copying of the cell from which the current set designation index begins into the reference designated set. The user calls the DCCI_17 interface through the DCC class object C, and transmits a starting position S and a cell set M, and the DCCI_17 interface firstly checks whether the starting position S is legal in the object C; if not, the process is terminated. Object M loops to call dcci_9 interface to append cell object copies in the C set sequentially at the end.
Dcci_18 is an interface provided by the DCC class to obtain a copy of a cell object based on a cell name.
DCCI 19 is an interface provided by DCC class to obtain a copy of a cell object from a cell index.
The data line class is named DataRow, abbreviated DR in this document. The data line class describes the attributes and methods that a single line should possess. A single row should have at least one set of cells and two attributes of the table.
The interfaces provided by the row classes are shown in table 3.
Table 3 data line class interface table
DRI_2 is a DR class assignment operator reload interface, DRI_3 is a DR class copy constructor interface, the two interfaces define a replication control mechanism of the DR class, and the class object replication process is required to construct completely independent replicas, namely, cell object pointers stored in the class must adopt a deep copy mode.
DRI_5 is the first search cell interface provided by the DR class, which is searched from within the row according to the cell name, and the interface internally calls the DCCI_18 interface of the cell collection class directly.
DRI_6 is a second type of search cell interface provided by the DR class, which is searched from within the row based on cell location, with the interface internal directly invoking the DCCI_19 interface of the cell collection class.
DRI_7 is the interface provided by the DR class to acquire the in-row cell collection object.
DRI_8 is an interface for the DR class to obtain a row number, and each row object in the table has a unique row number in the table, i.e., the row number is equivalent to the table primary key.
DRI_9 is the interface for DR class setup row object identification.
DRI_10 is the interface for DR class to obtain the line primary key value, the primary key of the line object is "Table name: line number".
DRI_11 is the interface provided by the DR class to obtain all field names in the row.
DRI_12 is an interface provided by the DR class to obtain all field names and values in the row, and F1-V1-F2-V2 … are sequentially stored in the returned dynamic array.
The data line collection class is named DataRowCollection, abbreviated DRC in this document. DRC class describes the properties and methods that a plurality of rows should possess. The row set class has a plurality of rows of element sets and a table attribute; a plurality of line object pointers (shared_ptr < DR >) are managed through a doubly linked list container, a line set index table is managed through a secondary hash table, a primary hash table uses column names as keys, a value field is also a hash table, and the secondary hash table uses column unit lattice object storage values as keys, and the value field is a line object pointer.
The interfaces provided by the line set class are shown in table 4.
Table 4 data line set class interface table
/>
The row set class needs to support setting a plurality of index fields simultaneously, and in order to realize the function, the index table adopts a two-stage hash table structure, the primary hash table takes a column name as a key, and the secondary hash table as a value. The secondary hash table uses column values as keys and row class examples to which the column values belong as values. DRCI_7 is an interface for setting an index of the DRC class, and when the index is set by the line set class, if the number of lines of the table to which the DRCI_7 belongs is 0, only the mapping relation between the column names and the empty secondary hash table is required to be added into the primary hash table. If the table row is not 0, a secondary hash table is also constructed according to each row of data in the table.
Drci_9 is an interface provided by the DRC class to add a single row. And adding a new row in the row set, and if the table is provided with an index, synchronously updating the index table. The specific treatment process comprises the following steps: traversing an index table, and acquiring a cell object corresponding to an index column name from the row object to be added; acquiring a storage value from the cell object, and searching whether the storage value exists in an index list value corresponding to the current list name; if the new line exists, namely the index field value conflicts, the new line addition fails. If the new column value does not exist, the corresponding relation between the new column value and the new row is inserted into the index table corresponding to the current column name. And finally, inserting a new row into the row set container.
Drci_10 is the first interface provided by the DRC class to delete a single line. When deleting a row object from the row set, if the table has an index set, the index table also needs to be updated. The specific treatment process comprises the following steps: checking whether an index column exists in the row object to be deleted; if the mapping relation exists, deleting the mapping relation between the corresponding column value and the row object from the index table; if not, searching the appointed row object from the row set container and deleting the appointed row object;
the drci_11 is a row interface provided by the row set class that deletes rows according to index field names and values.
DRCI_12 is a row set class that provides a way to retrieve rows according to location. The detailed processing process is as follows: checking whether the index of the incoming position crosses the boundary, if so, terminating the processing; otherwise, the incoming position index is corresponding to the relative position of the row object in the row set list, and the row object at the specified position is returned.
The drci_13 is an interface provided by the row set class to acquire row objects from row identifications.
The drci_14 is an interface provided by the row set class to obtain row objects from index field names and values.
DRCI_15 is an interface for updating row data provided by the row-set class.
DRCI_16 is an interface provided by the row set class to find rows that meet a user specified set of conditions.
Drci_17 is an interface for row-by-row traversal provided by the row-set class.
DRCI_18 is a row presence interface provided by the row set class that determines the presence of a row based on the row identification.
The table class describes a two-dimensional table model comprising rows and columns for temporarily storing virtual table data in memory, where the rows and columns are each defined as a set of cells. A two-dimensional table is made up of multiple rows and columns. The rows are represented by a row set, which contains a plurality of row instances, each row instance contains a cell set instance, one cell set instance contains a plurality of cell instances, and each cell instance stores a valid name and value. The columns are represented by a set of cells, the set of column cells containing a plurality of cell instances, each cell instance having a valid name and not storing a meaningful value. The table also has attributes such as name, number, subscription sub-object, and REDIS client terminal object.
The table class is named DataTable, abbreviated as DT in this document, and can be created and used independently. The interfaces provided by the table classes are shown in table 5.
Table 5 table class interface table
/>
/>
Dti_3 is a static method provided by the DT class to create a table instance, the internal process flow of which is shown on the right side of fig. 7. The user transmits parameters such as REDIS server IP, port, password, form name, database index and subscription flag to the interface. The REDIS server IP is an IP address for deploying REDIS service, the port is a REDIS service monitoring port, and the password is an authentication password when the REDIS client is connected with the REDIS server. The subscription flag indicates whether to turn on the subscription form data change function, and is turned on when the value is true, and turned off when the value is false. If the caller does not transmit the database index and the subscription flag parameter to the interface, the interface uses a default value, wherein the database index default value is 0, namely, default table data is stored in a No. 0 database of the REDIS server; the subscription flag default value is true, i.e., the form instance defaults to turn on the subscription data change function.
The static method first dynamically builds a table instance on the heap, storing the instance address in the intelligent pointer. After the table is instantiated, the internal data including row set, column set, REDIS client instance and subscription instance are initialized. The initially created table has no structure, i.e. no column names are set, nor are any row data stored. Therefore, initializing a row set requires dynamic creation of a null DRC instance, initializing a column name set requires dynamic creation of a null DCC instance. In order that the form instance can be used as a bridge between a user and the REDIS database, the REDIS client terminal object needs to be initialized when the form is initially created, so that the connection establishment between the REDIS client terminal object and the REDIS server terminal is ensured to be normal. In order to timely sense the change of the table data, after the table instance is created, a subscription sub-object is initialized, so that the asynchronous connection between the subscription sub-object and REDIS server is ensured to be established normally, simultaneously, a REDIS SUBSCRIBE command is successfully executed, an asynchronous event processing thread is started normally, and all messages on a channel named by the table name are subscribed. After the table object is successfully created and all initializations are completed, the static method returns the table instance address to the user. The user can obtain the table instance address, i.e., a shared_ptr < DT > type variable. Examples of static method calls are as follows:
shared_ptr<DT>PTR=DT::CreateDataTable(“192.168.1.1”,6973,“123456”,“TestTbl”,true,1);
Dti_5 is the interface for the DT class set table column field name. After the user obtains the table instance address, if a brand new data table is required to be designed, the column name of the data stored in the interface setting table can be called through the table instance address according to the application scene. For example, set 3 column names as F1, F2, and F3, respectively, then call is performed: vector < string > heads= { "F1", "F2", "F3" }; PTR- > SetHead (heads); the interface traverses the input column name array, sequentially takes out each element, calls the input parameters of the DCC class DCCI_12 interface as a table column cell set object, and circularly increases the cells with specified names.
Dti_6 is the interface for the DT class to set the table index field, the index is an optional setting item, allowing the table to be index-free. The user can create the index for the table instance at any time according to the service requirement, allow the index to be created on a plurality of columns, allow the index to be set for a plurality of times, and can select two modes of resetting or adding when setting. The index information before the resetting mode is emptied, and an index table is built again according to the table data; the additional mode can keep the original index information and supplement the index table data according to the newly set index column. Although one table is allowed to set a plurality of index columns, search is allowed only on one column, and multi-column combined search is not supported. The interface of the table class setting index directly calls the line set class setting index interface.
Dti_8 is the DT class setting table name interface.
Dti_9 is the DT class get table name interface. The table name is case-wise and the default value is null.
Dti_10 is the DT class get table number interface. The table number is obtained by adding the static variable of the table class, and the table number is unique in a single process and can be the same among multiple processes.
Dti_11 is the DT class load table full data interface. If the user does not need to set a new table, and only needs to load the existing table data from the REDIS database, the dti_11 interface of the table class is called through the table instance address, and an example is called: auto ret = PTR- > LoadData (); the method for loading table data first needs to execute the REDIS SCAN command through REDIS client terminal object of table class to obtain all keys related to table instance. Assuming that the table name is TestTbl, the TestTbl table data in the REDIS in-memory database is stored in a plurality of hash tables with keys TestTbl: N, where N represents a unique row number in the data table, and the meaning of the unique row number is equivalent to the primary key of the data table, so that a row of data can be uniquely determined. Therefore, the SCAN command to be executed is SCANcursor MATCH TableName, the initial value of cursor is 0, and each time the command is executed, the cursor searched for next time and the current search result satisfying the matching mode will be returned. When the return cursor is 0, this indicates that the SCAN command completes one complete traversal. All KEYS retrieved during the SCAN traversal are saved to the container, assuming tbl_keys. If the container is not empty, the first element is fetched, assuming TestTbl 1, and executing the REDIS HKEYS command obtains all field names in the TestTbl 1 key, i.e., column names of the table TestTbl. The dti_8 interface is called to set the table column name. And circularly traversing each key element in the TBL_KEYS, completing the conversion operation from the key value to the row object, and finally calling a table class batch addition data row interface to add all rows created according to the TBL_KEYS into the table. Since the data is already loaded from the REDIS database, the batch addition operation here does not need to synchronize the REDIS database. The data loading method returns the number of rows and columns successfully loaded to the caller.
The conversion operation from REDIS key to row object firstly executes REDIS HGETALL command to obtain all fields and values in key, analyzes row number RID from key value of "table name: row number" format, creates a new row object whose row number RID is identical with cell name in row and table column cell, and fills all fields and values in key into cells in new row object.
Dti_12 is the DT class get table rank interface.
Dti_13 is a DT class empty table row data interface.
Dti_15 is the DT class get table new line number interface. Each table specifies a globally unique row number identifier name. For example, a table instance may be named tableNameA and a row number identifier of the table may be defined as tableNameA_SEQ. The method of generating the new line number requires that the line number identifier name is first entered, and then the INCR command of REDIS is executed to add 1 to the KEY as the value stored in TableNameA_SEQ. The REDIS mechanism ensures that if the specified KEY does not exist in the REDIS database, the value of the specified KEY is initialized to 0, the INCR operation is performed, the KEY is stored in the REDIS database, and the result after the INCR operation is performed is returned to the client. The REDIS single-wire Cheng Chuanhang processing mechanism ensures that no data race problem occurs when new row numbers of the same table are concurrently generated in a multi-threaded environment.
Dti_16 is the DT class create table new row object interface. The new line object creating method includes creating one empty new line object dynamically on the pile, copying list cell set of the new line object to the new line object, setting the data table associated with the new line object as the current line object, and returning the new line object address to the user for setting line data.
Dti_17 is the DT class batch add-on interface.
Dti_18 is the DT class bulk delete line interface.
Dti_19 is the DT class batch modify line interface. Batch operations are executed in a transactional manner, with success being all successful and failure being all failed. When the batch is added, deleted or modified, the table data is firstly locked, then the data backup is carried out, and the backup is used for backing up the table data when part of the row operation fails. And after the backup is finished, calling the addition, deletion or modification of the row set class definition to circularly process the incoming rows of the single row interface. After all the rows are successfully processed, the table data is unlocked first, and then whether REDIS databases are synchronously updated is selected according to service requirements.
In this embodiment, the REDIS database updating method needs to be transmitted with batch line data to be updated and operation identifiers, and the operation identifiers can be set to be added, deleted or modified. According to the method, each line of data is firstly analyzed into a subscription and release data structure, and then the subscription and release structure is converted into REDIS commands according to operation identifiers. If the operation is identified as an add or modify, the data is converted to REDIS's HMSET KEY F V1[ F2V 2 … ] command. If the operation is identified as delete, the data is converted to REDIS's HDEL KEY F1[ F2 … ] command. The KEY in the command is "table name: row number", and Fn and Vn correspond to the name and value of each cell in the row. All lines to be operated are converted into REDIS commands according to rules, then the whole publishing and subscribing structure is serialized, and a PUBLISH CHANNEL MESSAGE command is added to a REDIS command set to be executed, wherein CHANNEL is a table name, and MESSAGE is serialized publishing and subscribing data. Executing all REDIS commands in a channel mode, analyzing the execution result, and returning success or failure to the caller according to the command execution result.
The publish-subscribe data structure is defined as a composite type that includes an operation identifier, a database index, a table name, a table number, and change line data. The row data comprises a row number and a row attribute set; the line attribute data includes an attribute name and an attribute value. The table instance of the publish-subscribe composite structure is serialized into a JSON string, and the table instance of the subscribe-change notification is inversely serialized into a composite structure.
The REDIS database updating method provided by the embodiment has the technical effects that: first, batch of row and column data is converted into multiple HMSET and HDEL commands using pipeline (pipeline mechanism) of REDIS. Secondly, changing the batch change data sequence into a JSON format, and notifying other homonymous table objects through a PUBLISH command.
Dti_20 is the DT class data polling interface. The row query method allows a user to input a custom query function object, custom row query conditions are defined in the function object, and a query function object interface is defined as a bool (DR &). The line inquiry method circularly traverses all lines in the table, takes each line as an input parameter of an inquiry function object, executes an inquiry function and judges whether the input line meets the inquiry condition according to the return value. If so, a copy of the incoming row is placed into the query result set. And finally, returning the query result set to the caller.
Dti_21 is the DT class batch add-on interface.
Dti_22 is the DT class bulk delete column interface. And circularly calling interfaces of the cells in the cell set in the batch adding or deleting method of the table, wherein the list cell set of the table stores the table address, and if the rows exist in the table when the cells are added or deleted, the cells are added or deleted in the cell set corresponding to each row.
Dti_23 is a row-by-row traversal interface provided by the DT class.
Dti_24 is the DT class registration line add notification callback interface.
Dti_25 is the DT class registration line delete notification callback interface.
Dti_26 is the DT class registration line modification notification callback interface. In order to realize the automatic synchronization function of the form data, the form needs to realize a data change callback method. When the asynchronous event processing thread subscribing the sub-objects in the form receives the change message, the data change callback registered by the form class is called. The change callback of the form class can synchronously update the self memory data according to the operation identification in the subscription message body. The user can selectively register the callback interface of the table data to add, modify or delete the change callback interface, and when the table updates the object memory data due to receiving the subscription change message, the callback interface registered by the user is called, and the user can customize the processing logic of the change data in the callback interface.
Dti_27 is a DT class registration subscription notification callback interface. The table class is an upper layer user of the subscription class, and has to register a subscription notification callback with the subscription class in order to receive the table data change notification message in time. After receiving the data change notification, the form class firstly deserializes the received JSON character string into a composite structure, and then performs addition, deletion or modification processing according to the operation identifier. When the number of the line in the change data is increased, the existence of the line number in the table instance memory is checked, and if the line number does not exist, the change data is increased. Otherwise, the processing is ignored. When modifying and deleting, if the line number exists in the table instance memory, updating or deleting the corresponding line data, otherwise, ignoring the processing. The form data change which is passively received and triggered is not synchronized to the REDIS database, and the form instance which actively issues the change completes the REDIS database data change.
Dti_28 is a DT class check form presence interface. The user can check the REDIS database for the presence of any form data by way of the form instance. For example, PTR- > TableExist ("Testcheck") may be performed by the TestTbl table instance detecting whether a Testcheck table already exists; if the entry table name is not specified, the existence of the table instance itself is checked by default, i.e., PTR- > TableExist () is equivalent to PTR- > TableExist ("TestTbl").
Dti_29 is the DT class interfaces to the search line according to the index field name value pair. The use of an index table search row allows searching on only one column, and does not support multi-column combined searching.
Fig. 8 is a schematic block diagram of a REDIS database updating apparatus according to an embodiment of the present invention. As shown in fig. 8, the present invention also provides a REDIS database updating apparatus corresponding to the REDIS database updating method above. The REDIS database updating apparatus includes a unit for performing the REDIS database updating method described above, and the apparatus may be configured in a desktop computer, a tablet computer, a laptop computer, or the like. Specifically, referring to fig. 8, the REDIS database updating apparatus 200 includes:
a data acquisition unit 201, configured to acquire batch line data and an operation identifier to be updated;
a data command unit 202, configured to parse the batch of line data to generate a data interaction structure, and convert the data interaction structure into a REDIS command according to the operation identifier;
a change issuing command unit 203 for designating a channel transmission command to the additional information in the set of REDIS commands;
and a result obtaining unit 204, configured to execute the REDIS command in a channel manner, and return execution success or failure according to an execution result.
It should be noted that, as will be clearly understood by those skilled in the art, the specific implementation process of each subunit of the REDIS database updating apparatus 200 may refer to the corresponding description in the foregoing method embodiment, and for convenience and brevity of description, the description is omitted here.
The REDIS database updating apparatus 200 described above is now in the form of a computer program which can be run on a computer device as shown in fig. 9.
With reference to FIG. 9, the computer device 300 includes a processor 302, a memory, and a network interface 305, which are connected by a system bus 301, wherein the memory may include a non-volatile storage medium 303 and an internal memory 304.
The non-volatile storage medium 303 may store an operating system 3031 and a computer program 3032. The computer program 3032 includes program instructions that, when executed, cause the processor 302 to perform a REDIS database update method.
The processor 302 is used to provide computing and control capabilities to support the operation of the overall computer device 300.
The internal memory 304 provides an environment for the execution of a computer program 3032 in the non-volatile storage medium 303, which computer program 3032, when executed by the processor 302, causes the processor 302 to perform a REDIS database update method.
The network interface 305 is used for network communication with other devices. It will be appreciated by those skilled in the art that the structure shown in fig. 9 is merely a block diagram of a portion of the structure associated with the present application and does not constitute a limitation of the computer device 300 to which the present application is applied, and that a particular computer device 300 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
The storage medium may be a U-disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk, or other various computer-readable storage media that can store program codes.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps described in connection with the embodiments disclosed herein may be embodied in electronic hardware, in computer software, or in a combination of the two, and that the elements and steps of the examples have been generally described in terms of function in the foregoing description to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the several embodiments provided by the present invention, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the device embodiments described above are merely illustrative. For example, the division of each unit is only one logic function division, and there may be another division manner in actual implementation. For example, multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed.
The steps in the method of the embodiment of the invention can be sequentially adjusted, combined and deleted according to actual needs. The units in the device of the embodiment of the invention can be combined, divided and deleted according to actual needs. In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The integrated unit may be stored in a storage medium if implemented in the form of a software functional unit and sold or used as a stand-alone product. Based on such understanding, the technical solution of the present invention is essentially or a part contributing to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a terminal, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention.
While the invention has been described with reference to certain preferred embodiments, it will be understood by those skilled in the art that various changes and substitutions of equivalents may be made and equivalents will be apparent to those skilled in the art without departing from the scope of the invention. Therefore, the protection scope of the invention is subject to the protection scope of the claims.
Claims (6)
1. A method for updating a REDIS database, comprising the steps of:
acquiring batch line data to be updated and an operation identifier; the row data comprises a row number and a row attribute set;
analyzing the batch line data to generate a data interaction structure, and converting the data interaction structure into REDIS commands according to the operation identifiers;
adding information-designating channel transmission commands to the REDIS command set;
executing the REDIS command in a channel mode, and returning execution success or failure according to an execution result;
the operation identifier comprises an identifier for adding, deleting or modifying; when the operation is identified as adding or modifying, the corresponding REDIS command is a REDIS Hmset command; when the operation identifier is deleted, the REDIS command is a REdis Hdel command;
The method also includes a static method of creating a table instance, comprising: dynamically constructing a table instance on the heap, and storing an instance address in the intelligent pointer;
dynamically creating a null DRC instance to initialize the row set, and dynamically creating a null DRC instance to initialize the column set;
initializing REDIS client terminal objects when a table is initially created;
initializing a subscription sub-object after the table instance is created;
executing REDIS SUBSCRIBE command, starting asynchronous event processing thread, and starting subscribing all messages on the channel named by the form name;
after the table object is successfully created and all the initializations are completed, the table instance address is returned to the user, and the user can obtain the table instance address;
calling an interface through the form instance address;
serializing the data interaction structure into a JSON character string, after receiving a data change notification, inversely serializing the received JSON character string into a composite structure, and then carrying out addition, deletion or modification treatment according to the operation identifier; when the operation mark is increased, checking the existence of a line number in the change data in the table instance memory, if the line number does not exist, increasing the change data, otherwise, ignoring the change data; when the operation identification is modification and deletion, if the line number exists in the table instance memory, the corresponding line data is updated or deleted.
2. The REDIS database updating method according to claim 1, wherein the step of converting the data interaction structure into REDIS commands according to the operation identification includes a command to operate on all lines to be operated.
3. The REDIS database updating method according to claim 1, wherein the step of adding the information-designating channel transmission command to the set of REDIS commands includes acquiring a table name and a serialized data interaction structure, and transmitting information to the designated channel.
4. A REDIS database updating apparatus, comprising the following elements:
the data acquisition unit is used for acquiring batch line data to be updated and operation identifiers; the row data comprises a row number and a row attribute set;
the data command unit is used for analyzing the batch data to generate a data interaction structure, and converting the data interaction structure into REDIS commands according to the operation identification;
a change issuing command unit configured to assign a channel transmission command to the set of REDIS commands by adding information;
the result acquisition unit is used for executing the REDIS command in a channel mode and returning execution success or failure according to an execution result;
The operation identifier comprises an identifier for adding, deleting or modifying; when the operation is identified as adding or modifying, the corresponding REDIS command is a REDIS Hmset command; when the operation identifier is deleted, the REDIS command is a REdis Hdel command;
further comprises: dynamically constructing a table instance on the heap, and storing an instance address in the intelligent pointer;
dynamically creating a null DRC instance to initialize the row set, and dynamically creating a null DRC instance to initialize the column set;
initializing REDIS client terminal objects when a table is initially created;
initializing a subscription sub-object after the table instance is created;
executing REDIS SUBSCRIBE command, starting asynchronous event processing thread, and starting subscribing all messages on the channel named by the form name;
after the table object is successfully created and all the initializations are completed, the table instance address is returned to the user, and the user can obtain the table instance address;
calling an interface through the form instance address;
serializing the data interaction structure into a JSON character string, after receiving a data change notification, inversely serializing the received JSON character string into a composite structure, and then carrying out addition, deletion or modification treatment according to the operation identifier; when the operation mark is increased, checking the existence of a line number in the change data in the table instance memory, if the line number does not exist, increasing the change data, otherwise, ignoring the change data; when the operation identification is modification and deletion, if the line number exists in the table instance memory, the corresponding line data is updated or deleted.
5. A computer device comprising a memory, a processor and a dis database update program stored on the memory and executable on the processor, wherein the dis database update program when executed by the processor implements the dis database update method as claimed in any one of claims 1-3.
6. A non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the REDIS database updating method as claimed in any one of claims 1 to 3.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010861934.XA CN111984663B (en) | 2020-08-21 | 2020-08-21 | REDIS database updating method, REDIS database updating device, REDIS database updating computer equipment and REDIS database storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010861934.XA CN111984663B (en) | 2020-08-21 | 2020-08-21 | REDIS database updating method, REDIS database updating device, REDIS database updating computer equipment and REDIS database storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111984663A CN111984663A (en) | 2020-11-24 |
CN111984663B true CN111984663B (en) | 2024-03-12 |
Family
ID=73443133
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010861934.XA Active CN111984663B (en) | 2020-08-21 | 2020-08-21 | REDIS database updating method, REDIS database updating device, REDIS database updating computer equipment and REDIS database storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111984663B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112925848B (en) * | 2021-02-23 | 2024-02-06 | 马上消费金融股份有限公司 | Data synchronization method, device, equipment and readable storage medium |
CN115190139A (en) * | 2022-03-28 | 2022-10-14 | 北京慧能分享科技有限公司 | Multi-protocol-based load balancing energy big data acquisition system and method |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105630913A (en) * | 2015-12-22 | 2016-06-01 | 福建星海通信科技有限公司 | Redis pipeline communication-based message passing method and system |
CN106294769A (en) * | 2016-08-11 | 2017-01-04 | 珠海格力电器股份有限公司 | Method, system and device for synchronizing engineering data |
CN108418874A (en) * | 2018-02-12 | 2018-08-17 | 平安科技(深圳)有限公司 | Guiding method, device, computer equipment and storage medium are returned across wide area network data |
CN109800239A (en) * | 2019-01-15 | 2019-05-24 | 科大国创软件股份有限公司 | Distributed structure/architecture data sharing method based on Redis |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106682004A (en) * | 2015-11-06 | 2017-05-17 | 网宿科技股份有限公司 | Redis Key management method and system |
-
2020
- 2020-08-21 CN CN202010861934.XA patent/CN111984663B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105630913A (en) * | 2015-12-22 | 2016-06-01 | 福建星海通信科技有限公司 | Redis pipeline communication-based message passing method and system |
CN106294769A (en) * | 2016-08-11 | 2017-01-04 | 珠海格力电器股份有限公司 | Method, system and device for synchronizing engineering data |
CN108418874A (en) * | 2018-02-12 | 2018-08-17 | 平安科技(深圳)有限公司 | Guiding method, device, computer equipment and storage medium are returned across wide area network data |
CN109800239A (en) * | 2019-01-15 | 2019-05-24 | 科大国创软件股份有限公司 | Distributed structure/architecture data sharing method based on Redis |
Also Published As
Publication number | Publication date |
---|---|
CN111984663A (en) | 2020-11-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111966690B (en) | Method, device, computer equipment and storage medium for loading form full data | |
CN111966756B (en) | Automatic form data synchronization method, device, computer equipment and storage medium | |
US6947950B2 (en) | Techniques for managing multiple hierarchies of data from a single interface | |
US7533136B2 (en) | Efficient implementation of multiple work areas in a file system like repository that supports file versioning | |
US7680764B2 (en) | Parallel population of an XML index | |
US10296524B1 (en) | Data virtualization using leveraged semantic knowledge in a knowledge graph | |
US20080281846A1 (en) | High performant row-level data manipulation using a data layer interface | |
US20060200486A1 (en) | System and method for supporting non-native data types in a database API | |
WO2009043033A4 (en) | Network operating system | |
CN111984663B (en) | REDIS database updating method, REDIS database updating device, REDIS database updating computer equipment and REDIS database storage medium | |
KR20060048418A (en) | System and method for delayed fetching of designated members of a user defined type | |
US20030135503A1 (en) | Determining object graph and object graph projection | |
EP3599555A1 (en) | Data virtualization using leveraged semantic knowledge in a knowledge graph | |
CN110990425B (en) | JDBC driving method and device of hardware database | |
Tauro et al. | A comparative analysis of different nosql databases on data model, query model and replication model | |
WO2019015364A1 (en) | Method and device for executing structured query language (sql) instruction | |
US7958154B2 (en) | Apparatus, system, and method for command manager support for pluggable data formats | |
CN112035572B (en) | Static method, device, computer equipment and storage medium for creating form instance | |
CN106874429B (en) | Method for converting standard SQL into full text retrieval standard query | |
KR102438812B1 (en) | Method and apparatus for managing knowledge base, device and medium | |
US6725213B1 (en) | Method and mechanism for providing external procedures to a database system | |
CN112000739B (en) | Cell designated insertion method, device, computer equipment and storage medium | |
US11222003B1 (en) | Executing transactions for a hierarchy of data objects stored in a non-transactional data store | |
CN112347794B (en) | Data translation method, device, equipment and computer storage medium | |
EP3091447B1 (en) | Method for modifying root nodes and modifying apparatus |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |