Disclosure of Invention
In view of this, embodiments of the present invention provide redemption code picking methods and apparatuses, which locate a storage queue through a pointer and use a pop command to pick a redemption code from the storage queue, so that repeated picking of the redemption code can be effectively prevented when the redemption code is picked and sent.
To achieve the above objects, according to aspects of embodiments of the present invention, a method of getting redemption codes is provided.
The redemption code receiving method comprises the steps of checking issuing amount and total inventory according to the issuing amount of redemption codes, obtaining pointers of the redemption codes when the checking is passed, finding corresponding storage queues used for storing the redemption codes through the current pointers, obtaining the redemption codes from the storage queues by adopting a pop command, and returning the redemption codes when the obtained redemption codes are not empty.
Optionally, the method further comprises: if the exchange code returns success, updating the getting state of the exchange code; and if the exchange code return fails, pushing the exchange code to a storage queue corresponding to the current pointer by adopting a push command.
Optionally, the step of obtaining the pointer to the redemption code further comprises taking a lower pointer as the current pointer if the obtained redemption code is empty and the current pointer is less than the number of the storage queues.
Optionally, before the step of verifying the release amount, the method further includes: self-increment the issuing amount of the exchange code; the checking the issuing amount according to the issuing amount and the total inventory amount of the redemption code comprises the following steps: and comparing the self-increased release amount with the total inventory amount, and judging whether the verification passes according to the comparison result.
Optionally, the method further comprises storing the redemption codes in at least of the storage queues of a Redis database based on the total number of redemption codes and the stored number of the storage queues.
To achieve the above object, according to another aspect of the embodiment of the present invention, a device for getting redemption codes is provided.
The redemption code receiving device comprises a checking module, a searching module and a returning module, wherein the checking module is used for checking the issuing amount according to the issuing amount and the total inventory amount of redemption codes, the searching module is used for acquiring pointers of the redemption codes when the checking is passed and searching corresponding storage queues for storing the redemption codes through the current pointers, and the returning module is used for acquiring the redemption codes from the storage queues by adopting a pop-up command and returning the redemption codes when the acquired redemption codes are not empty.
Optionally, the apparatus further comprises: the updating and pushing module is used for updating the getting state of the exchange code if the exchange code returns to success; and if the exchange code return fails, pushing the exchange code to a storage queue corresponding to the current pointer by adopting a push command.
Optionally, the apparatus further comprises a pointer updating module, configured to take a lower pointer as the current pointer if the obtained redemption code is empty and the current pointer is smaller than the number of the storage queues.
Optionally, the apparatus further comprises: the self-increment module is used for self-incrementing the issuing amount of the exchange code; the verification module is further configured to: and comparing the self-increased release amount with the total inventory amount, and judging whether the verification passes according to the comparison result.
Optionally, the apparatus further comprises a storage module for storing the redemption codes in at least storage queues of a Redis database based on the total number of redemption codes and the number of stores in the storage queue.
To achieve the above object, according to a further aspect of an embodiment of the present invention, kinds of electronic devices are provided.
The electronic devices of the embodiment of the invention comprise or multiple processors and a storage device, wherein the storage device is used for storing or multiple programs, and when the or multiple programs are executed by the or multiple processors, the or multiple processors realize the method for getting redemption codes of the embodiment of the invention.
To achieve the above object, according to a further aspect of an embodiment of the present invention, computer-readable media are provided.
computer readable media of embodiments of the invention have stored thereon computer programs that, when executed by a processor, implement methods of claiming redemption codes of embodiments of the invention.
embodiments of the invention have the advantages or beneficial effects that the storage queue is positioned through the pointer, the exchange code is obtained from the storage queue through the pop command, repeated picking of the exchange code is when the exchange code is obtained in a parallel mode can be effectively prevented, the exchange code which fails to return is pushed to the storage queue corresponding to the current pointer through the push command again, the exchange code can be picked again, the issuing amount of the exchange code is increased automatically before verification, the exchange code can be occupied in advance, the final issuing amount of the exchange code is prevented from being larger than the total inventory amount when the parallel request is sent, when the exchange code in the storage queue is empty, the exchange code can be automatically switched to the next storage queues through the pointer, the exchange code is stored in the multiple storage queues of the Redis database, normal picking of the exchange code is guaranteed in a high parallel scene, efficiency is high, and stability is good.
The effect of step of the above non-conventional alternative is described below in conjunction with the detailed description.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram of the main steps of a redemption code acquisition method according to an embodiment of the present invention. As shown in fig. 1, the method for obtaining a redemption code according to the embodiment of the present invention mainly includes the following steps:
step S101: and checking the issuing amount according to the issuing amount and the total inventory of the exchange code. Comparing the issuing amount of the exchange code with the total inventory amount, and if the issuing amount is less than or equal to the total inventory amount, indicating that the verification is passed; and if the release amount is larger than the total inventory amount, indicating that the verification is failed. In the real-time example, in order to prevent the final issued quantity of the exchange code from being more than the total inventory quantity when the concurrent requests are sent, the issued quantity of the exchange code is increased by 1 in advance, and if the issued quantity after the increase is less than or equal to the total inventory quantity, the verification is passed; and if the self-increased issuing amount is larger than the total inventory amount, the verification is failed, and the issuing amount of the redemption code is reduced by 1.
The method comprises the steps of S102, obtaining a pointer of the exchange code when the verification is passed, and finding a corresponding storage queue for storing the exchange code through a current pointer, wherein the pointer is a serial number (List _ count) of the storage queue, a database where the storage queue is located is a K-V (Key-Value pair) database, such as a Redis database and a Memcached database, Redis is high-performance Key-Value storage systems, and supports stored Value types including String, List, Set and Zset, Memcached is high-performance distributed memory object cache systems for dynamic Web application to reduce database load, if the exchange code is stored in a plurality of storage queues, the pointer of the step is the serial number of the plurality of storage queues, the initial Value of the current pointer is the smallest serial number, then each time of searching, increasing by 1, such as 2, and the current pointer is found as 2.
Step S103, acquiring a redemption code from the storage queue by adopting a pop command, and returning the redemption code when the acquired redemption code is not empty, in the embodiment, acquiring the redemption code from the storage queue by adopting an LPOP command of a Redis database, wherein the LPOP command is used for popping elements from the left side of the storage queue, judging whether the acquired redemption code is empty or not after acquiring the redemption code, if the acquired redemption code is empty and the current pointer is less than the number of the storage queue, taking a lower pointer as the current pointer, and if the acquired redemption code is not empty, returning the redemption code to a user.
Fig. 2 is a main flow diagram of a redemption code acquisition method according to an embodiment of the present invention. As shown in fig. 2, the method for obtaining a redemption code according to the embodiment of the present invention mainly includes the following steps:
step S201, storing the redemption codes into at least storage queues according to the total number of the redemption codes and the storage number of the storage queues, wherein the total number of the redemption codes is the number of the redemption codes uploaded to a Redis database by a merchant, and the storage number of the storage queues is the number of the redemption codes which can be stored in the storage queues at the maximum.
In the formula (I), the compound is shown in the specification,
is rounded up.
Each store queue may be distinguished by an activity identification of the list _ count _ redemption-code-issuing activity, such as list _2_ 1902.
For example, if the activity Identification (ID) of the redemption code issuing activities is 1902, the total number of redemption codes uploaded to the database by the merchant is 103, the number of stores in each storage queue is 10, and the redemption code issuing activity with the activity ID of 1902 requires
Step S202, receiving a redemption code acquisition request, and increasing the issuing amount of the redemption code by itself, wherein the user sends the redemption code acquisition request to a server through a client, the redemption code acquisition request comprises an activity ID. server which receives the redemption code acquisition request and then analyzes the redemption code acquisition request, and then increases the issuing amount of the redemption code belonging to the activity ID by itself by 1, the issuing amount of the redemption code is increased by itself by 1 every time redemption code acquisition requests are received, so that redemption codes can be occupied in advance, and the final issuing amount of the redemption code is prevented from being more than the total stock amount when the requests are sent in parallel.
Step S203: judging whether the self-increased release amount is larger than the total inventory amount, and if the self-increased release amount is larger than the total inventory amount, executing the step S204; if the self-increased dispensing amount is less than or equal to the total inventory amount, step S205 is executed. The total inventory refers to the total quantity of the exchange codes which are expected to be issued in the exchange code issuing activity.
Step S204: the issuance amount of the redemption code is reduced by itself, and step S214 is executed. In an embodiment, the issuance amount of the redemption code is reduced by 1. If the self-increased issue amount is larger than the total inventory amount, it indicates that the redemption code has been completely received, and the user cannot receive the redemption code, and since the issue amount of the redemption code has been increased by 1 in advance in step S202, it is necessary to decrease by 1 again to meet the actual issue amount of the redemption code.
Step S205: and acquiring the pointer of the exchange code, and finding out the corresponding storage queue for storing the exchange code through the current pointer. The pointer is list _ count and is stored in a Redis database. For example, if the obtained pointers are 2, 3, and 4, the current pointer is 2, and the storage queue list _2 corresponding to the pointer 2 is searched.
In the embodiment, the exchange code is acquired from the storage queue by adopting an LPOP command, the command is atomic and thread-safe, namely, only threads are allowed to acquire the exchange code at the same time of , other threads are queued for waiting, and the acquisition of exchange codes at the same time of by a plurality of threads is avoided.
Step S207: judging whether the obtained exchange code is empty, if so, executing step S208; if not, step S210 is performed.
Step S208: judging whether the current pointer is smaller than the number of the storage queues or not, and if the current pointer is smaller than the number of the storage queues, executing the step S209; if the current pointer is greater than or equal to the number of the storage queues, step S214 is performed. If the current pointer is greater than or equal to the number of the storage queues, the redemption code is fully received.
And S209, taking the lower pointer as the current pointer, finding the corresponding storage queue for storing the redemption code through the current pointer, and executing S206. assuming that the current pointer is 2, increasing the current pointer by 1, namely, finding the storage queue corresponding to the pointer 3 as list _ 3.
Step S210: returning the redemption code. And the server returns the acquired exchange code to the client.
Step S211: judging whether the redemption code returns success, if so, executing step S212; if the return fails, step S213 is executed.
Step S212: updating a pickup status of the redemption code. If the redemption code is successfully returned to the client, indicating that the redemption code was successfully received, the receipt status of the redemption code is updated to "successful receipt". The steps are executed asynchronously, so that time consumption is greatly reduced, and database pressure is relieved.
And S213, pushing the exchange code into a storage queue corresponding to the current pointer by adopting a push command, in the embodiment, acquiring the exchange code from the storage queue by adopting an RPUSH command, wherein the RPUSH command is operation commands of a Redis database and is used for enqueuing elements or a plurality of elements from the right side of the storage queue.
Step S214: and returning prompt information and ending the process. In an embodiment, a prompt message of "light robbed" may be returned to the client.
In the preferred embodiment, multiple storage queues may be scattered among different Redis nodes to ensure load balancing among each node and relieve pressure on the Redis database.
The method for receiving the exchange code can be seen that the storage queue is positioned through the pointer, the exchange code is obtained from the storage queue through the pop command, repeated receiving of the exchange code is carried out at the same time when the exchange code is obtained in a parallel mode can be effectively prevented, the exchange code which fails to return is pushed to the storage queue corresponding to the current pointer through the push command again, the exchange code can be received again, the issuing amount of the exchange code is increased automatically before verification, the exchange code can be occupied in advance, the final issuing amount of the exchange code is prevented from being larger than the total inventory amount when the parallel request is carried out, when the exchange code in the storage queue is empty, the exchange code can be automatically switched to next storage queues through the pointer, the exchange code is stored in the plurality of storage queues of the Redis database, normal receiving of the exchange code under a high parallel scene is guaranteed, efficiency is high, and stability is good.
Figure 3 is a schematic diagram of the main modules of a redemption code capture device according to an embodiment of the present invention. As shown in fig. 3, the redemption code receiving apparatus 300 according to the embodiment of the present invention mainly includes:
the verification module 301 is configured to verify the issuing amount according to the issuing amount and the total inventory amount of the redemption code. Comparing the issuing amount of the exchange code with the total inventory amount, and if the issuing amount is less than or equal to the total inventory amount, indicating that the verification is passed; and if the release amount is larger than the total inventory amount, indicating that the verification is failed. In the real-time example, in order to prevent the final issued quantity of the exchange code from being more than the total inventory quantity when the concurrent requests are sent, the issued quantity of the exchange code is increased by 1 in advance, and if the issued quantity after the increase is less than or equal to the total inventory quantity, the verification is passed; and if the self-increased issuing amount is larger than the total inventory amount, the verification is failed, and the issuing amount of the redemption code is reduced by 1.
The searching module 302 is configured to obtain the pointer of the redemption code when the verification is passed, and search the corresponding storage queue for storing the redemption code through the current pointer. Wherein, the pointer is a sequence number (list _ count) of the storage queue. The database where the storage queue is located is a K-V database, such as a Redis database and a Memcached database. If the redemption code is stored in multiple storage queues, the pointer obtained in this step is the serial number of the multiple storage queues, the initial value of the current pointer is the minimum serial number, and then the pointer is incremented by 1 each time the pointer is searched. For example, if the current pointer is 2, the found storage queue is list _ 2.
The return module 303 is used for acquiring the exchange code from the storage queue by adopting a pop command, and returning the exchange code when the acquired exchange code is not empty, in the embodiment, the exchange code is acquired from the storage queue by adopting an LPOP command of a Redis database, the LPOP command is used for dequeuing elements from the left side of the storage queue, after the exchange code is acquired, whether the acquired exchange code is empty is judged, if the acquired exchange code is empty and the current pointer is less than the number of the storage queue, a lower pointer is used as the current pointer, and if the acquired exchange code is not empty, the exchange code is returned to a user.
In addition, the redemption code getting device 300 of the embodiment of the invention may further include an update pushing module, a pointer updating module, a self-adding module and a storage module (not shown in fig. 3), wherein the update pushing module is configured to update the getting status of the redemption code if the redemption code returns successfully, and push the redemption code to a storage queue corresponding to the current pointer if the redemption code returns failed by using a push command, the pointer updating module is configured to take a lower pointer as the current pointer if the obtained redemption code is empty and the current pointer is smaller than the number of the storage queues, the self-adding module is configured to self-add the issuing amount of the redemption code, and the storage module is configured to store the redemption code in at least storage queues of a Redis database according to the total number of the redemption codes and the storage number of the storage queues.
From the above description, the storage queue is positioned through the pointer, the exchange code is obtained from the storage queue through the pop command, repeated picking of the exchange code can be effectively prevented when the exchange code is obtained in a concurrent mode, the exchange code which fails to return is pushed to the storage queue corresponding to the current pointer through the pop command again, the exchange code can be picked again, the issuing amount of the exchange code is increased automatically before verification, the exchange code can be occupied in advance, the final issuing amount of the exchange code is larger than the total storage amount when the request is made in a concurrent mode, when the exchange code in the storage queue is empty, the exchange code can be automatically switched to next storage queues through the pointer, the exchange code is stored in the plurality of storage queues of the Redis database, normal picking of the exchange code is guaranteed in a high concurrent scene, efficiency is high, and stability is good.
Figure 4 illustrates an exemplary system architecture 400 of a method of redemption code acquisition or an apparatus for redemption code acquisition to which embodiments of the invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports a redemption code acquisition request transmitted by a user using the terminal device 401, 402, 403. The background management server may analyze and otherwise process the received redemption code acquisition request and feed back the processing result (e.g., redemption code) to the terminal device.
The redemption code acquisition method provided in the embodiments of the present application is typically executed by the server 405, and accordingly, the redemption code acquisition device is typically provided in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides electronic devices and computer-readable media according to embodiments of the invention.
The electronic equipment comprises processors or a plurality of processors, and a storage device for storing programs or a plurality of programs, wherein when the programs or the plurality of programs are executed by the processors or the plurality of processors, the processors or the plurality of processors realize the redemption code getting method of the embodiment of the invention.
The computer readable medium of the present invention has stored thereon a computer program which, when executed by a processor, implements the method of retrieving redemption codes of embodiments of the present invention.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use in implementing an electronic device of an embodiment of the present invention, the electronic device shown in FIG. 5 is merely an example and should not be taken to limit the scope of use or functionality of an embodiment of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the computer system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
For example, embodiments of the present disclosure include computer program products comprising a computer program embodied on a computer readable medium, the computer program containing program code for performing the method illustrated in the main step diagram.
A more specific example of a computer readable storage medium may include, but is not limited to, an electrical connection having or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures, for example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved, and it may also be noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, may be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware, and the described modules may be provided in a processor, for example, it may be described that kinds of processors include a check module, a search module, and a return module, wherein names of the modules do not constitute a limitation of the module itself in some cases, for example, the check module may also be described as a "module for checking a dispensing amount according to a dispensing amount and a total stock amount of a redemption code".
As another aspect, the present invention also provides computer readable media, which may be included in the apparatus described in the above embodiments, or may be separately present and not installed in the apparatus, wherein the computer readable media carries or more programs, and when the or more programs are executed by apparatuses, the apparatus comprises checking the dispensing amount and the total stock amount of a redemption code, acquiring a pointer of the redemption code when the checking is passed, finding a corresponding storage queue for storing the redemption code through a current pointer, and acquiring the redemption code from the storage queue using a pop command to return the redemption code when the acquired redemption code is not empty.
From the above description, the storage queue is positioned through the pointer, the exchange code is obtained from the storage queue through the pop command, repeated picking of the exchange code can be effectively prevented when the exchange code is obtained in a concurrent mode, the exchange code which fails to return is pushed to the storage queue corresponding to the current pointer through the pop command again, the exchange code can be picked again, the issuing amount of the exchange code is increased automatically before verification, the exchange code can be occupied in advance, the final issuing amount of the exchange code is larger than the total storage amount when the request is made in a concurrent mode, when the exchange code in the storage queue is empty, the exchange code can be automatically switched to next storage queues through the pointer, the exchange code is stored in the plurality of storage queues of the Redis database, normal picking of the exchange code is guaranteed in a high concurrent scene, efficiency is high, and stability is good.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.