Number generation method and device, electronic equipment 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.
Patent Information
- Application Number
- CN202311634951.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-30
- Publication Date
- 2025-05-30
AI Technical Summary
The prior art takes a long time to assign numbers to objects, which affects efficiency, especially when the number to be allocated is insufficient.
By batch generating the numbers to be allocated in a single-threaded database and saving them in the corresponding set, the efficiency of allocating numbers to objects is improved. The specific method includes determining whether the set meets the number generation conditions, generating and saving the number until the set meets the conditions.
It realizes efficient when assigning numbers in objects, reduces the time to generate and check numbers in real time, and improves the efficiency of number allocation.
Smart Images

Figure CN120068801A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular, to a method, device, electronic device, and readable medium for generating numbers. Background Art
[0002] In order to enable users to better search for the objects they want to search for, it is necessary to configure numbers that can uniquely identify the corresponding objects for each object. This number brings a certain degree of convenience for users to search for objects. If a number is generated every time there is a need to assign a number to an object and it is checked whether this number is available, and when it is determined that the generated number is not used by other objects (i.e., the number is available), the number is assigned to the corresponding object. Although this process can achieve the purpose of assigning numbers to objects, it takes a long time, thus affecting the efficiency of assigning numbers to objects. Summary of the Invention
[0003] In order to solve the above technical problems, the present application provides a method, device, electronic device, and readable medium for generating numbers, which can batch generate numbers to be assigned and save them in a single-threaded database when the number of numbers to be assigned to objects is insufficient, so as to improve the efficiency of assigning numbers to objects.
[0004] In order to achieve the above object, the technical solutions provided by the present application are as follows:
[0005] In a first aspect, the present application provides a method for generating numbers, where the number is a numerical string that can uniquely identify an object, including:
[0006] Determine whether a first set in a single-threaded database meets the number generation condition. The first set is used to save numbers with a first value as the highest digit, the first value is any one of natural numbers less than 10, and the number generation condition is used to indicate that the number of numbers in the first set is insufficient. The single-threaded database only allows one operation to be executed at the same time;
[0007] 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;
[0008] Determine whether the updated first set meets the number generation condition. If it meets, return to execute the step of generating the first number with the first value as the highest digit and subsequent steps. If it does not meet, end the process of generating numbers for the first set.
[0009] In some implementation manners, the first set meets the number generation condition including:
[0010] The number of numbers in the first set is less than a preset number threshold;
[0011] And / or, the historical allocation speed of the first set is greater than a preset speed threshold, where the historical allocation speed is the ratio of the total number of numbers allocated from the first set to objects within a preset historical time period to the preset historical time period.
[0012] In some implementation manners, the single-threaded database is a Remote Dictionary Server (Redis). Then,
[0013] Generating the first number with the first value as the highest bit includes:
[0014] Obtaining at least one available coroutine from the coroutine pool of the Redis, and generating the first number on the at least one available coroutine;
[0015] Determining that the first set does not include the first number includes:
[0016] Determining that the bit corresponding to the first number in the bitmap of the Redis is 0 and that this bit can be successfully set to 1.
[0017] In some implementation manners, the method further includes:
[0018] In response to receiving a request to apply for a number for a target object, randomly generating a natural number less than 10, denoted as a second value;
[0019] Obtaining 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 bit;
[0020] Allocating the second number to the target object.
[0021] In some implementation manners, before determining that the first set does not include the first number, the method further includes:
[0022] Judging whether the first number exists in an allocation relation table, where the allocation relation table is used to store the correspondence between an object and the number allocated to this object and being used by this object;
[0023] If the first number does not exist in the allocation relation table, then execute the operation of, if it is determined that the first set does not include the first number, then saving the first number to the first set, and subsequent operations;
[0024] If the first number exists in the allocation relation table, the subsequent operations such as saving the first number to the first set if it is determined that the first set does not include the first number will no longer be executed.
[0025] In some implementations, before saving the first number to the first set, the method further includes:
[0026] If it is determined that the first set does not include the first number, modify 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 set includes the first number.
[0027] In some implementations, the method further includes:
[0028] If the save operation of saving the first number to the first set fails, perform a rollback operation until the rollback operation is successful or the number of executions of the rollback operation reaches a preset number. One rollback operation includes: modifying the second indication information to the first indication information;
[0029] If the rollback operation is successful, return to execute generating the first number with the first value as the highest bit and subsequent steps;
[0030] If the number of executions of the rollback operation reaches the preset number and the rollback operations are not successful, generate a notification message, where the notification message is used to indicate forcibly modifying the second indication information to the first indication information.
[0031] In a second aspect, the present application further provides a number generation device, where the number is a numerical string that can uniquely identify an object, including:
[0032] A first determination unit, configured to determine whether a first set in a single-threaded database meets the number generation condition. The first set is used to save numbers with the first value as the highest bit, the first value is any one of natural numbers less than 10, and the number generation condition is used to indicate that the number of numbers in the first set is insufficient. The single-threaded database only allows one operation to be executed at the same time;
[0033] A generation unit, configured to, if the first set meets the number generation condition, generate a first number with the first value as the highest bit, and if it is determined that the first set does not include the first number, save the first number to the first set to obtain an updated first set;
[0034] A second judgment unit, configured to judge whether the updated first set meets the number generation condition. If it meets, return to execute the generation of the first number with the first value as the highest digit and subsequent steps. If it does not meet, end the process of generating numbers for the first set.
[0035] In some implementation manners, that the first set meets the number generation condition includes:
[0036] The number of numbers in the first set is less than a preset number threshold;
[0037] And / or, the historical allocation speed of the first set is greater than a preset speed threshold, where the historical allocation speed is the ratio of the total number of numbers allocated to objects from the first set within a preset historical time period to the preset historical time period.
[0038] In some implementation manners, if the single-threaded database is Redis, then,
[0039] The generation subunit in the generation unit for generating the first number with the first value as the highest digit is specifically configured to:
[0040] Obtain at least one available coroutine from the coroutine pool of Redis, and generate the first number on the at least one available coroutine;
[0041] The determination subunit in the generation unit for determining that the first set does not include the first number is specifically configured to:
[0042] Determine that the bit corresponding to the first number in the bitmap of Redis is 0 and can be successfully set to 1.
[0043] In some implementation manners, the device further includes:
[0044] A first acquisition unit, 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, denoted as a second value;
[0045] A second acquisition unit, configured to acquire 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;
[0046] An allocation unit, configured to allocate the second number to the target object.
[0047] In some implementation manners, the device further includes:
[0048] A third determination unit, configured to determine whether the first number exists in an allocation relationship table before determining that the first set does not include the first number, where the allocation relationship table is used to store the correspondence between an object and the number assigned to the object and currently used by the object;
[0049] A first processing unit, configured to, if the first number does not exist in the allocation relationship table, execute the operation 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;
[0050] A second processing unit, configured to, if the first number exists in the allocation relationship table, no longer execute the operation 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] In some implementation manners, the apparatus further includes:
[0052] A modification unit, configured to, before saving the first number to the first set, if it is determined that the first set does not include the first number, modify 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 set includes the first number.
[0053] In some implementation manners, the apparatus further includes:
[0054] A rollback unit, configured to, if the save operation of saving the first number to the first set fails, perform a rollback operation until the rollback operation is successful or the number of times of the rollback operation reaches a preset number of times. One rollback operation includes: modifying the second indication information to the first indication information;
[0055] A third processing unit, configured to, if the rollback operation is successful, return to execute the operation of generating the first number with the first value as the highest bit and subsequent steps;
[0056] A notification unit, configured to, if the number of times of executing the rollback operation reaches the preset number of times and the rollback operations are not successful, generate a notification message, where the notification message is used to indicate that the second indication information is forced to be modified to the first indication information.
[0057] It should be noted that for the specific implementation manner of the apparatus and the achieved technical effects, reference may be made to the relevant descriptions of the method provided in the first aspect or any implementation manner of the first aspect.
[0058] In a third aspect, the present application further provides an electronic device, where the electronic device includes: a processor and a memory;
[0059] The memory is used to store instructions or programs;
[0060] 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 implementation manners of the target aspect.
[0061] In a fourth aspect, the present application further provides a readable medium, in which instructions or programs are stored. When the instructions or programs run on a processor, the processor is caused to execute the method provided by the above-mentioned target aspect or any one of the implementation manners of the target aspect.
[0062] Compared with the prior art, the embodiments of the present application have at least the following advantages:
[0063] In the technical solution provided by the present application, the number is a numerical string that can uniquely identify an object. The single-threaded database includes multiple sets, and the highest digits of the numbers saved in each set are the same. The method for generating numbers for each set is the same. Taking the generation of numbers in the first set with the first value as the highest digit as an example, the method for generating numbers provided by the present application may include: First, the number generation device determines whether the first set in the single-threaded database meets the number generation condition. The first set is used to save numbers with the first value as the highest digit, and the first value is any one of natural numbers less than 10. The number generation condition is used to indicate that the number of numbers in the first set is insufficient. 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 digit. If it is determined that the first number is not included in the first set, the first number is saved to 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. If it meets, it returns to execute the step of generating the first number with the first value as the highest digit and subsequent steps. If it does not meet, the process of generating numbers for the first set ends. In this way, in this method, by means of the single-threaded database and its related components, a strategy for batch generating numbers and saving them in the corresponding sets of the single-threaded database is designed, so that each set stores sufficient numbers to be allocated. Each time there is a need to allocate a number to an object, a number can be quickly and effectively allocated to the object directly from the sufficient numbers to be allocated saved in the corresponding set of the single-threaded database, without having to generate numbers in real time and determine whether the generated numbers are available. Therefore, the efficiency of allocating numbers to objects is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments recorded in the present application. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.
[0065] Figure 1 Schematic diagram of a network architecture adapted to the method provided by the embodiment of the present application;
[0066] Figure 2 Schematic flowchart of a number generation method provided by the embodiment of the present application;
[0067] Figure 3 Schematic flowchart of an example of a number generation method provided by the embodiment of the present application;
[0068] Figure 4 Schematic flowchart of another example of a number generation method provided by the embodiment of the present application;
[0069] Figure 5 Schematic diagram of a number allocation process provided by the embodiment of the present application;
[0070] Figure 6 Schematic diagram of the structure of a number generation device 600 provided by the embodiment of the present application;
[0071] Figure 7 Schematic diagram of the structure of an electronic device 700 provided by the embodiment of the present application. Detailed implementation
[0072] In order for users to search for objects simply and effectively, usually, in addition to relatively complex object identifiers such as object names and object numbers, a number is also assigned to the object. This number can not only uniquely identify the object, but also, due to its simplicity, easy memorability, and easy input, etc., can be conveniently used by users to search for the object. The object can be, for example, a commodity or a service. The number assigned to the object can be a numerical string composed of relatively short Arabic numerals. For example, the number can be 5 - or 6 - digit Arabic numerals. The number of object A can be 12345, and the number of object B can be 034567.
[0073] Currently, the process of allocating a number to an object includes: generating a number only when there is a number allocation request, and then checking whether the generated number is available. If it is available, the number is allocated to the object requesting the number as a response to the number allocation request. Among them, checking whether the generated number is available can be understood as checking whether the number has been allocated to other objects. If so, it is determined that the number is unavailable; if not, it is determined that the number is available. In this process, each time there is a need for number allocation, the generation of the number and the check of its availability are triggered, resulting in a relatively long time-consuming for allocating numbers to objects. If the number generated at one time is unavailable, another number needs to be regenerated, and it is necessary to check whether the newly generated number is available until an available number is generated, which increases the time consumption and the probability of failure of the number allocation request.
[0074] To shorten the time-consuming of number allocation, multiple available numbers can also be generated and saved in batches, which can be understood as a number pre-generation method. Currently, the process of generating and saving numbers corresponding to the number pre-generation method includes: after generating a number, first checking whether the number has been allocated to an object. If so, skip this number and regenerate other numbers to 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 this number and regenerate other numbers to execute this process; if the number has not been saved in the relational database, the device that needs to execute this process first performs a locking operation on the relational database, and the device stores the number in the relational database. Since the relational database in the locked state can only be operated by the device that performs the locking operation, it can be avoided that multiple devices store the same number in the relational database. Correspondingly, the process of allocating numbers corresponding to this number pre-generation method includes: when there is a number allocation request, first perform a locking operation on the relational database, then obtain a number from the multiple numbers pre-saved in the locked relational database, and then perform an unlocking operation on the relational database. Thus, the obtained number is allocated to the corresponding object as a response to the number allocation request. The locking operation in this process is to avoid allocating the same number in the relational database to multiple objects because the relational database without locking can be accessed by multiple devices. However, the current number pre-generation method mainly relies on the relational database. Therefore, when generating numbers and storing them in the relational database and retrieving numbers from the relational database, locking and unlocking operations are required, which is time-consuming. In addition, in a high-concurrency scenario, the relational database connects multiple devices that can send number allocation requests. Excessive connections are likely to cause the number allocation request to time out, affecting the success rate of number allocation.
[0075] Based on this, an embodiment of the present application provides a number generation method, which may include, for example: First, a number generation device determines whether a first set in a single-threaded database meets the number generation condition. The first set is used to store numbers with a first value as the highest digit, 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. 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 digit. If it is determined that the first number is not included in the first set, the first number is saved to 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. If it meets, it returns to execute the step of generating the first number with the first value as the highest digit and subsequent steps. If it does not meet, the process of generating numbers for the first set ends.
[0076] In this way, by means of the single-threaded database and its related components, the method designs a strategy for batch generating numbers and saving them in the corresponding set of the single-threaded database, so that each set stores sufficient numbers to be allocated. When there is a need to allocate numbers to an object each time, numbers can be quickly and effectively allocated to the object directly from the sufficient numbers to be allocated stored in the corresponding set of the single-threaded database, without the need to generate numbers in real time and determine whether the generated numbers are available. Thus, the efficiency of allocating numbers to an object is improved.
[0077] As an example, the single-threaded database may be Redis, for example, and Redis can implement the method provided by the embodiment of the present application through related components (such as bitmap, set).
[0078] Before introducing the specific implementation of the number generation method provided by the embodiment of the present application, in order to more clearly illustrate the technical solution provided by the embodiment of the present application, first in combination with Figure 1 introduce the network architecture applicable to the technical solution provided by the embodiment of the present application. Figure 1 take the single-threaded database as Redis as an example for illustration.
[0079] Such as Figure 1As shown in the figure, the network architecture may include: server 10, device 21, device 22, ……, device 2N, where N is an integer greater than 1. Among them, Redis 11 is included on server 10, and devices 21 to 2N are all connected to server 10 to access Redis 11. The components of Redis 11 may include, for example: bitmap, set 0, set 1, ……, set 9. Optionally, the components of Redis 11 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 a higher query efficiency than MySQL (relational database management system); each bit of the bitmap is used to indicate whether the number corresponding to the position of the bit has been generated and saved in the set; sets 0 to 9 are respectively used to store numbers starting with 0 to 9; coroutines 1 to coroutine M are used to generate numbers, and M usually needs to be set to a fixed value during initialization, which can not only reduce the overhead when the program is newly created and destroyed, but also avoid the problem of excessive CPU load caused by uncontrollable number of coroutines. It can be seen that through the above components or features of Redis 11, the problems existing in the current number generation scheme can be overcome.
[0080] It should be noted that Redis 11 on server 10 has the functions of generating numbers and saving numbers; all or part of devices 21 to 2N may have the function of requesting numbers, and obtain numbers from Redis 11 on server 10 to allocate to corresponding objects.
[0081] It should be noted that the main body implementing the number generation method may be the number generation device provided in the embodiments of the present application. The number generation device may be carried on an electronic device or a functional module of an electronic device. The number generation device may correspond, for example, to Figure 1 Redis 11 therein, specifically, the components and functional modules in Redis related to implementing the method provided in the embodiments of the present application.
[0082] Figure 2 It is a schematic flowchart of a number generation method provided in the embodiments of the present application. This method can be applied to the number generation device, and the number generation device may be, for example, Figure 1 Redis 11 therein, or it may also be the Figure 6 number generation device 600 shown below. In the following, the first set in Redis is taken as an example for description, and the number generation methods of other sets are the same as the Figure 2 method shown, and the other sets can be used as the first set to execute the Figure 2 method shown to generate numbers.
[0083] As Figure 2As shown, the method may include the following S101 to S103 for example:
[0084] 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, and the first value is any one of the natural numbers less than 10. The number generation condition is used to indicate that the number of numbers in the first set is insufficient. The single-threaded database only allows one operation to be executed at the same time.
[0085] It can be understood that in the embodiments of the present application, the number generation device can determine whether the first set corresponding to the first value in the single-threaded database meets the preset number generation condition. If so, execute the following S102 to generate numbers for the first set and execute the judgment step of S103; if not, execute the process of generating numbers for the first set in S102.
[0086] In the following, Redis is taken as an example of the single-threaded database for illustration.
[0087] Redis can have multiple sets. A set is a component of Redis and can be used to store multiple numbers generated in batches in the embodiments of the present application. As an example, in the embodiments of the present application, 10 sets in Redis can be used: set 0, set1,..., set 9. Each set is used to store numbers starting with a natural number less than 10 (or can also be called with a natural number less than 10 as the highest digit). For example, set 1 is used to store numbers starting with 1,..., set 9 is used to store numbers starting with 9. Since the time complexity of storing numbers in a set in Redis and querying numbers from a set in Redis is both O(1), and O(1) can be understood as that on average, tasks such as storing numbers in a set in Redis or querying numbers from a set in Redis can be completed through one operation. Therefore, compared with other ways of storing numbers and querying numbers (such as the way of storing numbers and querying numbers in a relational database), the execution efficiency is higher.
[0088] It should be noted that Figure 2 In the method shown, 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 one of the natural numbers less than 10. The first value corresponds to the first set. For example, when 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; another example is that when 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.
[0089] It should be noted that the numbers mentioned in the embodiments of this application are numbers used to assign a unique identifier to an object, and the numbers are composed of several natural numbers less than 10. For example, the numbers are 5- or 6-digit numbers composed of 5 or 6 natural numbers less than 10. The lengths of the numbers stored in each set can be the same or different, which does not affect the implementation of the embodiments of this application.
[0090] The number generation condition is pre-configured and is a condition for identifying whether it is necessary to pre-generate the numbers corresponding to a certain set and store them in the set. Figure 2 In the method shown, 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. The first set satisfies the number generation condition, which means that the number of numbers stored in the first set is insufficient. In this case, it is necessary to generate the numbers corresponding to the first set; on the contrary, the first set does not satisfy the number generation condition, which means that the number of numbers stored in the first set is sufficient. In this case, it is temporarily not necessary to generate the numbers corresponding to the first set. Among them, the numbers corresponding to the first set can be understood as the numbers with the first value corresponding to the first set as the highest digit, and the generated numbers are stored in the first set after generation.
[0091] It can be understood that to determine whether the number of numbers stored in the first set is sufficient, it can be based on the number of numbers stored in the first set, or on the number consumption speed (i.e., the historical allocation speed in the following text) of the first set in the recent period of time. Therefore, the number generation condition can include, but is not limited to: the number of numbers to be assigned to the object in the set is less than the preset number threshold, and / or, the historical allocation speed of the set is greater than the preset speed threshold, where the historical allocation speed is the ratio of the total number of numbers allocated to the object from the first set during the preset historical time period to the preset historical time period.
[0092] As an example, the number generation device can pre-configure a corresponding preset number threshold (such as 10,000) for each set, corresponding to Figure 2In the method shown, the number generation condition may 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 generation device determines that the number of numbers saved 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, and thus, the following S102 is triggered to generate the number corresponding to the first set. It should be noted that the preset quantity thresholds corresponding to each set may be the same or different. In this embodiment of the present application, the example where the preset quantity thresholds corresponding to each set are the same is used for illustration. The preset quantity threshold can be flexibly configured according to requirements. For example, a reasonable preset quantity threshold can be configured based on the different lengths of the numbers. If the number is a 5-digit number, the preset quantity threshold can be 10,000; if the number is a 6-digit number, the preset quantity threshold can be 100,000.
[0093] As another example, the number generation device can pre-configure a corresponding preset speed threshold (such as 1000 per second) for each set, corresponding to Figure 2 In the method shown, 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 generation device determines that the allocation speed of the numbers in the first set in the past 1 minute is 1100 per second, which is greater than the preset speed threshold of 1000 per second corresponding to the first set. Therefore, it is determined that the first set meets the number generation condition, and thus, the following S102 is triggered to generate the number corresponding to the first set. It should be noted that the preset speed thresholds corresponding to each set may be the same or different. In this embodiment of the present application, the example where the preset speed thresholds corresponding to each set are the same is used for illustration. The preset speed threshold can be flexibly configured according to requirements.
[0094] As yet another example, the number generation device can pre-configure a corresponding preset quantity threshold and preset speed threshold for each set, corresponding to Figure 2 In the method shown, the number generation condition may 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, and the allocation speed of the numbers in the first set is greater than the preset speed threshold. For example, the number generation device determines that the number of numbers saved in the first set is 100, and the historical allocation speed in the past 1 minute is 1100 per second. Thus, it is determined that the number of numbers saved in the first set, 100, is less than the preset quantity threshold of 10,000 corresponding to the first set, and it is determined that the allocation speed of the numbers in the first set, 1100 per second, is greater than the preset speed threshold of 1000 per second. That is, it is determined that the first set meets the number generation condition, and thus, the following S102 is triggered to generate the number corresponding to the first set.
[0095] In some implementations, the method provided by the embodiments of the present application may include: periodically traversing the number-related information in each set in Redis; then, S101 may include, for example: judging whether each set meets the number generation condition according to the number-related information in each set. Among them, judging whether each set meets the number generation condition according to the number-related information in each set may include: judging whether the first set meets the number generation condition according to the number-related information of the first set. As an example, Redis can trigger a query of the number-related information of each set in Redis through a timing task (such as a minute-level timing task), and judge whether each set meets the number generation condition accordingly. Among them, the number-related information may correspond to different contents according to different number generation conditions. For example, when the number generation condition includes the number of numbers to be allocated to an object in the set, then the number-related information may include the number of numbers currently saved in the set; for another example, when the number generation condition includes the allocation speed of the numbers in the set, then the number-related information may include the number consumption quantity or historical allocation speed in a recent preset period of time in the set.
[0096] It can be seen that after the judgment of S101, if the judgment result is negative, that is, the first set does not meet the number generation condition, then the following S102 is not executed; if the judgment result is positive, that is, the first set meets the number generation condition, then the number generation process corresponding to S102 is executed, and the judgment of S103 is continued, and it is determined whether to execute S102 again according to the judgment result of S103 until the first set does not meet the number generation condition.
[0097] S102, if the first set meets the number generation condition, generate a first number with the first value as the highest bit, and if it is determined that the first set does not include the first number, then save the first number to the first set to obtain an updated first set.
[0098] Among them, S102 may include: S1021, generating a first number with the first value as the highest bit; S1022, judging whether the first set includes the first number; S1023, if it is determined that the first set does not include the first number, then save the first number to the first set to obtain an updated first set.
[0099] 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 set includes the first number. In this example, if the saving operation of saving the first number to the first set in S1023 fails, then a rollback operation is performed until the rollback operation succeeds or the number of times of the rollback operation reaches a preset number. One rollback operation includes: modifying the second indication information to the first indication information; if the rollback operation succeeds, then return to execute S102; if the number of times of execution of the rollback operation reaches the preset number and the rollback operations are all unsuccessful, then a notification message is generated, and the notification message is used to indicate that the second indication information is forcibly modified to the first indication information.
[0100] Taking the single-threaded database Redis as an example, the implementation manner of S102 is described.
[0101] A fixed number of coroutine pools can be set in Redis, and multiple coroutines in the coroutine pool can all be used to implement the step S1021 of generating the first number with the first value as the highest bit.
[0102] As an example, S1021 may include, for example: First, obtain at least one available coroutine from the coroutine pool of Redis; then, generate the first number on the at least one obtained available coroutine. The number of available coroutines obtained in S1021 can determine the number of first numbers generated by executing S1021 once. For example, if 1 available coroutine is obtained in S1021, then one execution of S1021 can generate one first number; for another example, if 3 available coroutines are obtained in S1021, then one execution of S1021 can generate three first numbers.
[0103] It should be noted that the execution of S1021 requires not only the support of available coroutines on Redis, but also a function for generating numbers running on the available coroutines. The input parameters of the function may include the highest bit value (corresponding to the first value in this embodiment), and optionally, the input parameters of the function may further include the preset length of the number (such as 5 or 6). In this way, the first number meeting the requirements of the input parameters of the function can be generated through S1021.
[0104] Among them, the coroutine pool of Redis can be started in a non-blocking manner, that is, if no available coroutines are obtained in S1021, then the number generation process of generating the number with the first value as the highest bit this time is ended.
[0105] For example, see Figure 3As shown, the process of generating numbers may include, for example: S11, starting a timed task; S12, when the timed task is completed, traversing each set to obtain the number-related information of each set; S13, judging whether each set meets the number generation condition according to the number-related information of each set. If so, execute S14; otherwise, execute S16; S14, judging whether there is an available coroutine in the coroutine pool. If so, execute S15; otherwise, execute S16; S15, based on the first set that meets the number generation condition, obtaining an available coroutine and generating a first number based on the obtained available coroutine; S16, ending the current number generation process. Thus, based on Figure 3 the process shown, corresponding numbers can be generated for each set that meets the number generation condition.
[0106] In some implementation manners, in order 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: judging whether the first number exists in the allocation relation table. If the first number does not exist in the allocation relation table, then execute S1022 - S1023; if the first number exists in the allocation relation table, then end the current number generation process and do not execute the subsequent S1022 - S1023. Among them, the allocation relation table is used to save the corresponding relationship between the object and the number, and the corresponding relationships in the allocation relation table are all in a valid state. In other words, the number generation device can also record the successfully allocated objects and numbers in the allocation relation table. The numbers in the allocation relation table cannot be saved as newly generated numbers in Redis and wait to be continuously assigned to other objects. Therefore, for the generated first number, only by checking whether the first number exists in the allocation relation table can it be judged whether the first number is a number that can be subsequently assigned, providing a basis for whether to execute S1022 - S1023 subsequently.
[0107] For S1022 to judge whether the first set includes the first number, in the case where the single-threaded database is Redis, it may include: judging whether the bit corresponding to the first number in the bitmap of Redis is 0 and being able to successfully set this bit to 1.
[0108] Among them, the bitmap in Redis consists of multiple bits, and each bit is used to identify whether the number corresponding to this bit has been generated and saved to the corresponding set. For example, the 12345th bit in the bitmap is used to identify whether the number 12345 has been generated and saved to the corresponding set. When the number 12345 is not saved to 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 modified from 0 to 1. Since the time complexity of the bitmap in Redis is O(1) during the process of storing and querying numbers, compared with other ways of saving and querying numbers (such as saving and querying numbers in a relational database), the execution efficiency is higher.
[0109] As an example, the judgment in S1022 can be reflected by performing a bit setting operation on the bit corresponding to the first number in the Redis bitmap. Among them, the bit setting operation can be implemented through the function corresponding to the bit setting operation of the bitmap in Redis. For example, this function can be set bitmap(), and the input parameters of this function can include the first number. The return value of executing this function can be used to indicate whether the bit setting operation in S1022 is effective. The situations of the return value of this function can include: the operation is successful or an error is reported. In the case of a successful operation, the return value can include two situations: 0 or 1. When the return value reports an error, it can be considered that there is an error in this bit setting operation; when the return value is 1, it can be considered that this bit setting operation is successful, but the bit corresponding to the first number in the Redis bitmap before this bit setting operation is 1, that is, the first number is a number that has been generated and saved in the corresponding Redis set. To avoid saving the first number repeatedly, S1023 does not need to be executed; when the return value is 0, it can be considered that this bit setting operation is successful, and the bit corresponding to the first number in the Redis bitmap before this bit setting operation is 0. After this bit setting operation, the bit corresponding to the first number in the Redis bitmap is modified from 0 to 1, that is, this bit setting operation is effective.
[0110] For S1023, the effectiveness of the above bit setting operation can be used as the 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 the updated first set is obtained.
[0111] Among them, the effectiveness of the bit setting operation can be understood as: before this bit setting operation, the bit corresponding to the first number in the Redis bitmap is 0, and after this bit setting operation, the bit corresponding to the first number in the Redis bitmap is modified from 0 to 1.
[0112] As an example, after S1022, it can be determined whether the setting operation of S1022 is effective. If it is effective, then S1023 is executed to save the first number to the first set; if the setting operation fails (which can also be referred to as invalid), then the current number generation process ends. Among them, the failure of the setting operation can include the situation where the return value of the function corresponding to the above implementation of the setting operation reports an error or the return value is 1.
[0113] For the save operation of saving the first number to the first set in S1023, if the save operation is successful, it is considered that the current number generation process is completed; if the save operation fails, in order not to affect the subsequent saving of the first number when generating the first number again, a rollback operation can be performed on the setting operation on the bitmap in S1022. As an example, the method may further include: if the save operation of saving the first number to the first set in S1023 fails, then the rollback operation is executed until the rollback operation is successful or the number of executions of the rollback operation reaches a preset number of times. Among them, one rollback operation may include: setting the bit corresponding to the first number in the Redis bitmap to 0. In one case, if one rollback operation fails and the number of executions of the rollback operation does not reach the preset number of times (such as 3 times), then the next rollback operation is executed; in another case, if the rollback operation is successful, then the next number generation process starts; in yet another case, if the rollback operation reaches the preset number of times (such as 3 times), then a notification message is generated, and the notification message 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.
[0114] For example, see Figure 4As shown in the figure, for the first set that meets the number generation condition, the complete process of generating a number can include, for example: S21, generating a first number with the first value as the highest digit; S22, determining whether the first number is in the allocation relation table. If it is, then return to S21. If not, then execute S23; S23, perform a set operation on the bit corresponding to the first number in the bitmap to obtain the return value A; S24, determine whether the set operation is effective according to the return value A. If the set operation is effective, then execute S25. If the set operation is ineffective, then return to S21; S25, perform a save operation to save the first number to the first set to obtain the return value B; S26, determine whether the save operation is successful according to the return value B. If it is successful, then execute S27. If it fails, then execute S29; S27, obtain the number-related information of the first set; S28, determine whether the first set meets the number generation condition according to the number-related information of the first set. If it is, then return to S21. If not, then end; S29, perform a rollback operation on the set operation of the first number on the bitmap to obtain the return value C; S30, determine whether the rollback operation is successful according to the return value C. If it is successful, then return to S21. If it fails and the number of rollback operations has not reached the preset number, then return to S29. If it fails and the number of rollback operations has reached the preset number, then execute S31; S31, generate a notification message to notify manual intervention to forcibly set the bit corresponding to the first number in the Redis bitmap to 0. It can be seen that through this embodiment, a number can be generated for the first set with insufficient saved numbers and saved to the first set, so that the first set can save sufficient numbers, which is convenient for coping with the requests for numbers in a high-concurrency scenario and realizing efficient number allocation.
[0115] It can be seen that through S102, when the first set meets the number generation condition, a process of generating a number for the first set is completed, enriching the number of numbers in the first set and preparing for efficient number allocation.
[0116] S103, determine whether the updated first set meets the number generation condition. If it meets, then return to execute the step of generating the first number with the first value as the highest digit and subsequent steps. If it does not meet, then end the process of generating a number for the first set.
[0117] It can be understood that after obtaining the updated first set through S102, it is also possible to continue to determine whether the updated first set meets the number generation condition. If it meets, then it is possible to return to execute S102 to continue enriching the number of numbers in the first set. If it does not meet, then it is considered that it is possible not to generate a number for the first set temporarily.
[0118] It can be seen that through this method, by means of a single-threaded database (such as Redis) and its related components, a strategy for batch generating numbers and storing them in each set of the single-threaded database is designed, so that sufficient numbers to be allocated are stored in the set. When there is a need to allocate numbers to an object each time, numbers can be quickly and effectively allocated to the object directly from the sufficient numbers to be allocated stored in the corresponding set, without the need to generate numbers in real time and determine whether the generated numbers are available. Thus, the efficiency of allocating numbers to an object is improved.
[0119] In some implementation manners, the embodiment of the present application also provides 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 applying 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 the numbers to be allocated to the object in a second set corresponding to the second value in the single-threaded database, where the second set is used to store numbers with the second value as the highest digit; S107, allocating the second number to the target object. In addition, if the single-threaded database is Redis, and whether the number is stored in Redis is recorded through a bitmap in Redis, then, while S107 is implemented, the bit corresponding to the second number in the bitmap of Redis can be set to 0. In addition, optionally, after S107, the corresponding relationship between the target object and the second number may be stored in an allocation relationship table, so that when generating the second number subsequently, it can be accurately determined whether the second number has been allocated based on the allocation relationship table, making the number generation method provided by the embodiment of the present application have better effects.
[0120] Among them, 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 application.
[0121] Taking the single-threaded database as Redis as an example, S106 - S107 are described.
[0122] For S106, it can be implemented by a reading function for number reading from a set in Redis. The input parameters of the reading function may at least include the identifier of the second set. For example, the reading function may be pop(), and the input parameter of pop() may include the identifier of the second set - set 2. Then, S106 may include, for example: executing pop(set 2), and the output parameter of pop(set2) includes the second number.
[0123] For S107, on the one hand, Redis can allocate the second number to the target object and send the second number to the requester (such as Figure 1any one of devices 1 to device n) so that the requester assigns the second number to the target object; on the other hand, Redis can set the bit corresponding to the second number in the bitmap of Redis to 0 to indicate that the second number is no longer the number to be assigned to an object in Redis.
[0124] It should be noted that when the operation of setting the bit corresponding to the second number in the bitmap of Redis to 0 in S107 fails, this operation can be repeated until the number of times of repeating this operation reaches the maximum number of times allowed for this operation to be repeated or this operation is successful. If the operation still fails when the number of times of repeating this operation reaches the maximum number of times allowed for this operation to be repeated, a notification message can be generated. This notification message is used to indicate that the bit corresponding to the second number in the bitmap of Redis is forcibly set to 0, and this forced setting can be modified by manual intervention of the staff.
[0125] For example, see Figure 5As shown, the allocation process for the pre-generated numbers stored in Redis may include, for example: S41, generating a random number from 0 to 9, denoted as the second value; S42, performing an acquisition operation of obtaining 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 it is not successful, then execute S49. If it is successful, then execute S44; S44, performing a reset operation of setting the bit corresponding to the second number in the bitmap of Redis to 0, and obtaining a return value E; S45, judging whether the reset operation is successful according to the return value E. If it is successful, then end the allocation process. If it is not successful, then execute the repeated operations of S46 - S48; S46, performing a repeated operation 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. If it is 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, generating a notification message to notify manual intervention to forcibly set the bit corresponding to the second number in the bitmap of Redis to 0; S49, if the number of numbers stored in the second set in Redis is 0 (i.e., 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 in extreme cases, that is, after generating a number according to the method provided in the embodiment of the present application, directly allocate the number to the object requesting the number without storing the number in the corresponding set, so as to improve the number allocation efficiency in this extreme case. In this way, through this embodiment, the efficient allocation of the numbers stored in Redis is realized, and the efficiency of allocating numbers to objects is improved, which is especially applicable to high-concurrency scenarios (i.e., multiple requesters request numbers from Redis simultaneously).
[0126] It should be noted that the number allocation scheme corresponding to S105 - S107 can be used as Figure 2 the follow-up of the number generation method shown, or can be implemented as a separate embodiment to achieve the effect of efficiently requesting numbers from a single-threaded database.
[0127] It should be noted that the number allocated to the object can be permanently bound to the object; the validity period (such as 3 months) can also be set for this binding relationship, and the binding relationship will be automatically released after the expiration of the validity period; the binding relationship can also be released for other reasons (such as the application of the user). After the binding relationship is released, the corresponding relationship related to the binding relationship in the allocation relationship table can be deleted or set to an invalid state, and the number in the corresponding relationship in the invalid state is regarded as a number that does not exist in the allocation relationship table.
[0128] After the binding relationship is released, 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 application. Among them, the timing of executing the two operations of releasing 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 released; 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 is executed after the buffer time interval has passed after the unbinding relationship is started.
[0129] Accordingly, the embodiment of the present application also provides a number generating device 600, such as Figure 6 In the device 600, the number is a numerical string that can uniquely identify the object, and the device 600 may include, for example:
[0130] A first judging unit 601 is used 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;
[0131] 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 if it is determined that the first set does not include the first number, to obtain an updated first set;
[0132] 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.
[0133] In some implementations, the first set satisfying the number generation condition includes:
[0134] The number of numbers in the first set is less than a preset number threshold;
[0135] 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.
[0136] In some implementations, the single-threaded database is Redis, then,
[0137] The generating subunit in the generating unit 602 for generating a first number with the first value as the highest bit is specifically configured to:
[0138] 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;
[0139] The determining subunit in the generating unit 602 for determining that the first set does not include the first number is specifically configured to:
[0140] Determine that the bit corresponding to the first number in the bitmap of the Redis is 0 and can successfully set this bit to 1.
[0141] In some implementation manners, the apparatus 600 further includes:
[0142] A first obtaining unit, 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, denoted as a second value;
[0143] A second obtaining unit, configured to 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 bit;
[0144] An allocation unit, configured to allocate the second number to the target object.
[0145] In some implementation manners, the apparatus 600 further includes:
[0146] A third determining unit, configured to determine whether the first number exists in an allocation relationship table before determining that the first set does not include the first number, where the allocation relationship table is used to store the correspondence between an object and the number allocated to the object and currently used by the object;
[0147] A first processing unit, configured to, if the first number does not exist in the allocation relationship table, execute the operation of saving the first number to the first set and subsequent operations if it is determined that the first set does not include the first number;
[0148] A second processing unit, configured to, if the first number exists in the allocation relationship table, no longer execute the operation of saving the first number to the first set and subsequent operations if it is determined that the first set does not include the first number.
[0149] In some implementation manners, the apparatus 600 further includes:
[0150] A modification unit, configured to, before saving the first number to the first set, if it is determined that the first set does not include the first number, modify first indication information indicating that the first set does not include the first number into second indication information, where the second indication information is used to indicate that the first set includes the first number.
[0151] In some implementations, the apparatus 600 further includes:
[0152] A rollback unit, configured to, if a save operation of saving the first number to the first set fails, perform a rollback operation until the rollback operation succeeds or the number of times of the rollback operation reaches a preset number of times. One rollback operation includes: modifying the second indication information into the first indication information;
[0153] A third processing unit, configured to, if the rollback operation succeeds, return to execute generating the first number with the first value as the highest bit, and subsequent steps;
[0154] A notification unit, configured to, if the number of times of executing the rollback operation reaches the preset number of times and the rollback operations are not successful, generate a notification message, where the notification message is used to indicate forcibly modifying the second indication information into the first indication information.
[0155] It should be noted that for the specific implementation manners and achieved technical effects of the apparatus 600, reference may be made to Figure 2 the relevant descriptions of the method shown.
[0156] In addition, an embodiment of the present application further provides an electronic device, where the device includes a processor and a memory: the memory is configured to store instructions or computer programs; the processor is configured to execute the instructions or computer programs in the memory, so that the electronic device executes any implementation manner of the method provided in the embodiment of the present application.
[0157] Refer to Figure 7 , which shows a schematic structural diagram of an electronic device 700 suitable for implementing the embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is 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), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device shown is only an example, and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.
[0158] As Figure 7As shown, the electronic device 700 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 701, which may 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. In the RAM 703, various programs and data required for the operation of the electronic device 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other through a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0159] Generally, 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 wiredly to exchange data. Although Figure 7 the electronic device 700 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.
[0160] Specifically, according to an embodiment of the present disclosure, the process described above with reference to the flowchart may 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 program codes for performing the method shown in the flowchart. In such an embodiment, the computer program may be downloaded and installed from a 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 functions defined in the method of the embodiment of the present disclosure are executed.
[0161] 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. Technical details not described in detail in this embodiment may be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0162] An embodiment of the present application also provides a computer-readable medium, in which instructions or a computer program are stored. When the instructions or the computer program run on a device, the device is caused to execute any implementation manner of the method provided by the embodiment of the present application.
[0163] It should be noted that the computer-readable medium described above can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can 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, the computer-readable storage medium can be any tangible medium that contains or stores a program, which can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit 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 can be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0164] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (Hyper Text Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LANs"), wide area networks ("WANs"), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed networks.
[0165] The above computer-readable medium can be included in the above electronic device; or it can exist separately without being assembled into the electronic device.
[0166] The above computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device can execute the above method.
[0167] Computer program code for performing the operations of this disclosure may be written in one or more programming languages or combinations thereof. The foregoing programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the case of 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).
[0168] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.
[0169] The units involved in the embodiments described in this disclosure may be implemented in software or in hardware. Among them, the name of the unit / module does not constitute a limitation on the unit itself in some cases.
[0170] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, by way of non-limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and the like.
[0171] 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 connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0172] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the systems or apparatuses disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and reference can be made to the description in the method part for the relevant parts.
[0173] It should be understood that in this application, "at least one (item)" means one or more, and "a plurality" means two or more. "And / or" is used to describe the association relationship of associated objects and indicates that three relationships can exist. For example, "A and / or B" can mean: only A exists, only B exists, and both A and B exist simultaneously. Here, A and B can be singular or plural. The character " / " generally indicates an "or" relationship between the associated objects before and after. "At least one (one) of the following" or its similar expression refers to any combination of these items, including any combination of single item (one) or plural items (ones). For example, at least one (one) of a, b, or c can mean: 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.
[0174] It should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprising", "including" or any other variant 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 expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the element.
[0175] The steps of the methods or algorithms described in connection with the embodiments disclosed herein can be implemented directly in hardware, software modules executed by a processor, or a combination of both. The software modules can be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0176] It should be noted that in the embodiments of the present application, user-sensitive information is not involved, and user-related information is obtained, used and determined only after user authorization. In one example, before obtaining user-related information, a prompt message related to obtaining data usage authorization is displayed on the corresponding interface, and this prompt message informs the user of the type, usage scope, usage scenarios, etc. of the personal information involved in the present disclosure in an appropriate manner in accordance with relevant laws and regulations, so that the user can determine whether to agree to the authorization based on this prompt message. It can be understood that the above notification and user authorization process is only illustrative and does not constitute a limitation on the implementation manner of the present disclosure. Other ways that meet relevant laws and regulations can also be applied to the implementation manner of the present disclosure.
[0177] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to these embodiments shown herein, but will be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating numbers, characterized in that, the number is a numerical string that can uniquely identify an object, including: judging 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, and the number generation condition is used to indicate that the number of numbers in the first set is insufficient. The single-threaded database only allows one operation to be executed at the same time; 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, then save the first number to the first set to obtain an updated first set; judging whether the updated first set meets the number generation condition. If it meets, return to execute the generation of the first number with the first value as the highest digit and subsequent steps. If it does not meet, end the process of generating numbers for the first set.
2. The method according to claim 1, characterized in that, the first set meeting the number generation condition includes: 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 within a preset historical time period to the preset historical time period.
3. The method according to claim 1 or 2, characterized in that, if the single-threaded database is Redis (Remote Dictionary Server), then, the generation of the first number with the first value as the highest digit includes: obtaining at least one available coroutine from the coroutine pool of the Redis, and generating the first number on the at least one available coroutine; the determination that the first number is not included in the first set includes: determining 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-3, characterized in that, the method further includes: in response to receiving a request for applying for a number for a target object, randomly generating a natural number less than 10, denoted as a second value; obtaining a second number from a second set corresponding to the second value, the second set is used to store numbers with the second value as the highest digit; allocating the second number to the target object.
5. The method according to any one of claims 1-4, characterized in that, before the determination that the first number is not included in the first set, the method further includes: judging whether the first number exists in the allocation relationship table, the allocation relationship table is used to store the correspondence between an object and the number allocated to the object and currently in use by the object; if the first number does not exist in the allocation relationship table, then execute the step of if it is determined that the first number is not included in the first set, then save the first number to the first set, and subsequent operations; If the first number exists in the allocation relation table, the subsequent operations, such as saving the first number to the first set if it is determined that the first set does not include the first number, will no longer be executed.
6. The method according to any one of claims 1-5, wherein, before saving the first number to the first set, the method further includes: if it is determined that the first set does not include the first number, 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 set includes the first number.
7. The method according to claim 6, wherein, the method further includes: if the save operation of saving the first number to the first set fails, performing a rollback operation until the rollback operation is successful or the number of executions of the rollback operation reaches a preset number. One rollback operation includes: modifying the second indication information to the first indication information; if the rollback operation is successful, returning to execute generating the first number with the first value as the highest bit and subsequent steps; if the number of executions of the rollback operation reaches the preset number and the rollback operations are all unsuccessful, generating a notification message for instructing to forcibly modify the second indication information to the first indication information.
8. A number generation device, wherein, the number is a numeric string capable of uniquely identifying an object, including: a first judgment unit for judging whether a first set in a single-threaded database meets the number generation condition. The first set is used to save numbers with the first value as the highest bit, and the first value is any one of natural numbers less than 10. The number generation condition is used to indicate that the number of numbers in the first set is insufficient. The single-threaded database only allows one operation to be executed at the same time; a generation unit for generating a first number with the first value as the highest bit if the first set meets the number generation condition, and saving the first number to the first set if it is determined that the first set does not include the first number to obtain an updated first set; a second judgment unit for judging whether the updated first set meets the number generation condition. If it meets, returning to execute generating the first number with the first value as the highest bit and subsequent steps. If it does not meet, ending the process of generating numbers for the first set.
9. An electronic device, wherein, the electronic device includes: a processor and a memory; the memory is used to store instructions or programs; the processor is used to execute the instructions or programs in the memory so that the electronic device executes the method according to any one of claims 1-7.
10. A readable medium, wherein, instructions or programs are stored in the readable medium, and when the instructions or programs run on a processor, the processor is caused to execute the method according to any one of claims 1-7.