Number generation method and apparatus, and electronic device and readable medium

By batch generating and saving numbers in a single-threaded database, the problem of long-term number allocation in the existing technology is solved, and a more efficient number allocation process is achieved.

WO2025113645A1PCT designated stage expired Publication Date: 2025-06-05BEIJING YOUZHUJU NETWORK TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/135700
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-11-30
Filing Date
2024-11-29
Publication Date
2025-06-05

AI Technical Summary

Technical Problem

The prior art takes a long time to assign numbers to objects, which affects efficiency, especially when the number to be allocated is insufficient.

Method used

By batch generating the numbers to be allocated in a single-threaded database and saving them in a collection, it is necessary to improve the efficiency of allocating numbers to objects. The specific method includes determining whether the set meets the number generation conditions, generating and saving the number until the set meets the conditions.

Benefits of technology

It realizes efficient when assigning numbers in objects, reduces the time to generate and check numbers, and improves the efficiency of number allocation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024135700_05062025_PF_FP_ABST
    Figure CN2024135700_05062025_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present disclosure are a number generation method and apparatus, and an electronic device and a readable medium. The method comprises: firstly, determining whether a first set in a single-thread database satisfies a number generation condition, if the condition is satisfied, generating a first number with a first value as the highest bit, and if it is determined that the first set does not comprise the first number, storing the first number in the first set, so as to obtain an updated first set; and then, determining whether the updated first set satisfies the number generation condition, if the condition is satisfied, returning to execute the generation of the first number with the first value as the highest bit and the subsequent steps, and if the condition is not satisfied, ending the process of generating numbers for the first set, wherein the number is a numeric character string that can uniquely identify an object. It can be seen that in the method, by means of a single-thread database and related components thereof, the strategy for generating numbers in batches and storing same in various sets is designed, such that sufficient numbers to be allocated are stored in various sets, thereby improving the efficiency of allocating numbers to objects.
Need to check novelty before this filing date? Find Prior Art

Description

Number generation method, device, electronic device and readable medium

[0001] This application claims priority to Chinese patent application No. 202311634951.X filed on November 30, 2023. The contents of the above-mentioned Chinese patent application disclosure are hereby incorporated by reference in their entirety as a part of this application. Technical Field

[0002] The present disclosure relates to a number generation method, device, electronic device and readable medium. Background Art

[0003] In order to help users better search for the objects they want, each object needs to be assigned a number that can uniquely identify the corresponding object. This number brings a certain degree of convenience to users when searching for objects. If a number is generated each time a number is required for an object, and the number is checked for availability, and the generated number is assigned to the corresponding object when it is determined that it is not used by other objects (i.e., the number is available), this process can achieve the purpose of assigning numbers to objects, but it is time-consuming, thereby affecting the efficiency of object number assignment. Summary of the Invention

[0004] In order to solve the above technical problems, the present disclosure provides a number generation method, device, electronic device and readable medium, which can batch generate numbers to be allocated and save them in a single-threaded database when the number of numbers to be allocated to objects is insufficient, so as to improve the efficiency of allocating numbers to objects.

[0005] In order to achieve the above objectives, the technical solutions provided by the present disclosure are as follows:

[0006] In a first aspect, the present disclosure provides a method for generating a number, wherein the number is a numerical string capable of uniquely identifying an object, comprising:

[0007] Determining whether a first set in a single-threaded database satisfies a number generation condition, the first set being used to store numbers with a first value as the highest digit, the first value being any natural number less than 10, the number generation condition being used to indicate that the number of numbers in the first set is insufficient, and the single-threaded database allows only one operation to be executed at a time;

[0008] If the first set satisfies the number generation condition, generating a first number with the first value as the highest digit; if it is determined that the first number is not included in the first set, saving the first number to the first set to obtain an updated first set;

[0009] Determine whether the updated first set meets the number generation condition. If so, return to execute the generation of the first number with the first value as the highest digit and subsequent steps. If not, end the process of generating numbers for the first set.

[0010] In some implementations, the first set satisfying the number generation condition includes:

[0011] The number of numbers in the first set is less than a preset number threshold;

[0012] And / or, the historical allocation speed of the first set is greater than a preset speed threshold, and the historical allocation speed is the ratio of the total number of numbers allocated to objects from the first set in a preset historical time period to the preset historical time period.

[0013] In some implementations, the single-threaded database is a Remote Dictionary Server (Redis), then,

[0014] Generating a first number with the first value as the highest digit includes:

[0015] Obtain at least one available coroutine from the Redis coroutine pool, and generate the first number for the at least one available coroutine;

[0016] The determining that the first set does not include the first number includes:

[0017] It is determined that the bit corresponding to the first number in the Redis bitmap is 0, and the bit can be successfully set to 1.

[0018] In some implementations, the method further includes:

[0019] In response to receiving a request to apply for a number for a target object, randomly generating a natural number less than 10, recorded as a second value;

[0020] Obtain a second number from a second set corresponding to the second value, where the second set is used to store numbers with the second value as the highest digit;

[0021] The second number is assigned to the target object.

[0022] In some implementations, before determining that the first set does not include the first number, the method further includes:

[0023] determining whether the first number exists in an allocation relationship table, where the allocation relationship table is used to store a correspondence between an object and a number that is allocated to the object and currently being used by the object;

[0024] If the first number does not exist in the allocation relationship table, executing the step of: if it is determined that the first set does not include the first number, saving the first number to the first set, and subsequent operations;

[0025] If the first number exists in the allocation relationship table, the step of saving the first number to the first set if it is determined that the first set does not include the first number, and subsequent operations are no longer performed.

[0026] In some implementations, before saving the first number to the first set, the method further includes:

[0027] If it is determined that the first set does not include the first number, the first indication information indicating that the first set does not include the first number is modified to second indication information, where the second indication information is used to indicate that the first set includes the first number.

[0028] In some implementations, the method further includes:

[0029] If the saving operation of saving the first number to the first set fails, a rollback operation is performed until the rollback operation succeeds or the rollback operation reaches a preset number of times, where each rollback operation includes: modifying the second indication information to the first indication information;

[0030] If the rollback operation is successful, returning to the step of generating the first number with the first value as the highest digit, and subsequent steps;

[0031] If the rollback operation is executed a preset number of times and the rollback operation is unsuccessful, a notification message is generated, where the notification message is used to instruct the second indication information to be forcibly modified to the first indication information.

[0032] In a second aspect, the present disclosure further provides a number generating device, wherein the number is a numerical string capable of uniquely identifying an object, including:

[0033] a first determining unit, configured to determine whether a first set in a single-threaded database satisfies a number generation condition, the first set being configured to store numbers with a first value as the highest digit, the first value being any natural number less than 10, the number generation condition being configured to indicate that the number of numbers in the first set is insufficient, and the single-threaded database is configured to allow only one operation to be executed at a time;

[0034] a generating unit, configured to generate a first number with the first value as the highest digit if the first set satisfies the number generation condition, and save the first number to the first set if it is determined that the first number is not included in the first set, thereby obtaining an updated first set;

[0035] The second judgment unit is used to judge whether the updated first set meets the number generation condition. If so, it returns to execute the generation of the first number with the first value as the highest digit and subsequent steps; if not, it ends the process of generating numbers for the first set.

[0036] In some implementations, the first set satisfying the number generation condition includes:

[0037] The number of numbers in the first set is less than a preset number threshold;

[0038] And / or, the historical allocation speed of the first set is greater than a preset speed threshold, and the historical allocation speed is the ratio of the total number of numbers allocated to objects from the first set in a preset historical time period to the preset historical time period.

[0039] In some implementations, the single-threaded database is Redis, then,

[0040] The generating subunit in the generating unit for generating a first number with the first value as the highest digit is specifically configured to:

[0041] Obtain at least one available coroutine from the Redis coroutine pool, and generate the first number for the at least one available coroutine;

[0042] The determining subunit in the generating unit, configured to determine that the first set does not include the first number, is specifically configured to:

[0043] It is determined that the bit corresponding to the first number in the Redis bitmap is 0, and the bit can be successfully set to 1.

[0044] In some implementations, the apparatus further includes:

[0045] A first obtaining unit is configured to randomly generate a natural number less than 10 in response to receiving a request for applying for a number for a target object, and record the number as a second value;

[0046] a second acquiring unit, configured to acquire a second number from a second set corresponding to the second value, wherein the second set is configured to store numbers with the second value as the highest digit;

[0047] An allocating unit is configured to allocate the second number to the target object.

[0048] In some implementations, the apparatus further includes:

[0049] a third determining unit, configured to determine, before determining that the first set does not include the first number, whether the first number exists in an allocation relationship table, the allocation relationship table being configured to store a correspondence between an object and a number that is allocated to the object and is currently being used by the object;

[0050] a first processing unit, configured to, if the first number does not exist in the allocation relationship table, execute the step of: if it is determined that the first set does not include the first number, saving the first number to the first set, and subsequent operations;

[0051] The second processing unit is configured to, if the first number exists in the allocation relationship table, no longer execute the step of saving the first number to the first set if it is determined that the first set does not include the first number, and subsequent operations.

[0052] In some implementations, the apparatus further includes:

[0053] A modification unit is used to modify first indication information indicating that the first set does not include the first number to second indication information before saving the first number to the first set, if it is determined that the first number is not included in the first set, wherein the second indication information is used to indicate that the first number is included in the first set.

[0054] In some implementations, the apparatus further includes:

[0055] a rollback unit, configured to, if the saving operation of saving the first number to the first set fails, perform a rollback operation until the rollback operation succeeds or the rollback operation reaches a preset number of times, wherein one rollback operation includes: modifying the second indication information to the first indication information;

[0056] a third processing unit, configured to return to executing the step of generating the first number with the first value as the highest digit, and subsequent steps if the rollback operation is successful;

[0057] A notification unit is used to generate a notification message if the rollback operation is executed a preset number of times and the rollback operation is unsuccessful, wherein the notification message is used to instruct the second indication information to be forcibly modified to the first indication information.

[0058] It should be noted that the specific implementation method of the device and the technical effects achieved can be found in the relevant description of the method provided in the first aspect or any implementation method of the first aspect.

[0059] In a third aspect, the present disclosure further provides an electronic device, the electronic device comprising: a processor and a memory;

[0060] The memory is used to store instructions or programs;

[0061] The processor is used to execute the instructions or programs in the memory so that the electronic device executes the method provided by the above-mentioned target aspect or any one of the implementations of the target aspect.

[0062] In a fourth aspect, the present disclosure further provides a readable medium storing instructions or programs, which, when executed on a processor, enable the processor to execute the method provided in the above-mentioned target aspect or any one of the implementations of the target aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0064] FIG1 is a schematic diagram of a network architecture adapted by the method provided in an embodiment of the present disclosure;

[0065] FIG2 is a flow chart of a number generation method provided by an embodiment of the present disclosure;

[0066] FIG3 is a flow chart of an example of a number generation method provided by an embodiment of the present disclosure;

[0067] FIG4 is a flow chart of another example of a number generation method provided by an embodiment of the present disclosure;

[0068] FIG5 is a schematic diagram of a number allocation process provided by an embodiment of the present disclosure;

[0069] FIG6 is a schematic structural diagram of a number generating device 600 provided in an embodiment of the present disclosure; and

[0070] FIG7 is a schematic structural diagram of an electronic device 700 provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0071] To enable users to search for objects simply and efficiently, in addition to more complex object identifiers such as object names and object numbers, objects are typically assigned a number. This number not only uniquely identifies the object but also facilitates searches for it due to its simplicity, ease of memorization, and ease of input. Objects can be, for example, goods or services, and the number assigned to an object can be a short numeric string consisting of Arabic numerals. For example, the number can be a 5- or 6-digit Arabic numeral. Object A's number can be 12345, and Object B's number can be 034567.

[0072] Currently, the process of allocating numbers to an object involves generating a number only when a number allocation request is received, then checking whether the generated number is available. If so, the number is allocated to the object requesting the number as a response to the number allocation request. Checking whether the generated number is available can be understood as checking whether the number has already been allocated to another object. If so, the number is determined to be unavailable; if not, the number is determined to be available. This process triggers number generation and number availability checks each time a number allocation request is requested, making number allocation to an object time-consuming. If a generated number is unavailable, another number must be generated and checked for availability until a usable number is generated. This increases the time consumption and the probability of number allocation requests failing.

[0073] In order to shorten the time consumption of number allocation, multiple available numbers can also be generated in batches and saved. This method can be understood as a number pre-generation method. At present, the process of generating and saving numbers corresponding to the number pre-generation method includes: after generating a number, first check whether the number is a number that has been assigned to the object. If so, skip the number and regenerate other numbers and execute this process. If not, then determine whether the number has been saved in the relational database. If the number has been saved in the relational database, skip the number and regenerate other numbers and execute this process. If the number is not saved in the relational database, the device that needs to execute the process first locks the relational database, and the device stores the number in the relational database. The locked relational database can only be operated by the device that performs the locking operation. Therefore, it can prevent multiple devices from storing the same number in the relational database. Accordingly, the number allocation process corresponding to the number pre-generation method includes: when a number allocation request occurs, first locking the relational database, then obtaining a number from multiple numbers pre-stored in the locked relational database, and then unlocking the relational database, thereby assigning the obtained number to the corresponding object as a response to the number allocation request. The locking operation in this process is to avoid assigning the same number in the relational database to multiple objects, because an unlocked relational database can be accessed by multiple devices. However, current number pre-generation methods mainly rely on relational databases. Therefore, when generating a number and storing it in the relational database and retrieving the number from the relational database, locking and unlocking operations are required, which is relatively time-consuming. In addition, in high-concurrency scenarios, the relational database is connected to multiple devices that can send number allocation requests. Too many connections may cause the number allocation request to time out, affecting the success rate of number allocation.

[0074] In the technical solution provided by the present disclosure, a number is a numerical string that can uniquely identify an object. A single-threaded database includes multiple sets, the highest bit of the numbers stored in each set is the same, and the method for generating numbers for each set is the same. Taking the generation of numbers in a first set with a first value as the highest bit as an example, an embodiment of the present disclosure provides a number generation method, which may include: first, a number generation device determines whether a first set (set) in the single-threaded database meets a number generation condition, the first set is used to store numbers with a first value as the highest bit, and the first value is any natural number less than 10, the number generation condition is used to indicate that the number of numbers in the first set is insufficient, and the single-threaded database only allows one operation to be executed at the same time; then, if the first set meets the number generation condition, the number generation device generates a first number with the first value as the highest bit; if it is determined that the first number is not included in the first set, the first number is saved in the first set to obtain an updated first set; then, the number generation device determines whether the updated first set meets the number generation condition, and if so, returns to executing the generation of the first number with the first value as the highest bit and subsequent steps; if not, the process of generating numbers for the first set is terminated.

[0075] In this way, the method uses a single-threaded database and its related components to design a strategy for batch generating numbers and storing them in a corresponding set of the single-threaded database, so that each set stores sufficient numbers to be allocated. Whenever there is a need to allocate numbers to an object, a number can be quickly and effectively allocated to the object directly from the sufficient number of numbers to be allocated stored in the corresponding set in the single-threaded database, without the need to generate numbers in real time and determine whether the generated numbers are available, thereby improving the efficiency of allocating numbers to the object.

[0076] As an example, a single-threaded database may be Redis, and Redis may implement the method provided by the embodiment of the present disclosure through related components (such as bitmap and set).

[0077] Before introducing the specific implementation of the number generation method provided by the embodiment of the present disclosure, in order to more clearly illustrate the technical solution provided by the embodiment of the present disclosure, the network architecture applicable to the technical solution provided by the embodiment of the present disclosure is first introduced in conjunction with Figure 1. Figure 1 takes Redis as an example of a single-threaded database for illustration.

[0078] As shown in Figure 1, the network architecture may include: server 10, device 21, device 22, ..., device 2N, where N is an integer greater than 1. Specifically, server 10 includes Redis 11, and devices 21 through 2N are all connected to server 10 to access Redis 11. Redis 11 components may include, for example, bitmap, set 0, set 1, ..., set 9. Optionally, Redis 11 components may also include coroutine 1, coroutine 2, ..., coroutine M, where M is an integer greater than 1. It should be noted that Redis 11, as a container for storing numbers, has higher query efficiency than MySQL (a relational database management system). Each bit in the bitmap indicates whether the number corresponding to that bit position has been generated and saved in a set. Sets 0 through 9 are used to store numbers starting with 0 through 9, respectively. Coroutines 1 through M are used to generate numbers, and M is typically set to a fixed value during initialization. This not only reduces overhead when creating and destroying programs, but also avoids the problem of excessive CPU load caused by an uncontrollable number of coroutines. It can be seen that the above components or features of Redis 11 can overcome the problems existing in the current number generation solution.

[0079] It should be noted that the Redis 11 of the server 10 has the function of generating and storing numbers; all or part of the devices 21 to 2N may have the function of requesting numbers, obtaining numbers from the Redis 11 of the server 10 to allocate to corresponding objects.

[0080] It should be noted that the subject implementing the number generation method may be the number generation device provided in the embodiments of the present disclosure. The number generation device may be carried in an electronic device or a functional module of the electronic device. The number generation device may, for example, correspond to Redis 11 in Figure 1, specifically the components and functional modules in Redis related to implementing the method provided in the embodiments of the present disclosure.

[0081] FIG2 is a flow chart of a number generation method provided by an embodiment of the present disclosure. This method can be applied to a number generation device, such as Redis 11 in FIG1 , or number generation device 600 shown in FIG6 . The following description uses the first set in Redis as an example. The number generation method for other sets is the same as the method shown in FIG2 , and any other set can be used as the first set to execute the method shown in FIG2 to generate a number.

[0082] As shown in FIG2 , the method may include, for example, the following S101 to S103:

[0083] S101, determine whether the first set in the single-threaded database meets the number generation condition, the first set is used to store numbers with the first value as the highest digit, the first value is any natural number less than 10, the number generation condition is used to indicate that the number of numbers in the first set is insufficient, and the single-threaded database only allows one operation to be executed at the same time.

[0084] It can be understood that in the embodiment of the present disclosure, the number generating device can determine whether the first set corresponding to the first value in the single-threaded database meets the preset number generation conditions. If so, the following S102 is executed to generate numbers for the first set, and the judgment step of S103 is executed; if not, the process of generating numbers for the first set in S102 is executed.

[0085] The following uses Redis as an example to illustrate the single-threaded database.

[0086] Redis can have multiple sets, which are components of Redis and can be used to store multiple numbers generated in batches in the embodiments of the present disclosure. As an example, in the embodiments of the present disclosure, 10 sets in Redis can be used: set 0, set 1, ..., set 9, each set is used to store numbers that start with a natural number less than 10 (or can also be called a natural number less than 10 as the highest digit), such as set 1 is used to store numbers that start with 1, ..., set 9 is used to store numbers that start with 9. Since the time complexity of storing numbers in a set in Redis and querying numbers from a set in Redis is O(1), O(1) can be understood as tasks such as storing numbers in a set in Redis or querying numbers from a set in Redis can be completed in an average of one operation. Therefore, compared with other ways of storing and querying numbers (such as ways of storing and querying numbers in a relational database), the execution efficiency is higher.

[0087] It should be noted that in the method shown in Figure 2, the first set is used to store numbers with the first value as the highest digit, and the first value is a natural number less than 10. The first set can be any set in Redis, and the first value is any natural number less than 10. The first value corresponds to the first set. For example, if the first value is 0, the first set is set 0, and the first set is used to store numbers with 0 as the highest digit. For another example, if the first value is 8, the first set is set 8, and the first set is used to store numbers with 8 as the highest digit.

[0088] It should be noted that the numbers mentioned in the embodiments of the present disclosure are numbers assigned to objects to uniquely identify them. The numbers are composed of several natural numbers less than 10, for example, a 5-digit or 6-digit number composed of 5 or 6 natural numbers less than 10. The length of the numbers stored in each set can be the same or different, without affecting the implementation of the embodiments of the present disclosure.

[0089] The number generation condition is a pre-configured condition for determining whether it is necessary to pre-generate numbers corresponding to a certain set and save them in the set. In the method shown in Figure 2, the number generation condition is used to indicate that the number of numbers to be assigned to the object in the first set is insufficient. If the first set meets the number generation condition, it means that the number of numbers saved in the first set is insufficient. In this case, it is necessary to generate numbers corresponding to the first set; conversely, if the first set does not meet the number generation condition, it means that the number of numbers saved in the first set is sufficient. In this case, it is temporarily not necessary to generate numbers corresponding to the first set. The number corresponding to the first set can be understood as the number with the first value corresponding to the first set as the highest digit. After generation, the number is saved in the first set.

[0090] It is understood that determining whether the number of numbers stored in the first set is sufficient can be based on the number of numbers stored in the first set, or can also be based on the rate of number consumption in the first set over a recent period (i.e., the historical allocation rate hereinafter). Therefore, number generation conditions may include, but are not limited to: the number of numbers to be allocated to the object in the set is less than a preset number threshold, and / or the historical allocation rate of the set is greater than a preset rate threshold, where the historical allocation rate is the ratio of the total number of numbers allocated to the object from the first set in a preset historical time period to the preset historical time period.

[0091] As an example, the number generating device can pre-configure a corresponding preset quantity threshold (such as 10,000) for each set. Corresponding to the method shown in Figure 2, the number generation condition can be: the number of numbers to be assigned to the object in the first set is less than the preset quantity threshold corresponding to the first set. For example, the number generating device determines that the number stored in the first set is 100, which is less than the preset quantity threshold of 10,000 corresponding to the first set. Therefore, it is determined that the first set meets the number generation condition, thereby triggering the execution of the following S102 to generate the number corresponding to the first set. It should be noted that the preset quantity threshold corresponding to each set can be the same or different. In the embodiment of the present disclosure, the preset quantity threshold corresponding to each set is the same as an example. The preset quantity threshold can be flexibly configured based on demand. For example, a reasonable preset quantity threshold can be configured based on the length of the number. If the number is 5 digits, the preset quantity threshold can be 10,000. If the number is 6 digits, the preset quantity threshold can be 100,000.

[0092] As another example, the number generating device may pre-configure a corresponding preset speed threshold (such as 1000 per second) for each set. Corresponding to the method shown in FIG2 , the number generation condition may be: the historical allocation speed in the first set is greater than the preset speed threshold corresponding to the first set. For example, the number generating device determines that the number allocation speed in the first set in the past 1 minute is 1100 per second, which is greater than the preset speed threshold corresponding to the first set of 1000 per second. Therefore, it is determined that the first set meets the number generation condition, thereby triggering the execution of the following S102 to generate the number corresponding to the first set. It should be noted that the preset speed threshold corresponding to each set may be the same or different. In the embodiment of the present disclosure, the preset speed threshold corresponding to each set is the same as an example for explanation. The preset speed threshold can be flexibly configured based on demand.

[0093] As another example, the number generating device may pre-configure a corresponding preset quantity threshold and preset speed threshold for each set. Corresponding to the method shown in FIG2 , the number generation condition may be: the number of numbers to be allocated to the object in the first set is less than the preset quantity threshold corresponding to the first set, and the speed at which the numbers of the first set are allocated is greater than the preset speed threshold. For example, the number generating device determines that the number stored in the first set is 100, and the historical allocation speed in the past minute is 1100 per second. Thus, it is determined that the number of numbers stored in the first set, 100, is less than the preset quantity threshold corresponding to the first set, 1000, and that the speed at which the numbers in the first set are allocated, 1100 per second, is greater than the preset speed threshold 1000 per second. That is, it is determined that the first set meets the number generation condition, thereby triggering the execution of the following S102 to generate numbers corresponding to the first set.

[0094] In some implementations, the method provided by the embodiments of the present disclosure may include: periodically traversing the number-related information in each set in Redis; then, S101 may, for example, include: judging whether the set meets the number generation condition based on the number-related information in each set. Here, judging whether the set meets the number generation condition based on the number-related information in each set may include: judging whether the first set meets the number generation condition based on the number-related information in the first set. As an example, Redis can trigger a query of the number-related information of each set in Redis through a scheduled task (such as a minute-level scheduled task), and judge whether each set meets the number generation condition accordingly. Here, the number-related information may correspond to different content depending on the number generation condition. For example, when the number generation condition includes the number of numbers to be allocated to an object in the set, the number-related information may include the number of numbers currently stored in the set; for another example, when the number generation condition includes the speed at which numbers in the set are allocated, the number-related information may include the number of numbers consumed in the set within a recent preset period of time or the historical allocation speed.

[0095] It can be seen that after the judgment of S101, if the judgment result is no, that is, the first set does not meet the number generation condition, the following S102 will not be executed; if the judgment result is yes, that is, the first set meets the number generation condition, the number generation process corresponding to the following S102 will be executed, and the judgment of S103 will continue to be executed. According to the judgment result of S103, it is determined whether to execute S102 again until the first set does not meet the number generation condition.

[0096] S102: If the first set meets the number generation condition, generate a first number with the first value as the highest digit; if it is determined that the first number is not included in the first set, save the first number to the first set to obtain an updated first set.

[0097] Among them, S102 may include: S1021, generating a first number with the first value as the highest digit; S1022, judging whether the first number is included in the first set; S1023, if it is determined that the first number is not included in the first set, saving the first number to the first set to obtain an updated first set.

[0098] As an example, after determining that the first set does not include the first number and before saving the first number to the first set, the method may further include: modifying the first indication information indicating that the first set does not include the first number to second indication information, where the second indication information is used to indicate that the first number is included in the first set. In this example, if the save operation of saving the first number to the first set in S1023 fails, a rollback operation is performed until the rollback operation is successful or the rollback operation reaches a preset number of times. A rollback operation includes: modifying the second indication information to the first indication information; if the rollback operation is successful, returning to execute S102; if the rollback operation is executed a preset number of times and the rollback operation is unsuccessful, generating a notification message, which is used to indicate that the second indication information is forcibly modified to the first indication information.

[0099] Taking Redis as a single-threaded database as an example, the implementation method of S102 is described.

[0100] A fixed number of coroutine pools can be set in Redis, and multiple coroutines in the coroutine pool can be used to implement step S1021 of generating a first number with the first value as the highest digit.

[0101] As an example, S1021 may include: first, obtaining at least one available coroutine from the Redis coroutine pool; then, generating a first number for the at least one available coroutine obtained. The number of available coroutines obtained in S1021 may determine the number of first numbers generated by executing S1021 once. For example, if one available coroutine is obtained in S1021, then one first number may be generated by executing S1021 once. For another example, if three available coroutines are obtained in S1021, then three first numbers may be generated by executing S1021 once.

[0102] It should be noted that the execution of S1021 requires not only the support of an available coroutine on Redis, but also a function corresponding to the generated number running on the available coroutine. The input parameter of this function may include the value of the highest digit (corresponding to the first value in this embodiment). Optionally, the input parameter of this function may also include a preset length of the number (such as 5 or 6). In this way, S1021 can generate a first number that meets the input parameter requirements of the function.

[0103] The Redis coroutine pool may be started in a non-blocking manner, that is, if no available coroutine is obtained in S1021 , the number generation process for generating the number with the first value as the highest digit is terminated.

[0104] For example, referring to FIG3 , the number generation process may include: S11, starting a scheduled task; S12, when the scheduled task is completed, traversing each set and obtaining the number-related information of each set; S13, judging whether each set meets the number generation conditions based on the number-related information of each set; if so, executing S14; otherwise, executing S16; S14, judging whether there is an available coroutine in the coroutine pool; if so, executing S15; otherwise, executing S16; S15, based on the first set that meets the number generation conditions, obtaining an available coroutine, and generating the first number based on the obtained available coroutine; S16, ending the number generation process. In this way, based on the process shown in FIG3 , a corresponding number can be generated for each set that meets the number generation conditions.

[0105] In some implementations, to ensure that the generated first number is an available number that can be subsequently assigned to an object, after S1021 and before S1022, the method may further include: determining whether the first number exists in the allocation relationship table; if the first number does not exist in the allocation relationship table, executing S1022-S1023; if the first number exists in the allocation relationship table, terminating the current number generation process and not executing the subsequent S1022-S1023. The allocation relationship table is used to store the correspondence between objects and numbers, and the correspondences in the allocation relationship table are all valid. In other words, the number generating device may also record the successfully assigned objects and numbers in the allocation relationship table. Numbers in the allocation relationship table cannot be saved in Redis as newly generated numbers, waiting to be assigned to other objects. Therefore, for the generated first number, it is only necessary to check whether the first number exists in the allocation relationship table to determine whether the first number is a number that can be subsequently assigned, providing a basis for whether to subsequently execute S1022-S1023.

[0106] Regarding S1022, determining whether the first set includes the first number, in the case where the single-threaded database is Redis, it may include: determining whether the bit corresponding to the first number in the bitmap of Redis is 0, and whether the bit can be successfully set to 1.

[0107] The bitmap in Redis consists of multiple bits, each of which is used to identify whether the number corresponding to the bit has been generated and saved in the corresponding set. For example, the 12345th bit in the bitmap is used to identify whether the number 12345 has been generated and saved in the corresponding set. When the number 12345 is not saved in set 1, the value of the 12345th bit in the bitmap is 0. When the first number 12345 is generated, the value of the 12345th bit in the bitmap is changed from 0 to 1. Since the time complexity of the bitmap in Redis is O(1) in the process of storing and querying numbers, it is more efficient than other ways of storing and querying numbers (such as the way of storing and querying numbers in relational databases).

[0108] As an example, the determination in S1022 can be performed by setting the bit corresponding to the first number in the Redis bitmap to determine whether the set operation is valid. The set operation can be implemented by a function corresponding to the set operation of the bitmap in Redis, such as setbitmap(). The input parameter of the function can include the first number, and the return value of executing the function can be used to indicate whether the set operation in S1022 is valid. The return value of this function may include: operation success or error. In the case of successful operation, the return value may include two situations: 0 or 1. When the return value is an error, it can be considered that the set operation is incorrect; when the return value is 1, it can be considered that the set operation is successful, but before the set operation, the bit corresponding to the first number in the Redis bitmap is 1, that is, the first number is a number that has been generated and saved in the corresponding set in Redis. To avoid repeated saving of the first number, there is no need to execute S1023; when the return value is 0, it can be considered that the set operation is successful, and the bit corresponding to the first number in the Redis bitmap before the set operation is 0, and after the set operation, the bit corresponding to the first number in the Redis bitmap is changed from 0 to 1, that is, the set operation is valid.

[0109] For S1023, the above setting operation can be used as a basis for determining that the first set does not include the first number. On this basis, the first number is saved to the first set, and an updated first set is obtained.

[0110] The setting operation is effective, which can be understood as follows: before the setting operation, the bit corresponding to the first number in the Redis bitmap is 0; after the setting operation, the bit corresponding to the first number in the Redis bitmap is changed from 0 to 1.

[0111] As an example, after S1022, it can be determined whether the setting operation in S1022 is valid. If so, S1023 is executed to save the first number into the first set. If the setting operation fails (also known as invalid), the number generation process ends. The failure of the setting operation may include the return value of the function corresponding to the setting operation reporting an error or returning 1.

[0112] If the save operation of saving the first number to the first set in S1023 succeeds, the number generation process is considered complete. If the save operation fails, a rollback operation can be performed on the bitmap setting operation in S1022 to avoid affecting the subsequent saving of the first number when the first number is regenerated. As an example, the method may also include: if the save operation of saving the first number to the first set in S1023 fails, a rollback operation is performed until the rollback operation succeeds or a preset number of rollback operations are performed. A rollback operation may include setting the bit corresponding to the first number in the Redis bitmap to 0. In one case, if a rollback operation fails and the number of rollback operations executed does not reach a preset number (such as 3 times), the next rollback operation is executed; in another case, if the rollback operation is successful, the next number generation process is started; in yet another case, if the rollback operation reaches a preset number (such as 3 times), a notification message is generated, which is used to indicate that the bit corresponding to the first number in the Redis bitmap is forcibly set to 0, and this forced setting can be modified by manual intervention of the staff.

[0113] For example, referring to FIG4 , for the first set that meets the number generation condition, the complete process of generating the number may include: S21, generating the first number with the first value as the highest bit; S22, judging whether the first number is in the allocation relationship table, if yes, returning to S21, if not, executing S23; S23, performing a set operation on the bit corresponding to the first number in the bitmap, and obtaining a return value A; S24, judging whether the set operation is valid according to the return value A, if the set operation is valid, executing S25, if the set operation is invalid, returning to S21; S25, executing a save operation to save the first number to the first set, and obtaining a return value B; S26, judging whether the save operation is successful according to the return value B, if successful, executing S27, as shown in FIG4 . If it fails, execute S29; S27, obtain the number-related information of the first set; S28, determine whether the first set meets the number generation conditions based on the number-related information of the first set, if yes, return to S21, if not, end; S29, perform a rollback operation on the setting operation of the first number on the bitmap, and obtain a return value C; S30, determine whether the rollback operation is successful based on the return value C, if successful, return to S21, if it fails and the number of rollback operations does not reach the preset number, return to S29, if it fails and the number of rollback operations reaches the preset number, execute S31; S31, generate a notification message to notify manual intervention, and forcibly set the bit corresponding to the first number in the Redis bitmap to 0. It can be seen that through this embodiment, numbers can be generated for the first set that does not have enough numbers to save and saved in the first set, so that the first set can save enough numbers, which is convenient for responding to number requests in high-concurrency scenarios and achieving efficient number allocation.

[0114] It can be seen that through S102, when the first set meets the number generation condition, the process of generating numbers for the first set is completed once, which enriches the number quantity in the first set and prepares for efficient number allocation.

[0115] S103, determining whether the updated first set meets the number generation condition; if so, returning to execute the step of generating the first number with the first value as the highest digit and subsequent steps; if not, ending the process of generating numbers for the first set.

[0116] It is understandable that after obtaining the updated first set through S102, it is possible to continue to determine whether the updated first set meets the number generation conditions. If so, it is possible to return to execute S102 and continue to enrich the number of numbers in the first set. If not, it is considered that numbers may not be generated for the first set temporarily.

[0117] It can be seen that through this method, with the help of a single-threaded database (such as Redis) and its related components, a strategy for batch generating numbers and storing them in each collection of the single-threaded database is designed, so that sufficient numbers to be assigned are stored in the collection. Every time there is a need to assign numbers to objects, numbers can be quickly and effectively assigned to the objects directly from the sufficient number of numbers to be assigned stored in the corresponding collection, without the need to generate numbers in real time and determine whether the generated numbers are available, thereby improving the efficiency of assigning numbers to objects.

[0118] In some implementations, embodiments of the present disclosure also provide a process for allocating pre-generated numbers stored in a single-threaded database. As an example, the method may further include: S105, in response to receiving a request for a number for a target object, randomly generating a natural number less than 10, denoted as a second value; S106, obtaining a second number from a second set of numbers to be allocated to the object corresponding to the second value in the single-threaded database, the second set being used to store numbers with the second value as the highest bit; and S107, allocating the second number to the target object. Furthermore, if the single-threaded database is Redis, a bitmap in Redis records whether the number is stored in Redis. During S107, the bit corresponding to the second number in the Redis bitmap may be set to 0. Optionally, after S107, the correspondence between the target object and the second number may be stored in an allocation relationship table. This allows accurate determination of whether the second number has been allocated based on the allocation relationship table when subsequently generating the second number, thereby further improving the effectiveness of the number generation method provided by embodiments of the present disclosure.

[0119] The second value may be any one of the 10 natural numbers from 0 to 9, and the second value may be the same as or different from the first value, which does not affect the implementation of the embodiment of the present disclosure.

[0120] Taking Redis as a single-threaded database as an example, S106 to S107 are explained.

[0121] S106 can be implemented by a read function for reading a number from a Redis set, where the input parameter of the read function includes at least the identifier of the second set. The read function can be, for example, pop(), where the input parameter of pop() includes the identifier of the second set, set 2. Then, S106 can include, for example: executing pop(set 2), where the output parameter of pop(set 2) includes the second number.

[0122] For S107, on the one hand, Redis can assign the second number to the target object and send the second number to the requesting party (such as any one of device 1 to device n in Figure 1) so that the requesting party can assign the second number to the target object; on the other hand, Redis can set the bit position corresponding to the second number in the Redis bitmap to 0 to indicate that the second number is no longer the number to be assigned to the object in Redis.

[0123] It should be noted that, when the operation of setting the bit position corresponding to the second number in the bitmap of Redis to 0 in S107 fails, the operation can be repeated until the number of repetitions reaches the maximum number of repetitions allowed for the operation or the operation succeeds. If the operation still fails after the number of repetitions reaches the maximum number of repetitions allowed for the operation, a notification message can be generated. The notification message is used to indicate that the bit corresponding to the second number in the bitmap of Redis is forcibly set to 0. The forced setting can be modified by manual intervention of the staff.

[0124] For example, referring to FIG5 , the allocation process for the pre-generated numbers stored in Redis may include: S41, generating a random number from 0 to 9, recorded as the second value; S42, executing an acquisition operation of acquiring the second number from the second set corresponding to the second value, and obtaining a return value D; S43, judging whether the acquisition operation is successful according to the return value D, if unsuccessful, executing S49, if successful, executing S44; S44, executing a reset operation of the bit position corresponding to the second number in the Redis bitmap to 0, and obtaining a return value E; S45, judging whether the reset operation is successful according to the return value E, if successful, ending the allocation process, if unsuccessful, executing repeated operations of S46 to S48; S46, executing repeated operations of the above reset operation, and obtaining a return value F; S47, judging whether the repeated operation is successful according to the return value F. Whether the operation is successful, if successful, then end the allocation process, if it fails and the number of repeated operations does not reach the preset maximum number of allowed repeated operations, then return to S46, if it fails and the number of repeated operations reaches the preset maximum number of allowed repeated operations, then execute S48; S48, generate a notification message to notify manual intervention, and force the bit corresponding to the second number in the Redis bitmap to be set to 0; S49, if the number of numbers saved in the second set in Redis is 0 (that is, the second set is empty) due to the speed of requesting numbers being higher than the speed of number generation, then execute the degradation strategy for extreme cases, that is, after generating the number according to the method provided in the embodiment of the present disclosure, directly assign the number to the object requesting the number without saving the number in the corresponding set, so as to improve the number allocation efficiency in this extreme case. In this way, through this embodiment, efficient allocation of numbers saved in Redis is achieved, and the efficiency of allocating numbers to objects is improved, which is particularly suitable for high concurrency (that is, multiple requesting parties request numbers from Redis at the same time) scenarios.

[0125] It should be noted that the number allocation scheme corresponding to S105 to S107 can be a follow-up to the number generation method shown in FIG2 , or can be implemented as a separate embodiment to achieve the effect of efficiently requesting numbers from a single-threaded database.

[0126] It should be noted that a number assigned to an object can be permanently bound to the object; a validity period (e.g., three months) can be set for the binding, with the binding automatically terminated upon expiration; or the binding can be terminated for other reasons (e.g., user application). After the binding is terminated, the corresponding relationship in the allocation relationship table associated with the binding can be deleted or set to an invalid state. The numbers in the invalid corresponding relationship are considered to be non-existent in the allocation relationship table.

[0127] After the binding relationship is untied, the bit position corresponding to the number in the bitmap can be set to 0, allowing the number to be pre-generated and saved again in the single-threaded database according to the method provided in the embodiment of the present disclosure. The timing of executing the two operations of untiing the binding relationship and setting the bit position corresponding to the number in the bitmap to 0 can be, in one case, directly executing the operation of setting the bit position corresponding to the number in the bitmap to 0 after the binding relationship is untied; in another case, a buffer time interval (such as 5 days) can be set, and the operation of setting the bit position corresponding to the number in the bitmap to 0 can be executed after the buffer time interval has passed after the untiing relationship starts.

[0128] Accordingly, the embodiment of the present disclosure further provides a number generating device 600, as shown in Figure 6. In the device 600, the number is a numerical string that can uniquely identify an object. The device 600 may include:

[0129] A first determination unit 601 is configured to determine whether a first set in a single-threaded database satisfies a number generation condition, wherein the first set is configured to store numbers with a first value as the highest digit, the first value being any natural number less than 10, the number generation condition indicating that the number of numbers in the first set is insufficient, and the single-threaded database allows only one operation to be executed at a time;

[0130] A generating unit 602 is configured to generate a first number with the first value as the highest digit if the first set satisfies the number generation condition, and save the first number to the first set to obtain an updated first set if it is determined that the first number is not included in the first set;

[0131] The second judgment unit 603 is used to judge whether the updated first set meets the number generation condition. If so, it returns to execute the generation of the first number with the first value as the highest digit and subsequent steps; if not, it ends the process of generating numbers for the first set.

[0132] In some implementations, the first set satisfying the number generation condition includes:

[0133] The number of numbers in the first set is less than a preset number threshold;

[0134] And / or, the historical allocation speed of the first set is greater than a preset speed threshold, and the historical allocation speed is the ratio of the total number of numbers allocated to objects from the first set in a preset historical time period to the preset historical time period.

[0135] In some implementations, the single-threaded database is Redis, then,

[0136] The generating subunit in the generating unit 602 for generating the first number with the first value as the highest digit is specifically configured to:

[0137] Obtain at least one available coroutine from the Redis coroutine pool, and generate the first number for the at least one available coroutine;

[0138] The determining subunit in the generating unit 602, configured to determine that the first set does not include the first number, is specifically configured to:

[0139] It is determined that the bit corresponding to the first number in the Redis bitmap is 0, and the bit can be successfully set to 1.

[0140] In some implementations, the apparatus 600 further includes:

[0141] A first obtaining unit is configured to randomly generate a natural number less than 10 in response to receiving a request for applying for a number for a target object, and record the number as a second value;

[0142] a second acquiring unit, configured to acquire a second number from a second set corresponding to the second value, wherein the second set is configured to store numbers with the second value as the highest digit;

[0143] An allocating unit is configured to allocate the second number to the target object.

[0144] In some implementations, the apparatus 600 further includes:

[0145] a third determining unit, configured to determine, before determining that the first set does not include the first number, whether the first number exists in an allocation relationship table, the allocation relationship table being configured to store a correspondence between an object and a number that is allocated to the object and is currently being used by the object;

[0146] a first processing unit, configured to, if the first number does not exist in the allocation relationship table, execute the step of: if it is determined that the first set does not include the first number, saving the first number to the first set, and subsequent operations;

[0147] The second processing unit is configured to, if the first number exists in the allocation relationship table, no longer execute the step of saving the first number to the first set if it is determined that the first set does not include the first number, and subsequent operations.

[0148] In some implementations, the apparatus 600 further includes:

[0149] A modification unit is used to modify first indication information indicating that the first set does not include the first number to second indication information before saving the first number to the first set, if it is determined that the first number is not included in the first set, wherein the second indication information is used to indicate that the first number is included in the first set.

[0150] In some implementations, the apparatus 600 further includes:

[0151] a rollback unit, configured to, if the saving operation of saving the first number to the first set fails, perform a rollback operation until the rollback operation succeeds or the rollback operation reaches a preset number of times, wherein one rollback operation includes: modifying the second indication information to the first indication information;

[0152] a third processing unit, configured to return to executing the step of generating the first number with the first value as the highest digit, and subsequent steps if the rollback operation is successful;

[0153] A notification unit is used to generate a notification message if the rollback operation is executed a preset number of times and the rollback operation is unsuccessful, wherein the notification message is used to instruct the second indication information to be forcibly modified to the first indication information.

[0154] It should be noted that the specific implementation of the device 600 and the technical effects achieved can be found in the relevant description of the method shown in FIG2 .

[0155] In addition, an embodiment of the present disclosure also provides an electronic device, which includes a processor and a memory: the memory is used to store instructions or computer programs; the processor is used to execute the instructions or computer programs in the memory, so that the electronic device executes any implementation of the method provided in the embodiment of the present disclosure.

[0156] Referring to FIG7 , a schematic diagram of the structure of an electronic device 700 suitable for implementing an embodiment of the present disclosure is shown. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. The electronic device shown in FIG7 is merely an example and should not limit the functionality or scope of use of the embodiments of the present disclosure.

[0157] As shown in Figure 7, electronic device 700 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 into a random access memory (RAM) 703. Various programs and data required for the operation of electronic device 700 are also stored in RAM 703. Processing device 701, ROM 702, and RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to bus 704.

[0158] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data. Although FIG. 7 shows the electronic device 700 with various devices, it should be understood that not all of the devices shown are required to be implemented or present. More or fewer devices may be implemented or present instead.

[0159] For example, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 709, or installed from the storage device 708, or installed from the ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.

[0160] The electronic device provided by the embodiment of the present disclosure and the method provided by the above embodiment belong to the same inventive concept. For technical details not fully described in this embodiment, please refer to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.

[0161] The embodiments of the present disclosure further provide a computer-readable medium, in which instructions or computer programs are stored. When the instructions or computer programs are executed on a device, the device executes any implementation of the method provided in the embodiments of the present disclosure.

[0162] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or component. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.

[0163] In some embodiments, the client and server can communicate using any currently known or later developed network protocol, such as HTTP (Hypertext Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or later developed network.

[0164] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0165] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device can perform the method.

[0166] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0167] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0168] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a unit / module does not, in some cases, limit the unit itself.

[0169] The functions described above in the present disclosure 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 chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0170] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0171] It should be noted that the various embodiments of this disclosure are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the descriptions of the systems or devices disclosed in the embodiments for similarities and differences between them. Since the systems or devices disclosed in the embodiments correspond to the methods disclosed in the embodiments, their descriptions are relatively simple, and reference can be made to the descriptions of the methods for any related details.

[0172] It should be understood that in the present disclosure, "at least one (item)" refers to one or more, and "plurality" refers to two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can represent: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0173] It should also be noted that, in the present disclosure, relational terms such as first and second, etc., are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variants thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the statement "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0174] The steps of the methods or algorithms described in conjunction with the embodiments of the present disclosure may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0175] It should be noted that in the embodiments of the present disclosure, user sensitive information is not involved, and user-related information is obtained, used and determined after user authorization. In one example, before obtaining user-related information, the corresponding interface displays prompt information related to obtaining data use authorization. This prompt information is based on relevant laws and regulations and informs the user of the type, scope of use, usage scenarios, etc. of the personal information involved in this disclosure in an appropriate manner, so that the user can determine whether to agree to the authorization based on the prompt information. It can be understood that the above-mentioned notification and the process of obtaining user authorization are only illustrative and do not constitute a limitation on the implementation method of the present disclosure. Other methods that meet relevant laws and regulations can also be applied to the implementation method of the present disclosure.

[0176] The above description of the embodiments of the present disclosure is intended to enable those skilled in the art to implement or use the present disclosure. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined in this disclosure may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not limited to the embodiments shown herein, but is intended to be applied in the widest manner consistent with the principles and novel features of the present disclosure.

Claims

1. A method for generating a number, wherein: The number is a numerical string that can uniquely identify an object, and the method includes: Determine whether a first set in a single-thread database satisfies a number generation condition, the first set being used to store numbers with a first value as the highest digit, the first value being any one of natural numbers less than 10, the number generation condition being used to indicate that the number of numbers in the first set is insufficient, and the single-thread database allows only one operation to be executed at the same time; If the first set satisfies the number generation condition, generating a first number with the first value as the highest digit; if it is determined that the first set does not include the first number, saving the first number to the first set to obtain an updated first set; Determine whether the updated first set meets the number generation condition. If so, return to execute the generation of the first number with the first value as the highest digit and subsequent steps. If not, end the process of generating numbers for the first set.

2. The method according to claim 1, wherein: The first set satisfies the number generation condition including: The number of numbers in the first set is less than a preset number threshold; And / or, the historical allocation speed of the first set is greater than a preset speed threshold, and the historical allocation speed is the ratio of the total number of numbers allocated to objects from the first set in a preset historical time period to the preset historical time period.

3. The method according to claim 1 or 2, wherein: The single-threaded database is the remote dictionary service Redis; Generating a first number with the first value as the highest digit comprises: Obtain at least one available coroutine from the coroutine pool of the Redis, and generate the first number on the at least one available coroutine; The determining that the first set does not include the first number comprises: It is determined that the bit corresponding to the first number in the bitmap of the Redis is 0, and the bit can be successfully set to 1.

4. The method according to any one of claims 1 to 3, further comprising: In response to receiving a request for applying for a number for a target object, randomly generating a natural number less than 10, recorded as a second value; Obtain a second number from a second set corresponding to the second value, where the second set is used to store numbers with the second value as the highest digit; The second number is assigned to the target object.

5. The method according to any one of claims 1 to 4, wherein: Before determining that the first set does not include the first number, the method further includes: Determine whether the first number exists in an allocation relationship table, where the allocation relationship table is used to store a correspondence between an object and a number that is allocated to the object and is being used by the object; If the first number does not exist in the allocation relationship table, executing the if it is determined that the first set does not include the first number, saving the first number to the first set, and subsequent operations; If the first number exists in the allocation relationship table, if it is determined that the first set does not include the first number, saving the first number to the first set and subsequent operations are no longer performed.

6. The method according to any one of claims 1 to 5, wherein: Before storing the first number in the first set, the method further includes: If it is determined that the first set does not include the first number, the first indication information indicating that the first set does not include the first number is modified to second indication information, where the second indication information is used to indicate that the first set includes the first number.

7. The method according to claim 6, further comprising: If the saving operation of saving the first number to the first set fails, a rollback operation is performed until the rollback operation succeeds or the rollback operation reaches a preset number of times, and one rollback operation includes: modifying the second indication information to the first indication information; If the rollback operation is successful, returning to execute the step of generating the first number with the first value as the highest digit, and subsequent steps; If the rollback operation is executed a preset number of times and the rollback operation is unsuccessful, a notification message is generated, where the notification message is used to instruct that the second indication information is forcibly modified to the first indication information.

8. A number generating device, wherein: The number is a numerical string that can uniquely identify an object, and the device includes: a first judging unit, configured to judge whether a first set in a single-thread database satisfies a number generation condition, the first set being used to store numbers with a first value as the highest digit, the first value being any one of natural numbers less than 10, the number generation condition being used to indicate that the number of numbers in the first set is insufficient, and the single-thread database is only allowed to execute one operation at the same time; a generating unit configured to generate a first number with the first value as the highest digit if the first set satisfies the number generation condition, and save the first number to the first set if it is determined that the first number is not included in the first set, so as to obtain an updated first set; The second judgment unit is configured to judge whether the updated first set satisfies the number generation condition. If so, it returns to execute the generation of the first number with the first value as the highest digit and subsequent steps. If not, it ends the process of generating numbers for the first set.

9. An electronic device comprising a processor and a memory, wherein: The memory is configured to store instructions or programs; The processor is configured to execute the instructions or programs in the memory so that the electronic device executes the number generating method according to any one of claims 1 to 7.

10. A readable medium storing instructions or programs, wherein: When the instruction or program runs on a processor, the processor is enabled to execute the number generating method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Identity card number identification method and apparatus, and electronic device

    CN112380211A

  • Short link generation method and device, equipment and storage medium

    CN113378083A

  • Task processing method and device, electronic equipment and computer readable storage medium

    CN114048265A

  • Resource allocation method and device, electronic equipment and storage medium

    CN115423515A

  • Method, apparatus, device and storage medium for testing code

    US20210326248A1