CN-121984896-A - Method and device for detecting and notifying state of Internet of things equipment based on Redis multi-data structure cooperation and electronic equipment
Abstract
The invention provides an Internet of things equipment state detection and notification method, device and electronic equipment based on Redis multi-data structure cooperation, and relates to the technical field of Internet of things and data processing, comprising the steps of periodically calling a Lua script, executing ZRangeByScore in an atomic manner on a Redis server to inquire about members with scores smaller than a timeout threshold in an ordered set so as to obtain an offline equipment list, and executing ZRemRangeByScore to delete members corresponding to the offline equipment list in batches; and extracting service dimension based on the device attribute, classifying and aggregating the devices in the device set to be notified in the application layer memory according to the service dimension, generating an summarized message and pushing the summarized message to a third party system through a single callback interface. The automatic recovery method and the system realize automatic recovery of the expired index, do not need manual intervention, and ensure that the system runs for a long time without generating data expansion.
Inventors
- ZOU JIANHUA
- MA JUNXIANG
Assignees
- 递易(上海)智能科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20260407
Claims (10)
- 1. The method for detecting and notifying the state of the Internet of things equipment based on the cooperation of Redis and multiple data structures is characterized by comprising the following steps: constructing a device online index by using an ordered set of Redis, wherein the ordered set takes a device identifier as a member, takes a heartbeat timestamp as a score, and performs atomic writing in response to a heartbeat of a receiving device to update the ordered set; Periodically calling a Lua script, wherein the Lua script atomically executes ZRangeByScore members with the scores smaller than a timeout threshold in the ordered set to obtain an offline device list at a Redis server, and executes ZRemRangeByScore to delete the members corresponding to the offline device list in batches, and the Lua script ensures that the same offline device list is only acquired and processed by one service node by utilizing the single-thread execution characteristic of Redis; responding to the offline equipment list, and acquiring equipment attributes corresponding to all equipment identifiers in the offline equipment list in one-time batch from a hash structure of Redis by utilizing HMGET commands in combination with the Redis pipeline; Inquiring the last alarm time of each device recorded in the independent hash structure of the Redis based on a sliding time window algorithm, if the difference between the current time and the last alarm time is smaller than the preset window duration, suppressing the alarm, and taking the offline device which is not suppressed as a device set to be notified; and extracting service dimensions based on the device attributes, classifying and aggregating the devices in the device set to be notified in an application layer memory according to the service dimensions, generating summarized information and pushing the summarized information to a third party system through a single callback interface.
- 2. The method for detecting and notifying the state of the internet of things equipment based on the cooperation of Redis and multiple data structures according to claim 1, wherein the Lua script realizes a strong consistency mechanism of inquiry and clearing by encapsulating ZRangeByScore and ZRemRangeByScore in the same atomic operation, so that other concurrent service nodes can not inquire the same equipment after the data are cleared after the script is executed, and repeated processing caused by concurrent invocation of multiple service nodes is avoided.
- 3. The method for detecting and notifying the state of the internet of things device based on the cooperation of the Redis data structures according to claim 1, further comprising: recording a first heartbeat mark of the equipment by utilizing an independent hash structure of Redis; Responding to the received equipment heartbeat, inquiring the first heartbeat identification, judging that the equipment is online for the first time if the first heartbeat identification does not exist, and triggering a first registration synchronization notification to a third party system; and in response to receiving the heartbeat of the equipment and the existence of the equipment in the independent hash structure for recording the last alarm time, judging that the equipment is recovered offline, and triggering the online synchronization notification of the equipment to a third party system.
- 4. The method for detecting and notifying the status of the devices of the internet of things based on the cooperation of the Redis and the data structure according to claim 1, wherein the step of acquiring the device attribute corresponding to each device identifier in the offline device list in batch at a time by utilizing HMGET commands in combination with the Redis pipeline from the hash structure of the Redis comprises the following steps: Constructing a single HMGET command by taking a plurality of equipment identifiers in the offline equipment list as parameters; and sequentially executing the HMGET commands and the call of the Lua script in the same network connection through a Redis pipeline so as to reduce the network round trip times, and combining multiple independent key value queries into one batch operation.
- 5. The method for detecting and notifying the state of the internet of things device based on the coordination of Redis and data structures according to claim 1, wherein the extracting a service dimension based on the device attribute, classifying and aggregating the devices in the device set to be notified in the application layer memory according to the service dimension, comprises: Analyzing the equipment attribute, and extracting at least one business dimension label of merchant ID, site ID and grouping ID; Aggregating the equipment identifiers with the same keys into the same set by taking the service dimension labels as keys; and generating a summary message containing a device list, offline time and service dimension identification for each aggregation set, and pushing the summary message to a corresponding third party system through a single HTTP callback.
- 6. The method for detecting and notifying the state of the internet of things device based on the cooperation of the Redis data structures according to claim 1, further comprising: Setting a heartbeat timeout threshold and a window duration of a sliding time window, wherein the heartbeat timeout threshold is smaller than the window duration; dynamically adjusting the heartbeat timeout threshold and the window duration to adapt to real-time requirements and alarm sensitivity requirements in different scenes.
- 7. The method for detecting and notifying the state of the internet of things equipment based on the cooperation of Redis and a multi-data structure according to claim 1, wherein when the online index of the equipment is constructed by utilizing the ordered set of Redis, the score automatic ordering characteristic of ZSet is adopted, the heartbeat reporting timestamp is used as a score, the latest active equipment is positioned in a high-resolution area of the ordered set, the overtime equipment is automatically concentrated in a low-resolution area for the Lua script to perform range scanning, and the time complexity of offline detection is optimized from O (N) of the traditional full-scale scanning to O (logN+M), wherein N is the total equipment number, and M is the offline equipment number.
- 8. The device for detecting and notifying the state of the Internet of things equipment based on the cooperation of Redis and multiple data structures is characterized by comprising the following components: the heartbeat receiving module is used for constructing an equipment online index by utilizing an ordered set of Redis, wherein the ordered set takes equipment identification as a member, takes a heartbeat time stamp as a score, and responds to heartbeat of receiving equipment to execute atomic writing so as to update the ordered set; The offline detection module is used for periodically calling a Lua script, the Lua script performs ZRangeByScore in an atomic manner on a Redis server to inquire about members with scores smaller than a timeout threshold in the ordered set so as to obtain an offline device list, and performs ZRemRangeByScore batch deletion of the members corresponding to the offline device list, wherein the Lua script ensures that the same offline device list is acquired and processed by only one service node by utilizing the single-thread execution characteristic of Redis; The information retrieval module is used for responding to the offline equipment list, and acquiring equipment attributes corresponding to all equipment identifiers in the offline equipment list in one-time batch mode from a hash structure of the Redis by utilizing HMGET commands in combination with the Redis pipeline; The alarm deduplication module is used for inquiring the last alarm time of each device recorded in the independent hash structure of the Redis based on a sliding time window algorithm, if the difference value between the current time and the last alarm time is smaller than the preset window duration, suppressing the alarm, and taking the offline device which is not suppressed as a device set to be notified; And the state synchronization module is used for extracting service dimensions based on the equipment attributes, classifying and aggregating the equipment in the equipment set to be notified in the application layer memory according to the service dimensions, generating summarized information and pushing the summarized information to a third party system through a single callback interface.
- 9. An electronic device, wherein the electronic device comprises: And a memory storing computer executable instructions that, when executed, cause the processor to perform the method of any of claims 1-7.
- 10. A computer readable storage medium, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement the method of any of claims 1-7.
Description
Method and device for detecting and notifying state of Internet of things equipment based on Redis multi-data structure cooperation and electronic equipment Technical Field The invention relates to the technical field of Internet of things and data processing, in particular to an Internet of things equipment state detection and notification method and device based on Redis data structure cooperation and electronic equipment. Background Along with explosive growth of intelligent logistics terminal facilities (such as express cabinets, post cabinets and community cabinets), the online state instantaneity of cabinet equipment has become a core index for influencing terminal distribution efficiency and user experience. The existing off-line detection technology of cabinet equipment mainly relies on timing polling and a relational database, and when the equipment scale reaches over ten thousand levels, the technology bottleneck which cannot be overcome is faced. This mode suffers from the following significant drawbacks: 1. The off-line discovery is delayed, the detection efficiency is low, and the traditional scheme adopts a full-volume timing polling mechanism (such as scanning a device table every 5-30 minutes), and the method is essentially based on full-table scanning of a relational database. The time complexity of this operation approaches O (n), and as the number of devices n increases, the database I/O overhead increases linearly. Meanwhile, due to the existence of a polling interval, a 'detection blind area window' exists in the system, so that fault discovery is seriously delayed, and second-level offline perception cannot be realized. 2. Alarm logic is stiff and lacks intelligent deduplication, namely, the existing alarm logic is a simple threshold judgment of 'state change is triggered'. When the equipment is subjected to high-frequency oscillation due to network jitter, the system can generate mass repeated alarms to form an alarm storm. The processing capacity of the operation and maintenance monitoring platform is instantaneously broken down, and the operation and maintenance personnel are caused to generate alarm fatigue, so that the real serious offline fault is submerged, and the fault response efficiency is reduced. 3. And the invalid interaction redundancy and the system resource waste are that the prior art lacks the status increment screening capability when the status synchronization is carried out with a third party system, and a full push or high-frequency polling reporting mode is generally adopted. During steady operation of the device, over 90% of such interactions belong to invalid communications, greatly wasting network bandwidth and easily causing third party systems to trigger throttling or avalanche. 4. The database pressure is overlarge, the system expansibility is poor, and the high-frequency real-time state read-write pressure is directly applied to the bottom database based on the polling architecture of the relational database. Under the dual pressures of high concurrent writing (heartbeat reporting) and high concurrent reading (state query), the database is very easy to have lock competition and connection pool exhaustion, forming performance bottlenecks. For a long time, the industry commonly has the technical prejudice that 'Redis is only suitable for cache and not suitable for being used as core state storage', and the state is unreliable due to the fact that the data volatility of the Redis is considered, so that the prior art always adheres to a relational database as a core, and the performance bottleneck cannot be broken through from the architecture level. Therefore, an Internet of things equipment state detection and notification method and device based on Redis multi-data structure cooperation and electronic equipment are provided. Disclosure of Invention The specification provides a method, a device and electronic equipment for detecting and notifying the state of Internet of things equipment based on Redis multi-data structure cooperation, which realize automatic recovery of expiration indexes without manual intervention and ensure that the system runs for a long time without data expansion. The specification provides a method for detecting and notifying the state of Internet of things equipment based on Redis multi-data structure cooperation, which comprises the following steps: constructing a device online index by using an ordered set of Redis, wherein the ordered set takes a device identifier as a member, takes a heartbeat timestamp as a score, and performs atomic writing in response to a heartbeat of a receiving device to update the ordered set; Periodically calling a Lua script, wherein the Lua script atomically executes ZRangeByScore members with the scores smaller than a timeout threshold in the ordered set to obtain an offline device list at a Redis server, and executes ZRemRangeByScore to delete the members corresponding to the offline device list in