Continuous pipeline code generation method, equipment and medium

By distributely creating a flow code sequence in the Redis node and using a consistent hashing algorithm and dynamic priority queue, the continuity and efficiency of flow code generation are solved, and the flow code continuity and efficient generation in complex scenarios are achieved to meet business needs and data tracking.

CN120448427APending Publication Date: 2025-08-08SHANGHAI DEFINESYS INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510549647.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-29
Publication Date
2025-08-08

AI Technical Summary

Technical Problem

The prior art fails to effectively ensure the continuity and efficiency of flow codes in high concurrency environments, especially in complex scenarios, and it is difficult to meet the needs of business process coherence and data tracking.

Method used

By constructing a flow code identifier, the flow code sequence is distributed among multiple Redis nodes based on the self-increment sequence of Redis, and the node load is evenly distributed using a consistent hashing algorithm, combining dynamic priority queues and rollback mechanisms to ensure the continuity and efficient generation of flow codes.

Benefits of technology

It realizes continuity and efficient generation of flow codes in complex scenarios, meets business process coherence and data tracking needs, optimizes system stability and response speed, supports customized management and load balancing, and ensures data accuracy and integrity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120448427A_ABST
    Figure CN120448427A_ABST
Patent Text Reader

Abstract

The invention relates to a method and device for generating continuous stream codes and a medium, and the method comprises the following steps: constructing stream code identifiers, each generated stream code corresponding to a unique stream code identifier; creating a plurality of pipelined code sequences in a plurality of Redis nodes in a distributed manner based on the pipelined code identifiers and the Redis auto-increment sequence, and respectively storing the pipelined code sequences in the corresponding Redis nodes; according to a value taking rule, taking out a preset number of pipeline code sequences from the Redis node in advance and caching the pipeline code sequences; and when a pipelined code generation request is received, taking out a pipelined code sequence from the cache as a generated pipelined code, if the number of the pipelined code sequences in the cache is detected to be less than a preset number in the pipelined code generation process, taking out the pipelined code sequences from the Redis node for caching, and keeping the number of the pipelined code sequences in the cache to be the preset number. Compared with the prior art, the method has the advantages of being capable of efficiently and stably generating the continuous pipeline code and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device and medium for generating a continuous stream code. Background Art

[0002] In the field of modern information technology, the generation and management of serial numbers has become a major technical challenge. Traditional serial numbers typically use an increasing sequence of numbers or letters to ensure uniqueness, but for more complex scenarios, additional considerations must be given to the continuity and efficiency of the serial numbers.

[0003] Traditional methods typically use database auto-incrementing primary keys or stored procedures, but these methods are inefficient in high-concurrency environments. Therefore, some existing technologies have introduced Redis as an in-memory database, leveraging its efficient auto-incrementing sequence function to generate serial numbers, thereby improving efficiency and performance. For example, CN118377832A discloses a lightweight distributed ID generation method, including the following steps: establishing ID model fields in the Redis database and the Redis cache library respectively, and presetting the initialization value and step value in the Redis database; receiving an ID generation request, determining the cache switch status, and if the cache switch is determined to be in the off state, entering the database accumulation mode; if the cache switch is determined to be in the on state, switching to the cache accumulation mode; in the cache accumulation mode, executing the Redis atomic increment operation, and if the Redis atomic increment operation is successful, entering the step value determination step; if the Redis atomic increment operation fails, switching to the database accumulation mode; checking whether the ID value generated after executing the Redis atomic increment operation reaches the preset step value, if the preset step value is not reached, outputting the ID value; if the preset step value is reached, executing the database update step; when the ID value reaches the preset step value, interacting with the Redis database, updating the initialization value and resetting the ID value in the cache library. This method combines a database with a cache, leveraging the database's persistence to ensure stable ID generation and the cache's high-speed access to improve generation efficiency. However, this method only considers the uniqueness of the generated serial number and doesn't address the issue of serial number generation continuity in complex scenarios. Traditional serial number generation typically doesn't consider continuity; generated serial numbers that are not used or encounter errors during use are simply discarded. However, in some complex scenarios, due to business process continuity requirements or data tracking needs, it is necessary to ensure the continuity of the generated serial numbers.

[0004] Therefore, there is currently a lack of an efficient and stable continuous stream code generation technology. Summary of the Invention

[0005] The purpose of the present invention is to provide a method, device and medium for generating a continuous stream code in order to overcome the defects of the above-mentioned prior art.

[0006] The purpose of the present invention can be achieved by the following technical solutions:

[0007] According to a first aspect of the present invention, a method for generating a continuous stream code is provided, the method comprising the following steps:

[0008] Constructing a serial code identifier, where each generated serial code corresponds to a unique serial code identifier;

[0009] Based on the serial code identifier and Redis's auto-increment sequence, multiple serial code sequences are distributedly created in multiple Redis nodes and stored in corresponding Redis nodes respectively;

[0010] According to the value selection rules, a preset number of serial code sequences are pre-fetched from the Redis node and cached;

[0011] When receiving a request for generating a serial code, a serial code sequence is taken out from the cache as the generated serial code;

[0012] If it is detected during the serial code generation process that the number of serial code sequences in the cache is less than the preset number, the serial code sequence is taken out from the Redis node for caching, and the number of serial code sequences in the cache is kept at the preset number.

[0013] As an optimal technical solution, the serial code identifier includes a custom management identifier and an input parameter value. The custom management identifier is used to realize the unified management of the serial code identifier under the corresponding service demander. Different service demanders correspond to different custom management identifiers. The input parameter value includes one of the application ID, form ID, component ID and sequence information.

[0014] As a preferred technical solution, in the process of distributed generation of the serial code sequence, the consistent hashing algorithm is used to ensure that each Redis node is responsible for generating the serial code in a specific range, including the following steps:

[0015] Map all Redis nodes to a virtual hash ring using a hash function, where the hash value calculated by the hash function for the Redis node corresponds to its position on the virtual hash ring, and all nodes are evenly distributed on the virtual hash ring by setting virtual nodes;

[0016] According to the node position on the virtual hash ring, a specific range of stream code sequences is assigned to each node, where the hash value interval between two adjacent nodes corresponds to a stream code sequence range, and the last node and the first node belong to two adjacent nodes.

[0017] As a preferred technical solution, the distributed creation of multiple pipeline code sequences is specifically as follows:

[0018] Based on the serial code identifier, the following steps are executed in a loop to create multiple serial code sequences:

[0019] Perform hash calculation based on the information in the current serial code identifier to obtain the corresponding hash value;

[0020] Based on the calculated hash value, search for the first Redis node that is greater than or equal to the hash value on the virtual hash ring;

[0021] Use Redis's atomic operations on the found Redis node to generate the current serial code sequence.

[0022] As an optimal technical solution, if a serial code anomaly is detected during the serial code generation process, the rollback mechanism is triggered, and the corresponding serial code sequence in the Redis node is restored to the state before the anomaly occurs according to the recorded operation log, and the cache is updated according to the value selection rules to delete the abnormal serial code record.

[0023] As a preferred technical solution, the method further includes:

[0024] Based on the dynamic priority queue mechanism, the processing priority is adjusted according to the urgency of the serial code generation request.

[0025] As a preferred technical solution, the method further includes:

[0026] Set the modification interface to customize the currently generated serial code by modifying the value of the serial code identifier in the Redis node. During the modification process, the modified serial code identifier is verified. If the verification passes, the modified serial code is returned. Otherwise, an abnormal alarm is issued.

[0027] As a preferred technical solution, the method further includes:

[0028] Set the reset time of the serial code sequence, embed reset time related information in the serial code identifier, automatically clear the expired serial code identifier in the Redis node and clear the cache at the reset time, and realize the regular reset of the serial code sequence.

[0029] According to a second aspect of the present invention, an electronic device is provided, comprising a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the method when executing the program.

[0030] According to a third aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method described above is implemented.

[0031] Compared with the prior art, the present invention has the following beneficial effects:

[0032] (1) Ensuring the continuity of running codes: Existing technologies do not fully consider the continuity of running code generation in complex scenarios, and are insufficient in terms of business process continuity and data tracking requirements. This invention ensures the continuity of running code generation in complex scenarios by constructing a running code identifier, creating a running code sequence in a distributed manner, caching and retrieving the running code sequence from a Redis node based on value selection rules, and combining the end-to-end connection of the hash ring. This meets the business process continuity and data tracking requirements.

[0033] (2) Realize unified management and flexible configuration: The serial code identifier set by the present invention includes a custom management identifier and an input parameter value, wherein the custom management identifier can realize the unified management of the serial code identifiers under different service demand parties, and the input parameter value contains a variety of information, making the serial code generation more flexible and meeting diverse business needs.

[0034] (3) Optimize distributed generation and load balancing: In the process of distributed generation of serial code sequences, the consistent hashing algorithm is used to map Redis nodes to the virtual hash ring and set virtual nodes to make all nodes evenly distributed. A specific range of serial code sequences is assigned to each node, achieving load balancing, improving the stability and performance of the system, and ensuring that each Redis node is responsible for generating a specific range of serial code sequences.

[0035] (4) Ensure data accuracy and integrity: When a serial code anomaly is detected, the present invention triggers a rollback mechanism, restores the corresponding serial code sequence in the Redis node according to the operation log, updates the cache, and deletes the abnormal record, thereby ensuring the accuracy and integrity of the data, avoiding the occurrence of broken numbers and duplications, and avoiding data errors or losses due to abnormal situations.

[0036] (5) Improve generation efficiency and response speed: The present invention is based on a dynamic priority queue mechanism, which adjusts the processing priority according to the urgency of the serial code generation request, and can give priority to urgent requests, thereby improving the response speed and overall efficiency of the system and meeting the requirements of different business scenarios for request processing speed.

[0037] (6) Support for custom modification and verification: The present invention sets a modification interface, which can customize the currently generated serial code by modifying the value of the serial code identifier in the Redis node, providing users with a customizable, more flexible and reliable serial code generation and management service, while ensuring the legality and security of the modification, and improving user experience and satisfaction.

[0038] (7) Realizing periodic zeroing and resource management: The present invention can realize periodic zeroing of the serial code sequence by setting the reset time of the serial code sequence, effectively managing system resources and avoiding the impact of long-term accumulated data on system performance.

[0039] (8) Good scalability: The present invention simplifies the management and maintenance of multiple stream code sequences through the design of stream code identifiers and the characteristics of Redis, making the system easier to expand and upgrade, and reducing operation and maintenance costs and risks. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 is a flow chart of the method of the present invention;

[0041] Figure 2 Schematic diagram of a rollback mechanism in an embodiment;

[0042] Figure 3 A logical flow chart for generating serial code in one embodiment. DETAILED DESCRIPTION

[0043] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts should fall within the scope of protection of the present invention.

[0044] Unless otherwise defined, the technical or scientific terms used in this application should have the ordinary meaning understood by a person of ordinary skill in the technical field to which this application belongs. The words "one", "a", "the" and the like used in this application do not indicate a limit on quantity and may indicate the singular or plural. The terms "include", "comprise", "have" and any variations thereof used in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units that are inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like used in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The word "multiple" used in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects before and after are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific order for the objects.

[0045] Example 1

[0046] This embodiment provides a method for generating a continuous stream code, such as Figure 1 As shown, the method includes the following steps:

[0047] S1, construct a serial code identifier, each generated serial code corresponds to a unique serial code identifier.

[0048] In this embodiment, the serial code identifier key is used to ensure the uniqueness of each serial code sequence, and its composition includes a custom management identifier key_pre and an input parameter value, wherein the custom management identifier is used to achieve unified management of the serial code identifier under the corresponding service demander, and different service demanders correspond to different custom management identifiers. For example, if there are multiple service demanders who need to generate serial codes, a unique key_pre can be configured for each service demander, such as serviceA_ and serviceB_, and then combined with the specific input parameter value to form a complete key. The input parameter value includes one of the application ID, form ID, component ID and sequence information. For example, the serial code identifier can be represented as serviceA_user123 and serviceB_order456.

[0049] S2. Create multiple serial number sequences distributively in multiple Redis nodes based on the sequential codes identifier and the auto-increment sequence of Redis, and store them in the corresponding Redis nodes respectively.

[0050] In this embodiment, Redis is introduced as an in-memory database. By using its auto-increment sequence function to replace the traditional database auto-increment primary key or stored procedure, the efficiency and performance of generating sequential codes are improved. The Redis auto-increment sequence is atomic, and there is no need to consider transaction issues.

[0051] Among them, in the process of distributively generating sequential code sequences, the consistent hashing algorithm is used to ensure that each Redis node is responsible for generating sequential codes within a specific range, which not only improves the efficiency of generating sequential codes but also enhances the fault tolerance of the system. The specific steps are as follows:

[0052] S201. Map all Redis nodes to the virtual hash ring through a hash function. Specifically,

[0053] All Redis nodes participating in the generation of sequential code sequences calculate hash values based on a hash function (such as MD5, SHA-1, etc.). This hash value corresponds to its position on the virtual hash ring, and one node corresponds to one point on the virtual hash ring. For example, assume there are three Redis nodes, node1, node2, and node3. Calculate their hash values using the MD5 hash function, and the obtained hash values are their positions on the hash ring.

[0054] To make the data more evenly distributed on the hash ring, virtual nodes are set so that all nodes are evenly distributed on the virtual hash ring. Usually, multiple virtual nodes are created for each physical node, and each virtual node is also mapped to the hash ring through a hash function. For example, create three virtual nodes, node1-0, node, and node1-2, for node1 and map them to the hash ring. This can avoid the problem of some nodes being overloaded due to uneven node distribution and balance the load.

[0055] S202. Allocate a specific range of sequential code sequences to each node according to the node positions on the virtual hash ring.

[0056] The range allocation of sequential codes is based on the positions of nodes on the virtual hash ring. The hash value interval between two adjacent nodes corresponds to a sequential code range. For example, assume the hash value of node1 is h1 and the hash value of node2 is h2, and h1 < h2. Then the sequential codes in the interval from h1 + 1 to h2 are generated by node2.

[0057] In order to ensure that the generated serial code is continuous, the continuity of the serial code range must be ensured. Therefore, on the virtual hash ring of this embodiment, the interval between the last node and the first node also corresponds to a serial code range, forming a closed loop.

[0058] In one embodiment, the distributed creation of multiple stream code sequences is specifically as follows:

[0059] Based on the serial code identifier, the following steps are executed in a loop to create multiple serial code sequences:

[0060] S211, performing a hash calculation based on the information in the current serial code identifier to obtain a corresponding hash value;

[0061] S212: Based on the calculated hash value, search for the first Redis node on the virtual hash ring that is greater than or equal to the hash value. This node is the node responsible for generating the serial code sequence.

[0062] S213, using Redis atomic operations (such as INCR command) on the found Redis node to generate the current serial code sequence. Due to the single-threaded nature of Redis, the INCR command is atomic and can ensure the continuity of the serial code.

[0063] Based on the setting of this virtual hash ring, this embodiment can also implement simple node changes. When a new Redis node joins, the node and its virtual node are mapped to the virtual hash ring, and then the running code range is redistributed. Part of the running code range may be transferred from the original node to the new node. When a node exits, the running code range responsible for the node needs to be reallocated to other nodes. This process is achieved by updating the node information on the virtual hash ring.

[0064] S3, according to the value selection rules, pre-fetches a preset number of serial code sequences from the Redis node and caches them.

[0065] This embodiment ensures the continuity of serial code generation by pre-fetching values. Since the internal logic of the value-taking logic is relatively complex, Lua script is used to encapsulate the value-taking operation to facilitate client calls. The process includes the following steps:

[0066] S31, receiving parameters

[0067] In the Lua script, two important parameters passed from the client are received: the serial code identifier and the number of pre-fetched serial codes.

[0068] The first parameter is the serial code identifier, which is the Redis key name that stores the serial code. It is obtained through KEYS[1]. When executing the script, the client needs to explicitly specify this key name to identify the serial code storage location to be operated.

[0069] The second parameter is obtained through ARGV[1] and converted to a numeric type using the tonumber function. When the client calls the script, it must pass in the specific prefetch quantity.

[0070] S32, obtain the current serial code value

[0071] Use the redis.call("GET",key) function to call the Redis GET command and try to obtain the current serial code value corresponding to the serial code identifier (that is, the specified key) from Redis.

[0072] The obtained value is judged and processed: If the obtained value is nil, it means that the key does not exist in Redis, and the current serial code value is initialized to 0. If the obtained value exists, use the tonumber function to convert it to a number type for subsequent numerical calculations.

[0073] S33, pre-fetch serial code and update Redis value

[0074] Calculate the next serial code value after prefetching. Add the current serial code value to the number of prefetched serial codes to get next_value.

[0075] Use the redis.call("SET", key, next_value) function to call the Redis SET command and set the calculated next_value to the new value of the key in Redis. This way, subsequent serial number generation will start from this new value, ensuring the continuity of the serial number.

[0076] S34, returns the pre-fetched serial code interval

[0077] In this embodiment, a two-element array is returned. The first element is current_value+1, which represents the starting value of the pre-fetched serial code interval. The second element is next_value, which represents the ending value of the pre-fetched serial code interval. The client can cache and use the pre-fetched serial code locally based on this returned interval.

[0078] Through the above four steps, the Lua script implements the function of prefetching a specified number of serial codes from Redis, ensuring the atomicity of the operation and avoiding conflicts that may arise in concurrent situations.

[0079] The following is an example Lua script:

[0080] --Lua script for prefetching serial code

[0081] local key = KEYS[1]

[0082] local prefetch_count=tonumber(ARGV[1]);

[0083] --Get the current serial number

[0084]

[0085] --Prefetch serial code

[0086] local next_value=current_value+prefetch_countredis.call("SET",key,next_value)

[0087] --Return the pre-fetched serial code interval

[0088] return{current_value+1,next_value}

[0089] S4: When a request for generating a serial code is received, a serial code sequence is taken out from the cache as the generated serial code.

[0090] S5, if it is detected during the serial code generation process that the number of serial code sequences in the cache is less than the preset number, the serial code sequence is taken out from the Redis node for caching, and the number of serial code sequences in the cache is kept at the preset number.

[0091] Example 2

[0092] Based on Example 1, this embodiment provides a method for detecting abnormalities during the generation of a serial code. Figure 2 As shown, the following steps are included:

[0093] Execute business logic;

[0094] Get the serial number;

[0095] Execute subsequent business codes;

[0096] Determine whether a serial code exception is detected. If an exception is detected, determine whether a comment is added to the business method. If a comment is added, trigger the comment-based rollback mechanism, restore the corresponding serial code sequence in the Redis node to the state before the exception occurs according to the recorded operation log, update the cache according to the value selection rules, and delete the abnormal serial code record; if no comment is added or there is no exception, execute the subsequent steps normally.

[0097] In this embodiment, the recorded operation log includes the serial code key, the generated serial code value, the operation time, etc. This information can be stored in a Redis list or other data structure, or in a database.

[0098] Example 3

[0099] This embodiment, based on the first embodiment, provides a method for adjusting the processing priority according to the urgency of the serial code generation request based on a dynamic priority queue mechanism. The method includes the following steps:

[0100] Define a data structure for a serial code request, which contains the request identifier, urgency (i.e., priority), and other necessary information;

[0101] Use Python's heapq module to build a priority queue to sort requests according to their priority;

[0102] Regularly check the system load, such as the response time of Redis operations and CPU usage, and dynamically adjust the priority. When the system load is high, lower the priority of low-priority requests; when the system load is low, increase the priority of low-priority requests.

[0103] Dynamically adjust the priority of the request based on the waiting time in the queue. The longer the waiting time, the higher the priority.

[0104] Processing requests: Take out requests from the priority queue in descending order of priority and process them in sequence to generate a serial code.

[0105] Based on the above steps, you can ensure that high-priority requests are responded to quickly, while low-priority requests can be processed when the system load is lower.

[0106] Example 4

[0107] Based on Example 1, this embodiment provides a method for customizing and modifying a serial code. A modification interface is set to customize and modify the currently generated serial code by modifying the value of the serial code identifier in the Redis node. Specifically, the following steps are included:

[0108] Based on the serial code to be modified, use the consistent hashing algorithm or other distributed strategies to determine the Redis node that stores the target serial code identifier;

[0109] Use the Redis client library to connect to the corresponding Redis node;

[0110] Use the Redis SET command or other appropriate commands to modify the value of the serial code identifier;

[0111] The modified serial code identifier is verified and the modified serial code is returned if the verification passes, otherwise an abnormal alarm is issued.

[0112] Example 5

[0113] Based on Example 1, this embodiment provides a method for resetting a serial code, sets a reset time for a serial code sequence, embeds reset time-related information in a serial code identifier, automatically clears expired serial code identifiers in a Redis node and empties the cache at the reset time, thereby periodically resetting the serial code sequence to zero.

[0114] For example, if the serial code needs to be reset at midnight every day, you can set the expiration time in the serial code identifier to 24 hours, and use the Redis key expiration mechanism to automatically clear the expired key to ensure that the serial code sequence is automatically reset when the expiration time arrives.

[0115] Specifically, the implementation process includes the following steps:

[0116] Set the reset time, which can be daily or monthly;

[0117] Embed reset time related information into the serial code identifier (Redis key) to ensure that each cycle sequence corresponds to a unique key;

[0118] Before generating the serial code, check whether the current time exceeds the reset time of the key:

[0119] If it has not expired, directly use the current key to generate a serial code;

[0120] If it has expired, create a new key, set the initial value, and set the expiration time for the new key to the next reset time.

[0121] Example 6

[0122] This embodiment provides a method for generating a serial code taking into account the pre-fetch mechanism and the reset mechanism based on the embodiments 1-5. Figure 3 As shown, the following steps are included:

[0123] Step 1) Obtaining a serial code sequence;

[0124] Step 2) Call the Redis value Lua script;

[0125] Step 3) Determine whether a reset is required (i.e., whether the key has expired). If so, jump to step 4); otherwise, jump to step 5);

[0126] Step 4) Recreate the serial code sequence, clear the pre-fetch queue, and jump to step 6);

[0127] Step 5) Determine whether there is a value in the pre-fetch queue. If so, fetch the value from the pre-fetch queue and return it. Otherwise, jump to step 6);

[0128] Step 6) Call the Redis auto-increment sequence to batch-fetch n values, fill n-1 values into the pre-fetch queue, and return the first value in the pre-fetch queue.

[0129] Example 7

[0130] This embodiment provides an implementation of the application of the method for generating a serial code according to embodiments 1-6:

[0131] Create the WaterCodeService class to provide external water code operation services.

[0132] Write the createWaterCode(String key,long initialValue,long expired,TimeUtil time) method to provide the service of creating a serial water code sequence.

[0133] Write the setWaterCodeValue(String key, long value) method to provide the service of resetting the water code sequence.

[0134] Write the getWaterCodeValue(String key) method to provide a service for obtaining the specified water code sequence value.

[0135] Write the @WaterCodeRollBack annotation and write aspects in combination with Spring's AOP mechanism to trigger the water code rollback mechanism when handling business method call exceptions.

[0136] Add the @WaterCodeRollBack annotation to the business code as needed.

[0137] In the business code, the watercode operation method is called through the WaterCodeService class instance to complete the business logic.

[0138] Through the above design, the system realizes the full process automation of serial code creation, management, and exception rollback. Combined with Redis's atomic operations, it ensures the uniqueness and continuity of serial codes in a distributed environment and data consistency in the event of exceptions.

[0139] The electronic device of the present invention includes a central processing unit (CPU), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) or loaded from a storage unit into a random access memory (RAM). In the RAM, various programs and data required for device operation can also be stored. The CPU, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.

[0140] Many components in a device are connected to the I / O interface, including: input units, such as a keyboard and mouse; output units, such as various types of displays and speakers; storage units, such as magnetic disks and optical disks; and communication units, such as network cards, modems, and wireless communication transceivers. The communication unit allows the device to exchange information / data with other devices via computer networks such as the Internet and / or various telecommunication networks.

[0141] The processing unit performs the various methods and processes described above, such as methods S1 to S5. For example, in some embodiments, methods S1 to S5 can be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program can be loaded and / or installed on the device via a ROM and / or a communication unit. When the computer program is loaded into the RAM and executed by the CPU, one or more steps of methods S1 to S5 described above can be performed. Alternatively, in other embodiments, the CPU can be configured to execute methods S1 to S5 by any other appropriate means (for example, by means of firmware).

[0142] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0143] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. Such program code can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0144] In the context of the present invention, machine-readable medium can be a tangible medium that can contain or store a program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0145] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and such modifications or substitutions are intended to be within the scope of protection of the present invention. Therefore, the scope of protection of the present invention shall be subject to the scope of protection of the claims.

Claims

1. A method for generating a continuous stream code, characterized in that: The method comprises the following steps: Constructing a serial code identifier, where each generated serial code corresponds to a unique serial code identifier; Based on the serial code identifier and Redis's auto-increment sequence, multiple serial code sequences are distributedly created in multiple Redis nodes and stored in corresponding Redis nodes respectively; According to the value selection rules, a preset number of serial code sequences are pre-fetched from the Redis node and cached; When receiving a request for generating a serial code, a serial code sequence is taken out from the cache as the generated serial code; If it is detected during the serial code generation process that the number of serial code sequences in the cache is less than the preset number, the serial code sequence is taken out from the Redis node for caching, and the number of serial code sequences in the cache is kept at the preset number.

2. The method for generating a continuous stream code according to claim 1, wherein: The serial code identifier includes a custom management identifier and an input parameter value. The custom management identifier is used to realize the unified management of the serial code identifier under the corresponding service demander. Different service demanders correspond to different custom management identifiers. The input parameter value includes one of the application ID, form ID, component ID and sequence information.

3. The method for generating a continuous stream code according to claim 1, wherein: In the process of distributed generation of serial code sequences, the consistent hashing algorithm is used to ensure that each Redis node is responsible for generating serial codes within a specific range. The following steps are included: Map all Redis nodes to a virtual hash ring using a hash function, where the hash value calculated by the hash function for the Redis node corresponds to its position on the virtual hash ring, and all nodes are evenly distributed on the virtual hash ring by setting virtual nodes; According to the node position on the virtual hash ring, a specific range of stream code sequences is assigned to each node, where the hash value interval between two adjacent nodes corresponds to a stream code sequence range, and the last node and the first node belong to two adjacent nodes.

4. The method for generating a continuous stream code according to claim 3, wherein: The distributed creation of multiple pipeline code sequences is specifically as follows: Based on the serial code identifier, the following steps are executed in a loop to create multiple serial code sequences: Perform hash calculation based on the information in the current serial code identifier to obtain the corresponding hash value; Based on the calculated hash value, search for the first Redis node that is greater than or equal to the hash value on the virtual hash ring; Use Redis's atomic operations on the found Redis node to generate the current serial code sequence.

5. The method for generating a continuous stream code according to claim 1, wherein: If a serial code anomaly is detected during the serial code generation process, the rollback mechanism is triggered. The corresponding serial code sequence in the Redis node is restored to the state before the anomaly occurs according to the recorded operation log, and the cache is updated according to the value selection rules to delete the abnormal serial code record.

6. The method for generating a continuous stream code according to claim 1, wherein: The method further comprises: Based on the dynamic priority queue mechanism, the processing priority is adjusted according to the urgency of the serial code generation request.

7. The method for generating a continuous stream code according to claim 1, wherein: The method further comprises: Set the modification interface to customize the currently generated serial code by modifying the value of the serial code identifier in the Redis node. During the modification process, the modified serial code identifier is verified. If the verification passes, the modified serial code is returned. Otherwise, an abnormal alarm is issued.

8. The method for generating a continuous stream code according to claim 1, wherein: The method further comprises: Set the reset time of the serial code sequence, embed reset time related information in the serial code identifier, automatically clear the expired serial code identifier in the Redis node and clear the cache at the reset time, and realize the regular reset of the serial code sequence.

9. An electronic device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the program, the method according to any one of claims 1 to 8 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.