Server data pushing method and device and storage medium
By setting up push caching and exception caching queues in the server's memory, the problems of interface lag and data corruption during high-concurrency data push on the server were solved, achieving efficient and orderly data push and improving the operational efficiency of merchant devices.
Patent Information
- Application Number
- CN202211649952.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-21
- Publication Date
- 2025-12-23
- Estimated Expiration
- 2042-12-21
AI Technical Summary
In existing technologies, when servers push data with high concurrency, frequent database reads and writes can cause issues such as interface lag, data retransmission, missing data, or reversed data order, affecting merchant operations.
A push cache queue and an exception cache queue are preset in the server memory. Data is pushed through the push cache queue, and data that fails to be pushed is pushed into the exception cache queue for re-push. The version update file ensures that the data is pushed to the user terminal in an orderly and complete manner.
This reduces the frequency of database read and write operations, improves data push efficiency, ensures orderly data push, avoids data reception errors on merchant devices, and enhances server performance and operational efficiency.
Smart Images

Figure CN115866036B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a server data pushing method and device for pushing data to a user terminal and a storage medium. BACKGROUND
[0002] In the prior art, in order to improve the quality and efficiency of operation services, merchants usually choose a third-party server to provide professional operation management and services. The server pushes operation data to the merchant's device (i.e. the user terminal) in real time according to the operation needs of the merchant, for example, the server provides the merchant with services such as cash register management, place clock management (which can be applied to leisure and health care places and other places with technician clock service), device function configuration, etc. In many cases, the server is based on an Android operating system, and the hardware resources of the server are limited and cannot be expanded, so there are certain limitations in performance. In many cases, the server is required to push operation data to the merchant's device in real time, especially in the case of high concurrency of the server pushing data, the existing data pushing mechanism of the server will have the following problems:
[0003] 1. Frequent reading and writing of the database, resulting in lag in interface operation of the merchant's device, and even access timeout;
[0004] 2. In the case of server data concurrency, there are data retransmission, missing or sequence reversal, resulting in disorder of the data received by the merchant's device. Taking a clock order as an example, in normal circumstances, the merchant's device first performs the clock operation and then performs the clock-off operation. If the server loses, retransmits or reverses the sequence of the data during pushing, the merchant's device will first receive the clock-off data, resulting in that the merchant's device only has the clock-on time but no clock-off time when querying the order, and further affecting the operation of the merchant. SUMMARY
[0005] In view of the above problems, the present application provides a server data pushing method to solve the above problems of the server data pushing.
[0006] To achieve the above purpose, the inventors provide a server data pushing method for pushing data to a user terminal, the method comprising the following steps:
[0007] Pre-setting two or more pushing cache queues and an exception cache queue in the memory of the server;
[0008] Writing the data to be pushed generated by the server into the corresponding pushing cache queue;
[0009] Polling the pushing cache queue, taking data from the pushing cache queue and pushing it to the user terminal, and adding data that fails to push to the exception cache queue;
[0010] taking out data from the abnormal cache queue and pushing to the user terminal.
[0011] In some technical solutions, the push cache queue and the abnormal cache queue are concurrent queues supporting data joining and taking out at the same time.
[0012] In some technical solutions, the data includes a business ID and a version number, and the data is written into a database of the server, and an upload flag bit of the data is set in the database, and the method further includes the steps of:
[0013] preparing a version update file in the server, and adding the business ID and the version number of the data that has been successfully pushed into the version update file;
[0014] updating the upload flag bit of the corresponding data in the database using the version update file.
[0015] In some technical solutions, the step of updating the upload flag bit of the corresponding data in the database using the version update file includes the steps of:
[0016] determining whether the version number of the data in the version update file is equal to the version number of the corresponding data in the database; if yes, updating the upload flag bit of the corresponding data in the database to uploaded, and clearing the business ID and the version number corresponding to the last uploaded data in the version update file; and if no, not updating the upload flag bit.
[0017] In some technical solutions, the method further includes the steps of:
[0018] comparing the version update file and the database when the server is initialized or restarted, adding the data with the upload flag bit not uploaded or the data version number higher than that of the version update file in the database into the push cache queue, and making the data be pushed to the user terminal again.
[0019] In some technical solutions, the step of taking out data from the abnormal cache queue and pushing to the user terminal includes the steps of:
[0020] taking out data from the abnormal cache queue and pushing to the user terminal, and determining whether the abnormal cache queue is empty; if no, taking out the next data and pushing to the user terminal.
[0021] In some technical solutions, the server is an Android system server, and the data is business data of a merchant.
[0022] To solve the above technical problems, the application further provides another technical solution:
[0023] A server data pushing device for pushing data to a user end, comprising:
[0024] a queue module for presetting more than one pushing cache queue and more than one exception cache queue in the memory of the server;
[0025] a writing module for writing data to be pushed generated by the server into the corresponding pushing cache queue; and
[0026] a pushing module for polling the pushing cache queue, taking data from the pushing cache queue and pushing to the user end, and adding data failed in pushing into the exception cache queue; taking data from the exception cache queue and pushing to the user end.
[0027] In some technical solutions, further comprising:
[0028] a version updating module for presetting a version updating file in the server, adding the business ID and version number of data successfully pushed into the version updating file, and updating the upload flag bit of the corresponding data in the database using the version updating file.
[0029] To solve the above technical problems, the present application further provides another technical solution:
[0030] A computer readable storage medium having a computer program stored thereon, the program being executed by a processor to implement the server data pushing method according to any one of the above technical solutions.
[0031] Different from the prior art, the server data pushing method according to the above technical solution presets a pushing cache queue and an exception cache queue in the memory, pushes data through the pushing cache queue, and pushes data failed in pushing again through the exception cache queue, so that the read-write frequency of the database can be reduced, the performance requirement of the server can be lowered, and the data can be ensured to be pushed to the user end in order, avoiding data loss or user end data receiving error caused by data covering.
[0032] The above invention content is only a summary of the technical solutions of the present application, in order to enable those skilled in the art to more clearly understand the technical solutions of the present application, and then can be implemented according to the content of the description and the drawings, and in order to let the above purpose and other purposes, characteristics and advantages of the present application can be more easily understood, the following is described in combination with the specific embodiments of the present application and the drawings. BRIEF DESCRIPTION OF DRAWINGS
[0033] The drawings are only used to show the principles, implementation ways, applications, characteristics and effects of the specific embodiments of the present application and other related contents, and cannot be considered as the limitation of the present application.
[0034] In the drawings:
[0035] Figure 1 Flow chart of the server data pushing method according to the embodiments;
[0036] Figure 2 Flow chart of the data version control according to the embodiments;
[0037] Figure 3 Flow chart of the data pushing when the server starts up or abnormally restarts according to the embodiments;
[0038] Figure 4 Flow chart of the server data pushing according to the embodiments;
[0039] Figure 5 Flow chart of the server abnormal condition data recovery pushing according to the embodiments;
[0040] Figure 6 Block diagram of the server data pushing device according to the embodiments;
[0041] Figure 7 Schematic diagram of the computer readable storage medium according to the embodiments;
[0042] The reference signs involved in the above drawings are explained as follows:
[0043] 600, server data pushing device;
[0044] 601, queue module; 602, writing module; 603, pushing module;
[0045] 700, computer readable storage medium; EMBODIMENTS
[0046] To make the possible application scenarios, technical principles, specific schemes that can be implemented, purposes and effects achieved, etc. of the present application clear, the following will be described in detail in combination with the specific embodiments listed and the drawings. The embodiments described in the present document are only used to more clearly illustrate the technical schemes of the present application, and therefore cannot limit the protection scope of the present application.
[0047] In the present document, the term “embodiment” means that the specific features, structures or characteristics described in combination with the embodiments can be included in at least one embodiment of the present application. The term “embodiment” appearing at various positions in the specification does not necessarily refer to the same embodiment, and does not particularly limit the independence or association between the other embodiments. In principle, in the present application, as long as there is no technical contradiction or conflict, each technical feature mentioned in each embodiment can be combined in any way to form a corresponding implementable technical scheme.
[0048] Unless otherwise defined, the meanings of technical terms used in the present application are the same as commonly understood by one of ordinary skill in the art to which the present application belongs; the use of related terms herein is only for the purpose of describing specific embodiments of the present application, and is not intended to limit the present application.
[0049] In the description of the present application, the phrase "and / or" is a description of the logical relationship between objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases: A exists, B exists, and A and B exist at the same time. In addition, the character " / " herein generally represents that the associated objects before and after are a "or" logical relationship.
[0050] In the present application, terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual quantity, primary and secondary, or order relationship between the entities or operations.
[0051] In the present application, without more limitation, the "includes", "contains", "has" or other similar open expressions used in the sentence are intended to cover non-exclusive inclusion, and these expressions do not exclude the presence of other elements in the process, method or product including the described elements, so that the process, method or product including a series of elements can not only include those limited elements, but also include other elements not explicitly listed, or also include elements inherent to such process, method or product.
[0052] As the same as the understanding in the "Guidelines for Examination", in the present application, the expressions such as "greater than", "less than", "exceed" are understood as not including the number; the expressions such as "above", "below", "within" are understood as including the number. In addition, in the description of the embodiments of the present application, the meaning of "multiple" is more than two (including two), and similar expressions related to "multiple" are also understood in this way, for example, "multiple groups", "multiple times" and the like, unless otherwise explicitly limited.
[0053] Please refer to Figures 1 to 7 The present embodiment provides a server data pushing method and device and storage medium. The server data pushing method, device and storage medium can be applied to a server which needs to push data to multiple user terminals. The user terminal can be a management device of a digital entertainment place such as a KTV, a bar or a massage place. The data pushed by the server can be cash register data, place business data and management and control data of the place equipment of the digital entertainment place (referred to as place).
[0054] As Figure 1As shown, a flowchart of a service end data pushing method. The service end data pushing method is used to push data to a user end, and the method comprises the following steps:
[0055] S101, presetting one or more push cache queues and one or more exception cache queues in a memory of a service end;
[0056] S102, writing data to be pushed generated by the service end into the corresponding push cache queue;
[0057] S103, polling the push cache queue, taking data from the push cache queue and pushing it to the user end, and adding data that fails to be pushed to the exception cache queue;
[0058] S104, taking data from the exception cache queue and pushing it to the user end.
[0059] The service end can use an Android system, or an IOS system or a Windows system. The push cache queue and the exception cache queue both have a first-in first-out feature, that is, data enters from one end of the push cache queue and the exception cache queue and is read from the other end of the queue, so the data that enters the queue first will be read out first. The number of the push cache queue and the exception cache queue can be determined according to the number of types of data to be pushed. The data can be provided with a business ID, and different business IDs represent different types of data.
[0060] In some embodiments, a plurality of push cache queues and a plurality of exception cache queues can also be set, that is, one push cache queue and one exception cache queue can be preset for each type of data. In other embodiments, one push cache queue and one exception cache queue can also be shared by two or more types of data.
[0061] In step S102, the data generated by the service end is data to be pushed, which is business data generated by the service end. Taking the service end pushing data of a massage place as an example, the business data generated by the service end includes business data such as clock-in data, order data, and checkout data of the massage place. The service end writes the data into the corresponding push cache queue for data pushing by the push cache queue. In step S103, data is pushed by polling each push cache queue, and it is determined whether the data pushing of each push cache queue is successful. If the data pushing fails, the data that fails to be pushed is added to the exception cache queue, and in step S104, the data that fails to be pushed is pushed again by the exception cache queue.
[0062] In the whole data pushing process of the embodiment, the data generated by the server is handed over to the pushing cache queue and the exception cache queue in the memory for pushing, so that the database does not need to be frequently accessed, the data pushing efficiency is improved, and the performance requirement for the server is greatly reduced. In addition, the queue has the first-in first-out feature, so that the data can be pushed in order to avoid disorder of the data receiving sequence of the user end. In addition, the data that fails to be pushed by the pushing cache queue is added to the exception cache queue for re-pushing, so that data loss can be avoided.
[0063] In some embodiments, in order to improve the data processing efficiency of the pushing cache queue and the exception cache queue and avoid data blocking when the amount of data to be pushed is large, the pushing cache queue and the exception cache queue are concurrent queues that support data adding and taking out at the same time. For example, the pushing cache queue and the exception cache queue are expanded and implemented by using the class ConcurrentLinkedQueue provided by JavaApi, so that the pushing cache queue and the exception cache queue support data writing and reading operations at the same time.
[0064] In some embodiments, taking out data from the exception cache queue and pushing it to the user end includes the following steps:
[0065] Taking out data from the exception cache queue and pushing it to the user end, and judging whether the exception cache queue is empty. If not, the next data is taken out and pushed to the user end.
[0066] When the next polling arrives, if the exception cache queue is not empty, the data in the exception cache queue is preferentially sent until the data in the exception cache queue is successfully sent, and then data is taken out from the pushing cache queue and sent to the user end. For example, when the next polling arrives, it is first judged whether there is unsent data in the exception cache queue. If there is, the data in the exception cache queue is preferentially sent until the exception cache queue is empty, new business data is taken out from the pushing cache queue, and then sent to the merchant platform.
[0067] As shown in Figure 2 In some embodiments, the data includes a business ID and a version number, and the server writes the data into the database, and the database is provided with an upload flag bit of the data. The method further includes the following steps:
[0068] S201. In the server, a preset version update file is used to add the business ID and the version number of the data that has been successfully pushed to the version update file.
[0069] S202. The version update file is used to update the upload flag bit of the corresponding data in the database.
[0070] The service ID of the data is used to represent the service type of the data, different service IDs represent different service types, and the version number of the data represents the chronological order of the generation time of the data. For example, the service ID of the order placing data is 1, and the service ID of the order placing data is 2. The data with the same service ID, the data with the high version number is later than the data with the low version number, for example, in the order placing data with the same service ID, the data with the version number 5 is later than the data with the version number 4. The version update file in step S201 can be stored in a mobile storage medium such as an SD card, a U disk and the like. The service ID and the version number of the data that has been successfully pushed are stored in the version update file. In step S202, the upload flag bit is used to represent whether the corresponding data has been successfully pushed. When updating, the upload flag bit is updated by comparing the version numbers of the data with the same service ID.
[0071] The use of the version update file to update the upload flag bit of the corresponding data in the database includes the following steps:
[0072] It is judged whether the version number of the data (i.e. the data that has been pushed) in the version update file is equal to the version number of the corresponding data in the database. If yes, it means that the current data is the latest data, and the upload flag bit of the corresponding data in the database is updated to have been uploaded, and the business ID and the version number corresponding to the data pushed last time in the version update file are cleared. If not, the upload flag bit is not updated. The upload flag bit of the data that has been successfully pushed in the database is updated (i.e. marked), and the upload flag bit of the data with a higher version number in the database is not updated and is pushed subsequently. For example, the upload flag bit of the data that has been uploaded in the database is "Y", and the upload flag bit of the data that has not been uploaded is "N". Therefore, whether the data has been uploaded (i.e. whether it has been successfully pushed) can be known by the upload flag bit of the data in the database.
[0073] As shown in FIG. 1, the server data pushing method includes the following steps: Figure 3 As shown in FIG. 1, the server data pushing method includes the following steps:
[0074] S301, when the server is initialized or restarted, the version update file and the database are compared;
[0075] S302, the data with the upload flag bit not uploaded or the data version number higher than the version update file in the database is added to the push cache queue, so that the data is re-pushed to the user end.
[0076] In the embodiment, when the server is down, starts up, starts up after power failure or restarts, the uploading flag bit of the data in the database is identified, that is, which data in the database is pushed, and the data that is not successfully pushed is pushed again to avoid data missing, and the data that is successfully pushed will not be pushed again.
[0077] As shown in Figure 4 is a specific flowchart of pushing merchant data by the server in a specific embodiment. The business system is a business system of the server, and the business system of the server includes multiple concurrent businesses 1 to concurrent business N. The concurrent businesses generate corresponding business table data, which is data to be pushed to the user end.
[0078] The server preconfigures multiple business table data cache queues (i.e., push cache queues) including business table data 1 cache queue to business data N cache queue in the memory, and preconfigures a corresponding business table data exception cache queue (i.e., an exception cache queue) for each business table data cache queue. The business table data generated by the server is pushed by the corresponding business table data cache queue, wherein business table data 1 corresponds to business table data 1 cache queue, and business table data N corresponds to business table data N cache queue. The business table data is pushed by the corresponding business table data cache queue and is also sent to the local database of the server for saving.
[0079] Each business table data cache queue is polled by a polling mechanism, and data is written into the corresponding business table data cache queue, and the business table data of the business table data cache queue is sent to the merchant (i.e., the user end). The data can be directly sent to the offline device of each merchant, or can be sent to the cloud database of the merchant. The data that fails to be sent by the business table data cache queue is written into the corresponding business table data exception cache queue. In the polling mechanism, it is first determined whether there is data that fails to be sent in each business table data exception cache queue. If there is, the data in each business table data exception cache queue is sent to each merchant until each business table data exception cache queue has been successfully sent, and then the data in each business table data cache queue is read out and sent to the merchant. The data that fails to be sent by the business table data cache queue enters the business table data exception cache queue.
[0080] A version update file is preconfigured in the SD card, and the version update file is updated in the polling mechanism. The business ID and version number of the data that has been successfully sent to the merchant are saved in the version update file. Updating the version update file specifically includes:
[0081] The business ID and version number of the current data that has been successfully sent (i.e., the current data) are compared with the business ID and version number of the data updated last time in the version update file;
[0082] The system checks if the current data's service ID is a new service ID. If so, it directly adds the current data's service ID and version number to the service ID and version number list. If not, it checks if the current data's version number is greater than the version number of the same service ID data in the version update file. If so, it adds the current data's service ID and version number to the list; otherwise, it adds the service ID and version number of the previously successfully sent data to the list. Finally, the resulting list of service IDs and version numbers is saved to the version update file on the SD card. After successful saving, the version update file on the SD card contains the service IDs and version numbers of the latest successfully sent service data.
[0083] Finally, the service ID and version number of the successfully sent data are read from the SD card and compared with the service ID and version number of the data stored in the local database. It is determined whether the version number of the data with the same service ID is consistent. If so, the upload flag of the data in the local database on the server is changed to "uploaded" and saved to the local database. If not, no update is performed.
[0084] like Figure 5 The diagram shows the specific flowchart for data recovery and push in case of server-side anomalies. After the server initializes upon startup, powers on after a power outage, or restarts, it retrieves the business ID and version number of the data from the local database and compares them with the business ID and version number of the latest data in the version update file retrieved from the SD card.
[0085] Determine whether the upload flag in the local database indicates that data has been uploaded.
[0086] If so, compare the version numbers of data with the same business ID and determine whether the version number of the data in the database is greater;
[0087] If the upload flag is not uploaded, the data is added to the business table data cache queue; and if the version number of the data in the database is larger, the data is added to the business table data cache queue.
[0088] Finally, the data in the business table data cache queue is sent.
[0089] Therefore, by comparing the version update file in the SD card with the data upload flag in the local database, it is possible to determine whether the data was successfully sent when the server is abnormal, and to push the data that was not successfully pushed again to avoid data loss, while the data that was successfully pushed will not be pushed again.
[0090] like Figure 6The diagram shown is a block diagram of a server-side data push device 600 according to another embodiment of the present invention. The server-side data push device 600 is used to push data to a user terminal, and includes:
[0091] Queue module 601 is used to pre-set one or more push cache queues and one or more exception cache queues in the memory of the server.
[0092] The writing module 602 is used to write the data to be pushed generated by the server to the corresponding push cache queue;
[0093] The push module 603 is used to poll the push cache queue, retrieve data from the push cache queue and push it to the user terminal, and add data that fails to be pushed to the exception cache queue; retrieve data from the exception cache queue and push it to the user terminal.
[0094] In some embodiments, the server-side data push device 600 further includes a version update module. The version update module is used to preset a version update file on the server, add the business ID and version number of successfully pushed data to the version update file, and use the version update file to update the upload flag of the corresponding data in the database.
[0095] like Figure 7 As shown, the present invention also provides another embodiment of a computer-readable storage medium 700, on which a computer program is stored, which, when executed by a processor, implements the server data push method as described in any of the above embodiments.
[0096] Finally, it should be noted that although the above embodiments have been described in the text and drawings of this application, this should not limit the scope of patent protection of this application. Any technical solutions that are based on the essential concept of this application and utilize the content described in the text and drawings of this application, resulting in equivalent structural or procedural substitutions or modifications, as well as the direct or indirect application of the technical solutions of the above embodiments to other related technical fields, are all included within the scope of patent protection of this application.
Claims
1. A server-side data push method for pushing data to a user terminal, characterized in that, The method includes the following steps: On the server side, one or more push cache queues and one or more exception cache queues are preset in memory; The data to be pushed generated by the server is written to the corresponding push cache queue; The system polls the push cache queue, retrieves data from the push cache queue and pushes it to the user terminal, and adds data that fails to push to the exception cache queue. Retrieve data from the exception cache queue and push it to the user client; The push cache queue and the exception cache queue are concurrent queues that support simultaneous data addition and retrieval.
2. The server-side data push method according to claim 1, characterized in that, The data includes a business ID and a version number. The data is written to the server's database, which contains an upload flag. The method also includes the following steps: The server pre-sets a version update file, and adds the business ID and version number of the data that has been successfully pushed to the version update file; Update the upload flag of the corresponding data in the database using the version update file.
3. The server-side data push method according to claim 2, characterized in that, The step of updating the upload flag of the corresponding data in the database using the version update file includes the following steps: Determine whether the version number of the data in the version update file is equal to the version number of the corresponding data in the database; if yes, update the upload flag of the corresponding data in the database to "uploaded" and clear the business ID and version number corresponding to the last uploaded data in the version update file; if no, do not update the upload flag.
4. The server-side data push method according to claim 2, characterized in that, It also includes the following steps: During server startup initialization or restart, the version update file and the database are compared. Data whose upload flag is not uploaded or whose data version number is higher than the updated version file in the database are added to the push cache queue, so that the data is re-pushed to the user.
5. The server-side data push method according to claim 1, characterized in that, The step of retrieving data from the exception cache queue and pushing it to the user terminal includes the following steps: The system retrieves data from the exception cache queue and pushes it to the user terminal, and determines whether the exception cache queue is empty. If not, it retrieves the next data and pushes it to the user terminal. When the next polling arrives, if the exception cache queue is not empty, the data in the exception cache queue is sent first until all the data in the exception cache queue has been sent successfully. Then, the data is retrieved from the push cache queue and sent to the user.
6. The server-side data push method according to claim 1, characterized in that, The server is an Android system server, and the data is the merchant's business data.
7. A server-side data push device for pushing data to a user terminal, characterized in that, include: The queue module is used to pre-set one or more push cache queues and one or more exception cache queues in the server's memory; The writing module is used to write the data to be pushed generated by the server to the corresponding push cache queue; as well as The push module is used to poll the push cache queue, retrieve data from the push cache queue and push it to the user terminal, and add data that fails to be pushed to the exception cache queue. Data is retrieved from the exception cache queue and pushed to the user terminal; the push cache queue and the exception cache queue are concurrent queues that support simultaneous data addition and retrieval.
8. The server-side data push device according to claim 7, characterized in that, Also includes: The version update module is used to preset a version update file on the server and add the business ID and version number of the data that has been successfully pushed to the version update file; And use the version update file to update the upload flag of the corresponding data in the server's database.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the server-side data push method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Distributed cache high-availability processing method and system based on multithreading asynchronous double writing
CN103500120A
Data synchronization system and method
CN112615907A
Task scheduling method and device, equipment and storage medium
CN112667382A