CN110738507A - Method and device for receiving a redemption code - Google Patents
Method and device for receiving a redemption code Download PDFInfo
- Publication number
- CN110738507A CN110738507A CN201810790916.XA CN201810790916A CN110738507A CN 110738507 A CN110738507 A CN 110738507A CN 201810790916 A CN201810790916 A CN 201810790916A CN 110738507 A CN110738507 A CN 110738507A
- Authority
- CN
- China
- Prior art keywords
- redemption code
- code
- redemption
- pointer
- storage
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q30/00—Commerce
- G06Q30/02—Marketing; Price estimation or determination; Fundraising
- G06Q30/0207—Discounts or incentives, e.g. coupons or rebates
- G06Q30/0208—Trade or exchange of goods or services in exchange for incentives or rewards
Landscapes
- Business, Economics & Management (AREA)
- Accounting & Taxation (AREA)
- Finance (AREA)
- Engineering & Computer Science (AREA)
- Development Economics (AREA)
- Strategic Management (AREA)
- Game Theory and Decision Science (AREA)
- Entrepreneurship & Innovation (AREA)
- Economics (AREA)
- Marketing (AREA)
- Physics & Mathematics (AREA)
- General Business, Economics & Management (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
本发明公开了一种兑换码的领取方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:根据兑换码的发放量和总库存量,对所述发放量进行校验;当校验通过时获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列;采用出栈命令从所述存储队列中获取所述兑换码,以在获取的所述兑换码不为空时,返回所述兑换码。该方法通过指针定位存储队列,并采用出栈命令从存储队列中获取兑换码,能够有效防止并发获取兑换码时,同一兑换码被重复领取。
The invention discloses a method and device for receiving a redemption code, and relates to the technical field of computers. A specific implementation of the method includes: verifying the issued amount according to the issued amount of the redemption code and the total inventory; when the verification is passed, acquiring the pointer of the redemption code, and finding the corresponding user through the current pointer. in the storage queue for storing the redemption code; use a pop command to obtain the redemption code from the storage queue, so as to return the redemption code when the obtained redemption code is not empty. The method locates the storage queue through a pointer, and uses a stacking command to obtain the redemption code from the storage queue, which can effectively prevent the same redemption code from being repeatedly received when the redemption code is obtained concurrently.
Description
技术领域technical field
本发明涉及计算机领域,尤其涉及一种兑换码的领取方法和装置。The present invention relates to the field of computers, and in particular, to a method and device for receiving a redemption code.
背景技术Background technique
为了促进物品营销,商家会将实体物品或者虚拟物品的兑换码发放至用户,其中,兑换码是一种由数字和字母组成的号码。兑换码发放前,需由商家将兑换码上传至关系型数据库进行存储。当用户领取兑换码时,查看数据库中是否有未领取的兑换码,并将该未领取的兑换码的领取状态置为“兑换中”;如果兑换码领取成功,则将该兑换码的领取状态置为“已领取”;如果兑换码领取失败,则将该兑换码的领取状态置为“未领取”。In order to promote item marketing, merchants will issue redemption codes for physical items or virtual items to users, where the redemption code is a number composed of numbers and letters. Before the redemption code is issued, the merchant needs to upload the redemption code to a relational database for storage. When the user receives the redemption code, check whether there is an unclaimed redemption code in the database, and set the redemption status of the unclaimed redemption code as "redemption"; if the redemption code is successfully received, then the redemption code's redemption status Set it to "Claimed"; if the redemption code fails to be received, the redemption code's redemption status will be set to "Unclaimed".
在实现本发明过程中,发明人发现现有技术中至少存在如下问题:兑换码的存储和领取基于关系型数据库,在高并发请求下,很容易出现同一兑换码被多个用户领取的情况,从而导致部分用户无法使用领取的兑换码。In the process of realizing the present invention, the inventor found that there are at least the following problems in the prior art: the storage and receipt of redemption codes are based on relational databases, and under high concurrent requests, it is easy to occur that the same redemption code is received by multiple users, As a result, some users cannot use the redeem code they received.
发明内容SUMMARY OF THE INVENTION
有鉴于此,本发明实施例提供一种兑换码的领取方法和装置,通过指针定位存储队列,并采用出栈命令从存储队列中获取兑换码,能够有效防止并发获取兑换码时,同一兑换码被重复领取。In view of this, the embodiment of the present invention provides a method and device for obtaining a redemption code, which locates a storage queue through a pointer, and uses a pop-out command to obtain a redemption code from the storage queue, which can effectively prevent the same redemption code when the redemption code is obtained concurrently. received repeatedly.
为实现上述目的,根据本发明实施例的一个方面,提供了一种兑换码的领取方法。In order to achieve the above purpose, according to an aspect of the embodiments of the present invention, a method for receiving a redemption code is provided.
本发明实施例的一种兑换码的领取方法,包括:根据兑换码的发放量和总库存量,对所述发放量进行校验;当校验通过时获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列;采用出栈命令从所述存储队列中获取所述兑换码,以在获取的所述兑换码不为空时,返回所述兑换码。A method for receiving a redemption code according to an embodiment of the present invention includes: verifying the issued amount according to the issued amount of the redemption code and the total inventory; The pointer finds the corresponding storage queue for storing the redemption code; the redemption code is obtained from the storage queue by using a pop command, so as to return the redemption code when the obtained redemption code is not empty .
可选地,所述方法还包括:若所述兑换码返回成功,更新所述兑换码的领取状态;若所述兑换码返回失败,采用压栈命令将所述兑换码推送到所述当前指针对应的存储队列中。Optionally, the method further includes: if the redemption code returns successfully, updating the redemption status of the redemption code; if the redemption code fails to return, pushing the redemption code to the current pointer by using a push command in the corresponding storage queue.
可选地,所述获取所述兑换码的指针的步骤之后,还包括:若获取的所述兑换码为空且所述当前指针小于所述存储队列的数量,将下一指针作为所述当前指针。Optionally, after the step of acquiring the pointer of the redemption code, the method further includes: if the acquired redemption code is empty and the current pointer is less than the number of the storage queues, using the next pointer as the current pointer. pointer.
可选地,所述对所述发放量进行校验的步骤之前,还包括:将所述兑换码的发放量自增;所述根据兑换码的发放量和总库存量,对所述发放量进行校验,包括:将自增后的所述发放量与总库存量进行比较,根据比较结果判断校验是否通过。Optionally, before the step of verifying the issued amount, the step further includes: automatically increasing the issued amount of the redemption code; Carrying out the verification includes: comparing the self-increased release amount with the total inventory, and judging whether the verification is passed according to the comparison result.
可选地,所述方法还包括:根据所述兑换码的总数量和所述存储队列的存储数量,将所述兑换码存储到Redis数据库的至少一个所述存储队列中。Optionally, the method further includes: storing the redemption codes in at least one of the storage queues of the Redis database according to the total quantity of the redemption codes and the storage quantity of the storage queues.
为实现上述目的,根据本发明实施例的另一方面,提供了一种兑换码的领取装置。To achieve the above object, according to another aspect of the embodiments of the present invention, a device for receiving a redemption code is provided.
本发明实施例的一种兑换码的领取装置,包括:校验模块,用于根据兑换码的发放量和总库存量,对所述发放量进行校验;查找模块,用于当校验通过时获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列;返回模块,用于采用出栈命令从所述存储队列中获取所述兑换码,以在获取的所述兑换码不为空时,返回所述兑换码。A device for receiving a redemption code according to an embodiment of the present invention includes: a verification module for verifying the issued amount according to the issued amount of the redemption code and the total inventory; a search module for when the verification passes When obtaining the pointer of the redemption code, the corresponding storage queue for storing the redemption code is found through the current pointer; the return module is used to obtain the redemption code from the storage queue by using a pop command to store the redemption code in the When the obtained redemption code is not empty, the redemption code is returned.
可选地,所述装置还包括:更新推送模块,用于若所述兑换码返回成功,更新所述兑换码的领取状态;以及若所述兑换码返回失败,采用压栈命令将所述兑换码推送到所述当前指针对应的存储队列中。Optionally, the device further includes: an update push module, configured to update the receiving state of the redemption code if the redemption code returns successfully; and if the redemption code fails to return, use a push command to convert the redemption code The code is pushed to the storage queue corresponding to the current pointer.
可选地,所述装置还包括:指针更新模块,用于若获取的所述兑换码为空且所述当前指针小于所述存储队列的数量,将下一指针作为所述当前指针。Optionally, the apparatus further includes: a pointer updating module, configured to use the next pointer as the current pointer if the acquired redemption code is empty and the current pointer is smaller than the number of the storage queues.
可选地,所述装置还包括:自增模块,用于将所述兑换码的发放量自增;所述校验模块,还用于:将自增后的所述发放量与总库存量进行比较,根据比较结果判断校验是否通过。Optionally, the device further includes: an auto-increment module for auto-increasing the issued amount of the redemption code; the verification module, further for: adding the auto-incremented issued amount to the total inventory Compare and judge whether the verification is passed or not according to the comparison result.
可选地,所述装置还包括:存储模块,用于根据所述兑换码的总数量和所述存储队列的存储数量,将所述兑换码存储到Redis数据库的至少一个所述存储队列中。Optionally, the apparatus further includes: a storage module, configured to store the redemption codes in at least one of the storage queues of the Redis database according to the total number of redemption codes and the storage quantity of the storage queues.
为实现上述目的,根据本发明实施例的再一方面,提供了一种电子设备。To achieve the above object, according to yet another aspect of the embodiments of the present invention, an electronic device is provided.
本发明实施例的一种电子设备,包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种兑换码的领取方法。An electronic device according to an embodiment of the present invention includes: one or more processors; and a storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, The one or more processors are caused to implement a method for receiving a redemption code according to an embodiment of the present invention.
为实现上述目的,根据本发明实施例的再一方面,提供了一种计算机可读介质。To achieve the above object, according to yet another aspect of the embodiments of the present invention, a computer-readable medium is provided.
本发明实施例的一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种兑换码的领取方法。A computer-readable medium according to an embodiment of the present invention stores a computer program thereon, and when the program is executed by a processor, a method for obtaining a redemption code according to an embodiment of the present invention is implemented.
上述发明中的一个实施例具有如下优点或有益效果:通过指针定位存储队列,并采用出栈命令从存储队列中获取兑换码,能够有效防止并发获取兑换码时,同一兑换码被重复领取;通过压栈命令将返回失败的兑换码重新推送到当前指针对应的存储队列中,以使该兑换码能够重新被领取;在校验前,将兑换码的发放量自增,能够预先占用兑换码,以防止并发请求时,兑换码最终的发放量多于总库存量;当存储队列中的兑换码为空时,能够通过指针自动切换到下一个存储队列;将兑换码存储在Redis数据库的多个存储队列中,在高并发场景下保证兑换码的正常领取,效率高,稳定性好。One embodiment of the above invention has the following advantages or beneficial effects: locating the storage queue through a pointer, and using a pop-out command to obtain a redemption code from the storage queue, which can effectively prevent the same redemption code from being repeatedly collected when concurrently acquiring the redemption code; The push command pushes the failed redemption code to the storage queue corresponding to the current pointer, so that the redemption code can be reclaimed; before the verification, the issued amount of the redemption code is automatically increased, so that the redemption code can be occupied in advance, In order to prevent concurrent requests, the final issuance of the redemption code is more than the total inventory; when the redemption code in the storage queue is empty, it can automatically switch to the next storage queue through the pointer; store the redemption code in multiple Redis database. In the storage queue, the normal collection of redemption codes is guaranteed in high concurrency scenarios, with high efficiency and good stability.
上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.
附图说明Description of drawings
附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:
图1是根据本发明实施例的兑换码的领取方法的主要步骤的示意图;1 is a schematic diagram of the main steps of a method for collecting a redemption code according to an embodiment of the present invention;
图2是根据本发明实施例的兑换码的领取方法的主要流程示意图;FIG. 2 is a schematic flowchart of a main flow of a method for receiving a redemption code according to an embodiment of the present invention;
图3是根据本发明实施例的兑换码的领取装置的主要模块的示意图;3 is a schematic diagram of the main modules of a redemption code claiming device according to an embodiment of the present invention;
图4是本发明实施例可以应用于其中的示例性系统架构图;4 is an exemplary system architecture diagram to which an embodiment of the present invention may be applied;
图5是适用于来实现本发明实施例的电子设备的计算机装置的结构示意图。FIG. 5 is a schematic structural diagram of a computer apparatus suitable for implementing the electronic device according to the embodiment of the present invention.
具体实施方式Detailed ways
以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. 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 from the following description for clarity and conciseness.
图1是根据本发明实施例的兑换码的领取方法的主要步骤的示意图。如图1所示,本发明实施例的兑换码的领取方法,主要包括如下步骤:FIG. 1 is a schematic diagram of main steps of a method for collecting a redemption code according to an embodiment of the present invention. As shown in FIG. 1 , the method for receiving a redemption code according to an embodiment of the present invention mainly includes the following steps:
步骤S101:根据兑换码的发放量和总库存量,对所述发放量进行校验。将兑换码的发放量与总库存量进行大小比较,如果所述发放量小于等于所述总库存量,说明校验通过;如果所述发放量大于所述总库存量,说明校验未通过。实时例中,为了防止并发请求时,兑换码最终的发放量多于总库存量,预先将兑换码的发放量自增1,如果自增后的所述发放量小于等于所述总库存量,说明校验通过;如果自增后的所述发放量大于所述总库存量,说明校验未通过,将所述兑换码的发放量自减1。Step S101: Verify the issued amount according to the issued amount of the redemption code and the total inventory. Compare the issued amount of the redemption code with the total inventory. If the issued amount is less than or equal to the total inventory, the verification has passed; if the issued amount is greater than the total inventory, the verification has failed. In the real-time example, in order to prevent concurrent requests, the final issued amount of the redemption code is more than the total inventory, the issued amount of the redemption code is automatically incremented by 1 in advance. If the issued amount after the automatic increase is less than or equal to the total inventory, Indicates that the verification has passed; if the issued amount after the self-increment is greater than the total inventory, it indicates that the verification has not passed, and the issued amount of the redemption code is automatically decremented by 1.
步骤S102:当校验通过时获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列。其中,所述指针为存储队列的序号(list_count)。存储队列所在的数据库为K-V(Key-Value,键值对)数据库,比如Redis数据库、Memcached数据库。Redis是一个高性能的Key-Value存储系统,它支持存储的Value类型包括String(字符串)、List(链表)、Set(集合)和Zset(有序集合);Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。如果兑换码被存储在多个存储队列,则该步骤获取到的指针为多个存储队列的序号,当前指针的初始值为最小的序号,之后每次查找,指针递增1。比如,当前指针为2,则查找到的存储队列为list_2。Step S102: When the verification is passed, the pointer of the redemption code is obtained, and the corresponding storage queue for storing the redemption code is found through the current pointer. The pointer is the sequence number (list_count) of the storage queue. The database where the storage queue is located is a K-V (Key-Value, key-value pair) database, such as Redis database and Memcached database. Redis is a high-performance Key-Value storage system, which supports stored Value types including String (string), List (linked list), Set (collection) and Zset (ordered collection); Memcached is a high-performance distributed In-memory object caching system for dynamic web applications to reduce database load. If the redemption codes are stored in multiple storage queues, the pointers obtained in this step are the serial numbers of the multiple storage queues, the initial value of the current pointer is the smallest serial number, and the pointer is incremented by 1 for each subsequent search. For example, if the current pointer is 2, the found storage queue is list_2.
步骤S103:采用出栈命令从所述存储队列中获取兑换码,以在获取的所述兑换码不为空时,返回所述兑换码。实施例中,采用Redis数据库的LPOP命令从存储队列中获取兑换码。LPOP命令用于从存储队列的左边出队一个元素。获取到兑换码后,判断获取的兑换码是否为空,如果为空且所述当前指针小于所述存储队列的数量,将下一指针作为所述当前指针;如果不为空,则将所述兑换码返回至用户。Step S103: Use a pop command to obtain a redemption code from the storage queue, so as to return the redemption code when the obtained redemption code is not empty. In the embodiment, the redemption code is obtained from the storage queue by using the LPOP command of the Redis database. The LPOP command is used to dequeue an element from the left of the store queue. After obtaining the redemption code, determine whether the obtained redemption code is empty. If it is empty and the current pointer is less than the number of the storage queue, the next pointer is used as the current pointer; if it is not empty, the The redemption code is returned to the user.
图2是根据本发明实施例的兑换码的领取方法的主要流程示意图。如图2所示,本发明实施例的兑换码的领取方法,主要包括如下步骤:FIG. 2 is a schematic flowchart of a main flow of a method for collecting a redemption code according to an embodiment of the present invention. As shown in FIG. 2 , the method for receiving a redemption code according to an embodiment of the present invention mainly includes the following steps:
步骤S201:根据兑换码的总数量和存储队列的存储数量,将所述兑换码存储到至少一个所述存储队列中。其中,所述兑换码的总数量为商家上传至Redis数据库的兑换码的数量;所述存储队列的存储数量为存储队列最大能存储的兑换码的数量。实施例中,该存储队列存储在Redis数据库中。该步骤需首先计算出存储队列的数量,计算公式为:Step S201: Store the redemption codes in at least one of the storage queues according to the total quantity of redemption codes and the storage quantity of the storage queues. Wherein, the total number of redemption codes is the number of redemption codes uploaded by the merchant to the Redis database; the storage quantity of the storage queue is the maximum number of redemption codes that the storage queue can store. In an embodiment, the storage queue is stored in a Redis database. In this step, the number of storage queues needs to be calculated first. The calculation formula is:
式中,为向上取整。In the formula, to round up.
每个存储队列可以用list_count_兑换码发放活动的活动标识来区分,比如list_2_1902。Each storage queue can be distinguished by the activity ID of the list_count_redemption code issuance activity, such as list_2_1902.
比如,一个兑换码发放活动的活动标识(Identification,ID)为1902,商家上传至数据库的兑换码的总数量为103个,每个存储队列的存储数量为10,则活动ID为1902的兑换码发放活动所需要的 For example, the activity identification (ID) of a redemption code issuance activity is 1902, the total number of redemption codes uploaded by the merchant to the database is 103, and the storage quantity of each storage queue is 10, then the activity ID is the redemption code of 1902 required for distribution
步骤S202:接收兑换码获取请求,将所述兑换码的发放量自增。用户通过客户端向服务端发送兑换码获取请求,兑换码获取请求中包括活动ID。服务端接收到兑换码获取请求后进行解析,之后将归属于该活动ID的兑换码的发放量自增1。每接收到一个兑换码获取请求,则将兑换码的发放量自增1,这样能够预先占用一个兑换码,以防止并发请求时,兑换码最终的发放量多于总库存量。Step S202: Receive a redemption code acquisition request, and automatically increase the issued amount of the redemption code. The user sends a redemption code acquisition request to the server through the client, and the redemption code acquisition request includes the activity ID. After receiving the redemption code acquisition request, the server parses it, and then automatically increments the issued amount of redemption codes belonging to the activity ID by 1. Each time a redemption code acquisition request is received, the issued amount of the redemption code is automatically increased by 1, so that a redemption code can be pre-occupied to prevent the final issued amount of the redemption code than the total inventory when concurrent requests are made.
步骤S203:判断自增后的所述发放量是否大于总库存量,如果自增后的所述发放量大于所述总库存量,则执行步骤S204;若自增后的所述发放量小于等于所述总库存量,则执行步骤S205。其中,总库存量是指本次兑换码发放活动预计发放的兑换码的总数量。Step S203: Determine whether the issued amount after the self-increase is greater than the total inventory, and if the issued amount after the self-increase is greater than the total inventory, execute step S204; if the issued amount after the self-increase is less than or equal to For the total inventory, step S205 is executed. Among them, the total inventory refers to the total number of redemption codes expected to be issued in this redemption code issuance activity.
步骤S204:将所述兑换码的发放量自减,执行步骤S214。实施例中,将兑换码的发放量自减1。如果自增后的所述发放量大于所述总库存量,说明兑换码已经全部被领取,用户不能领取到兑换码,由于在步骤S202中预先对兑换码的发放量已经增加1,故此处需要再减少1,以符合兑换码的实际发放量。Step S204: Decrease the issued amount of the redemption code, and execute Step S214. In the embodiment, the issued amount of the redemption code is decremented by 1. If the self-increased distribution amount is greater than the total inventory, it means that all the redemption codes have been received, and the user cannot receive the redemption codes. Since the issued amount of the redemption codes has been increased by 1 in step S202 in advance, it is necessary to Decrease 1 again to match the actual amount of redemption codes issued.
步骤S205:获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列。所述指针为list_count,存储于Redis数据库中。比如,获取到的指针为2、3和4,则当前指针为2,查找指针2所对应的存储队列list_2。Step S205: Obtain the pointer of the redemption code, and find a corresponding storage queue for storing the redemption code through the current pointer. The pointer is list_count, which is stored in the 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 pointer 2 is searched.
步骤S206:采用出栈命令从所述存储队列中获取所述兑换码。实施例中,采用LPOP命令从存储队列中获取兑换码,此命令是原子性的,线程安全,即同一时刻只允许一个线程取得兑换码,其他线程排队等待,避免多个线程同一时刻取得同一个兑换码。另外,使用该命令查询效率高,能够使兑换码在获取的同时从存储队列中删除,可以有效防止并发获取重复兑换码。Step S206: Obtain the redemption code from the storage queue by using a pop command. In the embodiment, the LPOP command is used to obtain the redemption code from the storage queue. This command is atomic and thread-safe, that is, only one thread is allowed to obtain the redemption code at the same time, and other threads wait in line to prevent multiple threads from obtaining the same code at the same time. redemption code. In addition, using this command has high query efficiency, and the redemption code can be deleted from the storage queue at the same time as it is acquired, which can effectively prevent the concurrent acquisition of duplicate redemption codes.
步骤S207:判断获取的所述兑换码是否为空,如果为空,则执行步骤S208;如果不为空,则执行步骤S210。Step S207: Determine whether the obtained redemption code is empty, if it is empty, go to step S208; if it is not empty, go to step S210.
步骤S208:判断当前指针是否小于所述存储队列的数量,如果所述当前指针小于所述存储队列的数量,则执行步骤S209;如果所述当前指针大于等于所述存储队列的数量,则执行步骤S214。如果当前指针大于等于存储队列的数量,说明兑换码已经全部被领取。Step S208: determine whether the current pointer is less than the number of the storage queues, if the current pointer is less than the number of the storage queues, then perform step S209; if the current pointer is greater than or equal to the number of the storage queues, perform step S209 S214. If the current pointer is greater than or equal to the number of storage queues, it means that all redemption codes have been received.
步骤S209:将下一指针作为所述当前指针,通过所述当前指针查找到相应的用于存储所述兑换码的存储队列,执行步骤S206。假设当前指针为2,将当前指针自增1,即查找指针3对应的存储队列为list_3。Step S209: take the next pointer as the current pointer, find a corresponding storage queue for storing the redemption code through the current pointer, and execute step S206. Assuming that the current pointer is 2, the current pointer is incremented by 1, that is, the storage queue corresponding to the search pointer 3 is list_3.
步骤S210:返回所述兑换码。服务端将获取的兑换码返回至客户端。Step S210: Return the redemption code. The server returns the obtained redemption code to the client.
步骤S211:判断所述兑换码是否返回成功,如果返回成功,则执行步骤S212;如果返回失败,则执行步骤S213。Step S211: Determine whether the redemption code is returned successfully, if the return is successful, go to step S212; if the return fails, go to step S213.
步骤S212:更新所述兑换码的领取状态。如果兑换码成功返回至客户端,说明兑换码领取成功,将兑换码的领取状态更新为“领取成功”。该步骤为异步执行,大大减少耗时,缓解数据库压力。Step S212: Update the receiving status of the redemption code. If the redemption code is successfully returned to the client, it means that the redemption code has been received successfully, and the redemption code redemption status will be updated to "Received Successfully". This step is executed asynchronously, which greatly reduces time-consuming and relieves database pressure.
步骤S213:采用压栈命令将所述兑换码推送到所述当前指针对应的存储队列中。实施例中,采用RPUSH命令从存储队列中获取兑换码。RPUSH命令是Redis数据库的一种操作命令,用于从存储队列的右边入队一个元素或多个元素。使用RPUSH命令能够将兑换码重新放回到未领取的存储队列中,以在收到兑换码获取请求后,能够重新被领取。Step S213: Push the redemption code to the storage queue corresponding to the current pointer by using a push command. In the embodiment, the redemption code is obtained from the storage queue using the RPUSH command. The RPUSH command is an operation command of the Redis database, which is used to enqueue an element or multiple elements from the right side of the storage queue. Using the RPUSH command, the redemption code can be put back into the unclaimed storage queue, so that it can be reclaimed after receiving the redemption code acquisition request.
步骤S214:返回提示信息,结束本流程。实施例中,可向客户端返回“已抢光”的提示信息。Step S214: Return to the prompt information, and end the process. In the embodiment, the prompt information of "sold out" may be returned to the client.
在一优选的实施例中,可以将多个存储队列分散到不同的Redis节点中,以保证每个节点之间的负载均衡,缓解Redis数据库的压力。In a preferred embodiment, multiple storage queues can be distributed to different Redis nodes to ensure load balance between each node and relieve the pressure on the Redis database.
通过本发明实施例的兑换码的领取方法可以看出,通过指针定位存储队列,并采用出栈命令从存储队列中获取兑换码,能够有效防止并发获取兑换码时,同一兑换码被重复领取;通过压栈命令将返回失败的兑换码重新推送到当前指针对应的存储队列中,以使该兑换码能够重新被领取;在校验前,将兑换码的发放量自增,能够预先占用兑换码,以防止并发请求时,兑换码最终的发放量多于总库存量;当存储队列中的兑换码为空时,能够通过指针自动切换到下一个存储队列;将兑换码存储在Redis数据库的多个存储队列中,在高并发场景下保证兑换码的正常领取,效率高,稳定性好。It can be seen from the method for receiving a redemption code of the embodiment of the present invention that the storage queue is located by a pointer, and the redemption code is obtained from the storage queue by using a pop command, which can effectively prevent the same redemption code from being repeatedly received when concurrently acquiring the redemption code; Re-push the failed redemption code to the storage queue corresponding to the current pointer through the push command, so that the redemption code can be reclaimed; before the verification, the issued amount of the redemption code is automatically increased, so that the redemption code can be pre-occupied , to prevent the final issuance of the redemption code is more than the total inventory during concurrent requests; when the redemption code in the storage queue is empty, it can automatically switch to the next storage queue through the pointer; store the redemption code in the Redis database. In a storage queue, the normal collection of redemption codes is guaranteed in high concurrency scenarios, with high efficiency and good stability.
图3是根据本发明实施例的兑换码的领取装置的主要模块的示意图。如图3所示,本发明实施例的兑换码的领取装置300,主要包括:FIG. 3 is a schematic diagram of main modules of a redemption code claiming apparatus according to an embodiment of the present invention. As shown in FIG. 3 , the redemption code receiving device 300 according to the embodiment of the present invention mainly includes:
校验模块301,用于根据兑换码的发放量和总库存量,对所述发放量进行校验。将兑换码的发放量与总库存量进行大小比较,如果所述发放量小于等于所述总库存量,说明校验通过;如果所述发放量大于所述总库存量,说明校验未通过。实时例中,为了防止并发请求时,兑换码最终的发放量多于总库存量,预先将兑换码的发放量自增1,如果自增后的所述发放量小于等于所述总库存量,说明校验通过;如果自增后的所述发放量大于所述总库存量,说明校验未通过,将所述兑换码的发放量自减1。The verification module 301 is configured to verify the issued amount according to the issued amount of the redemption code and the total inventory amount. Compare the issued amount of the redemption code with the total inventory. If the issued amount is less than or equal to the total inventory, the verification has passed; if the issued amount is greater than the total inventory, the verification has failed. In the real-time example, in order to prevent concurrent requests, the final issued amount of the redemption code is more than the total inventory, the issued amount of the redemption code is automatically incremented by 1 in advance. If the issued amount after the automatic increase is less than or equal to the total inventory, Indicates that the verification has passed; if the issued amount after the self-increment is greater than the total inventory, it indicates that the verification has not passed, and the issued amount of the redemption code is automatically decremented by 1.
查找模块302,用于当校验通过时获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列。其中,所述指针为存储队列的序号(list_count)。存储队列所在的数据库为K-V数据库,比如Redis数据库、Memcached数据库。如果兑换码被存储在多个存储队列,则该步骤获取到的指针为多个存储队列的序号,当前指针的初始值为最小的序号,之后每次查找,指针递增1。比如,当前指针为2,则查找到的存储队列为list_2。The search module 302 is configured to obtain the pointer of the redemption code when the verification is passed, and find the corresponding storage queue for storing the redemption code through the current pointer. The pointer is the sequence number (list_count) of the storage queue. The database where the storage queue is located is a K-V database, such as Redis database and Memcached database. If the redemption codes are stored in multiple storage queues, the pointers obtained in this step are the serial numbers of the multiple storage queues, the initial value of the current pointer is the smallest serial number, and the pointer is incremented by 1 for each subsequent search. For example, if the current pointer is 2, the found storage queue is list_2.
返回模块303,用于采用出栈命令从所述存储队列中获取所述兑换码,以在获取的所述兑换码不为空时,返回所述兑换码。实施例中,采用Redis数据库的LPOP命令从存储队列中获取兑换码。LPOP命令用于从存储队列的左边出队一个元素。获取到兑换码后,判断获取的兑换码是否为空,如果为空且所述当前指针小于所述存储队列的数量,将下一指针作为所述当前指针;如果不为空,则将所述兑换码返回至用户。Returning module 303, configured to acquire the redemption code from the storage queue by using a pop command, so as to return the redemption code when the acquired redemption code is not empty. In the embodiment, the redemption code is obtained from the storage queue by using the LPOP command of the Redis database. The LPOP command is used to dequeue an element from the left of the store queue. After obtaining the redemption code, determine whether the obtained redemption code is empty. If it is empty and the current pointer is less than the number of the storage queue, the next pointer is used as the current pointer; if it is not empty, the The redemption code is returned to the user.
另外,本发明实施例的兑换码的领取装置300还可以包括:更新推送模块、指针更新模块、自增模块和存储模块(图3中未示出)。其中,所述更新推送模块,用于若所述兑换码返回成功,更新所述兑换码的领取状态;以及若所述兑换码返回失败,采用压栈命令将所述兑换码推送到所述当前指针对应的存储队列中。所述指针更新模块,用于若获取的所述兑换码为空且所述当前指针小于所述存储队列的数量,将下一指针作为所述当前指针。所述自增模块,用于将所述兑换码的发放量自增。所述存储模块,用于根据所述兑换码的总数量和所述存储队列的存储数量,将所述兑换码存储到Redis数据库的至少一个所述存储队列中。In addition, the apparatus 300 for redeeming codes according to the embodiment of the present invention may further include: an update push module, a pointer update module, an auto-increment module, and a storage module (not shown in FIG. 3 ). Wherein, the update push module is configured to update the receiving status of the redemption code if the redemption code returns successfully; and if the redemption code fails to return, push the redemption code to the current The pointer corresponds to the storage queue. The pointer updating module is configured to use the next pointer as the current pointer if the acquired redemption code is empty and the current pointer is smaller than the number of the storage queue. The self-increasing module is used for self-increasing the issued amount of the redemption code. The storage module is configured to store the redemption codes in at least one of the storage queues of the Redis database according to the total quantity of the redemption codes and the storage quantity of the storage queues.
从以上描述可以看出,通过指针定位存储队列,并采用出栈命令从存储队列中获取兑换码,能够有效防止并发获取兑换码时,同一兑换码被重复领取;通过压栈命令将返回失败的兑换码重新推送到当前指针对应的存储队列中,以使该兑换码能够重新被领取;在校验前,将兑换码的发放量自增,能够预先占用兑换码,以防止并发请求时,兑换码最终的发放量多于总库存量;当存储队列中的兑换码为空时,能够通过指针自动切换到下一个存储队列;将兑换码存储在Redis数据库的多个存储队列中,在高并发场景下保证兑换码的正常领取,效率高,稳定性好。As can be seen from the above description, positioning the storage queue through the pointer and using the pop command to obtain the redemption code from the storage queue can effectively prevent the same redemption code from being repeatedly obtained when the redemption code is obtained concurrently; The redemption code is re-pushed to the storage queue corresponding to the current pointer, so that the redemption code can be reclaimed; before the verification, the issued amount of the redemption code is automatically increased, and the redemption code can be occupied in advance to prevent the redemption code during concurrent requests. The final distribution of the code is more than the total inventory; when the redemption code in the storage queue is empty, it can automatically switch to the next storage queue through the pointer; store the redemption code in multiple storage queues in the Redis database, in high concurrency In the scenario, the normal collection of the redemption code is guaranteed, with high efficiency and good stability.
图4示出了可以应用本发明实施例的兑换码的领取方法或兑换码的领取装置的示例性系统架构400。FIG. 4 shows an exemplary system architecture 400 of a method for collecting a redemption code or an apparatus for collecting a redemption code to which an embodiment of the present invention can be applied.
如图4所示,系统架构400可以包括终端设备401、402、403,网络404和服务器405。网络404用以在终端设备401、402、403和服务器405之间提供通信链路的介质。网络404可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 4 , the system architecture 400 may include terminal devices 401 , 402 , and 403 , a network 404 and a server 405 . The network 404 is a medium used to provide a communication link between the terminal devices 401 , 402 , 403 and the server 405 . The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
用户可以使用终端设备401、402、403通过网络404与服务器405交互,以接收或发送消息等。终端设备401、402、403上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等。The user can use the terminal devices 401, 402, 403 to interact with the server 405 through the network 404 to receive or send messages and the like. Various communication client applications may be installed on the terminal devices 401 , 402 and 403 , such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, and the like.
终端设备401、402、403可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。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 computers, desktop computers, and the like.
服务器405可以是提供各种服务的服务器,例如对用户利用终端设备401、402、403发送来的兑换码获取请求提供支持的后台管理服务器。后台管理服务器可以对接收到的兑换码获取请求进行分析等处理,并将处理结果(例如兑换码)反馈给终端设备。The server 405 may be a server that provides various services, for example, a background management server that provides support for obtaining requests for redemption codes sent by users using the terminal devices 401 , 402 , and 403 . The background management server can analyze and process the received redemption code acquisition request, and feed back the processing result (for example, the redemption code) to the terminal device.
需要说明的是,本申请实施例所提供的兑换码的领取方法一般由服务器405执行,相应地,兑换码的领取装置一般设置于服务器405中。It should be noted that the method for collecting the redemption code provided by the embodiment of the present application is generally performed by the server 405 , and accordingly, the device for collecting the redemption code is generally set in the server 405 .
应该理解,图4中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 4 are merely illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.
根据本发明的实施例,本发明还提供了一种电子设备和一种计算机可读介质。According to an embodiment of the present invention, the present invention further provides an electronic device and a computer-readable medium.
本发明的电子设备包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例的一种兑换码的领取方法。The electronic device of the present invention comprises: one or more processors; storage means for storing one or more programs, when the one or more programs are executed by the one or more processors, so that the one or more programs A plurality of processors implement a method for receiving a redemption code according to an embodiment of the present invention.
本发明的计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例的一种兑换码的领取方法。The computer-readable medium of the present invention has a computer program stored thereon, and when the program is executed by the processor, a method for obtaining a redemption code according to an embodiment of the present invention is implemented.
下面参考图5,其示出了适用于来实现本发明实施例的电子设备的计算机系统500的结构示意图。图5示出的电子设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring to FIG. 5 below, it shows a schematic structural diagram of a computer system 500 suitable for implementing an electronic device according to an embodiment of the present invention. The electronic device shown in FIG. 5 is only an example, and should not impose any limitation on the function and scope of use of the embodiments of the present invention.
如图5所示,计算机系统500包括中央处理单元(CPU)501,其可以根据存储在只读存储器(ROM)502中的程序或者从存储部分508加载到随机访问存储器(RAM)503中的程序而执行各种适当的动作和处理。在RAM 503中,还存储有计算机系统500操作所需的各种程序和数据。CPU 501、ROM 502以及RAM 503通过总线504彼此相连。输入/输出(I/O)接口505也连接至总线504。As shown in FIG. 5, a computer system 500 includes a central processing unit (CPU) 501 which can be loaded into a random access memory (RAM) 503 according to a program stored in a read only memory (ROM) 502 or a program from a storage section 508 Instead, various appropriate actions and processes are performed. In the RAM 503, various programs and data necessary for the operation of the computer system 500 are also stored. The CPU 501 , the ROM 502 , and the RAM 503 are connected to each other through a bus 504 . An input/output (I/O) interface 505 is also connected to bus 504 .
以下部件连接至I/O接口505:包括键盘、鼠标等的输入部分506;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分507;包括硬盘等的存储部分508;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分509。通信部分509经由诸如因特网的网络执行通信处理。驱动器510也根据需要连接至I/O接口505。可拆卸介质511,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器510上,以便于从其上读出的计算机程序根据需要被安装入存储部分508。The following components are connected to the I/O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc. ; and a communication section 509 including a network interface card such as a LAN card, a modem, and the like. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 510 as needed so that a computer program read therefrom is installed into the storage section 508 as needed.
特别地,根据本发明公开的实施例,上文主要步骤图描述的过程可以被实现为计算机软件程序。例如,本公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行主要步骤图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分509从网络上被下载和安装,和/或从可拆卸介质511被安装。在该计算机程序被中央处理单元(CPU)501执行时,执行本发明的系统中限定的上述功能。In particular, according to the disclosed embodiments of the present invention, the processes described in the main step diagrams above may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods illustrated in the main step diagrams. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 509 and/or installed from the removable medium 511 . When the computer program is executed by the central processing unit (CPU) 501, the above-described functions defined in the system of the present invention are performed.
需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The 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 a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with 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), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks 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. It is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.
描述于本发明实施例中所涉及到的模块可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的模块也可以设置在处理器中,例如,可以描述为:一种处理器包括校验模块、查找模块和返回模块。其中,这些模块的名称在某种情况下并不构成对该模块本身的限定,例如,校验模块还可以被描述为“根据兑换码的发放量和总库存量,对所述发放量进行校验的模块”。The modules involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described module can also be set in the processor, for example, it can be described as: a processor includes a check module, a search module and a return module. Among them, the names of these modules do not constitute a limitation of the module itself under certain circumstances. For example, the verification module can also be described as "according to the issued amount of the redemption code and the total inventory, the issued amount is verified. test module".
作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:根据兑换码的发放量和总库存量,对所述发放量进行校验;当校验通过时获取所述兑换码的指针,通过当前指针查找到相应的用于存储所述兑换码的存储队列;采用出栈命令从所述存储队列中获取所述兑换码,以在获取的所述兑换码不为空时,返回所述兑换码。As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by one of the equipment, the equipment includes: according to the issued amount and the total inventory amount of the redemption code, correcting the issued amount. When the verification is passed, the pointer of the redemption code is obtained, and the corresponding storage queue for storing the redemption code is found through the current pointer; the redemption code is obtained from the storage queue by using a pop command, to When the obtained redemption code is not empty, the redemption code is returned.
从以上描述可以看出,通过指针定位存储队列,并采用出栈命令从存储队列中获取兑换码,能够有效防止并发获取兑换码时,同一兑换码被重复领取;通过压栈命令将返回失败的兑换码重新推送到当前指针对应的存储队列中,以使该兑换码能够重新被领取;在校验前,将兑换码的发放量自增,能够预先占用兑换码,以防止并发请求时,兑换码最终的发放量多于总库存量;当存储队列中的兑换码为空时,能够通过指针自动切换到下一个存储队列;将兑换码存储在Redis数据库的多个存储队列中,在高并发场景下保证兑换码的正常领取,效率高,稳定性好。As can be seen from the above description, positioning the storage queue through the pointer and using the pop command to obtain the redemption code from the storage queue can effectively prevent the same redemption code from being repeatedly obtained when the redemption code is obtained concurrently; The redemption code is re-pushed to the storage queue corresponding to the current pointer, so that the redemption code can be reclaimed; before the verification, the issued amount of the redemption code is automatically increased, and the redemption code can be occupied in advance to prevent the redemption code during concurrent requests. The final distribution of the code is more than the total inventory; when the redemption code in the storage queue is empty, it can automatically switch to the next storage queue through the pointer; store the redemption code in multiple storage queues in the Redis database, in high concurrency In the scenario, the normal collection of the redemption code is guaranteed, with high efficiency and good stability.
上述产品可执行本发明实施例所提供的方法,具备执行方法相应的功能模块和有益效果。未在本实施例中详尽描述的技术细节,可参见本发明实施例所提供的方法。The above product can execute the method provided by the embodiment of the present invention, and has corresponding functional modules and beneficial effects for executing the method. For technical details not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims (12)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810790916.XA CN110738507A (en) | 2018-07-18 | 2018-07-18 | Method and device for receiving a redemption code |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810790916.XA CN110738507A (en) | 2018-07-18 | 2018-07-18 | Method and device for receiving a redemption code |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN110738507A true CN110738507A (en) | 2020-01-31 |
Family
ID=69235015
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201810790916.XA Pending CN110738507A (en) | 2018-07-18 | 2018-07-18 | Method and device for receiving a redemption code |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN110738507A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112308599A (en) * | 2020-08-31 | 2021-02-02 | 北京沃东天骏信息技术有限公司 | Redemption code issuing method, system and device |
Citations (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110145125A1 (en) * | 2009-12-15 | 2011-06-16 | Trading Technologies International, Inc. | System and Methods for Risk-Based Prioritized Transaction Message Flow |
| CN103838753A (en) * | 2012-11-23 | 2014-06-04 | 腾讯科技(北京)有限公司 | Storage and verification method and device for exchange codes |
| CN104123649A (en) * | 2013-04-24 | 2014-10-29 | 深圳富泰宏精密工业有限公司 | Electronic ticket exchange system and method |
| HK1198301A1 (en) * | 2014-11-21 | 2015-03-27 | 腾讯科技(深圳)有限公司 | Storage and verification method and device for exchange codes |
| CN104851031A (en) * | 2015-03-31 | 2015-08-19 | 深圳市中润四方信息技术有限公司 | Electronic bill coding method and system |
| CN105913288A (en) * | 2016-05-31 | 2016-08-31 | 知而行(上海)营销咨询有限公司 | O2O closed-loop marketing system based on discount enjoyed by code scanning |
| US20160321568A1 (en) * | 2013-12-20 | 2016-11-03 | Smartseats Ip Bvba | Systems and methods for redistributing tickets to an event |
| CN106156309A (en) * | 2016-07-01 | 2016-11-23 | 五八同城信息技术有限公司 | Method for reading data and device |
| CN106815338A (en) * | 2016-12-25 | 2017-06-09 | 北京中海投资管理有限公司 | A kind of real-time storage of big data, treatment and inquiry system |
| CN107302488A (en) * | 2016-04-14 | 2017-10-27 | 阿里巴巴集团控股有限公司 | Distribution method, system and the server of virtual objects |
| CN108133399A (en) * | 2016-11-30 | 2018-06-08 | 北京京东尚科信息技术有限公司 | The second of high concurrent fast-response kills the method, apparatus and system that inventory precisely reduces |
-
2018
- 2018-07-18 CN CN201810790916.XA patent/CN110738507A/en active Pending
Patent Citations (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110145125A1 (en) * | 2009-12-15 | 2011-06-16 | Trading Technologies International, Inc. | System and Methods for Risk-Based Prioritized Transaction Message Flow |
| CN103838753A (en) * | 2012-11-23 | 2014-06-04 | 腾讯科技(北京)有限公司 | Storage and verification method and device for exchange codes |
| CN104123649A (en) * | 2013-04-24 | 2014-10-29 | 深圳富泰宏精密工业有限公司 | Electronic ticket exchange system and method |
| US20160321568A1 (en) * | 2013-12-20 | 2016-11-03 | Smartseats Ip Bvba | Systems and methods for redistributing tickets to an event |
| HK1198301A1 (en) * | 2014-11-21 | 2015-03-27 | 腾讯科技(深圳)有限公司 | Storage and verification method and device for exchange codes |
| CN104851031A (en) * | 2015-03-31 | 2015-08-19 | 深圳市中润四方信息技术有限公司 | Electronic bill coding method and system |
| CN107302488A (en) * | 2016-04-14 | 2017-10-27 | 阿里巴巴集团控股有限公司 | Distribution method, system and the server of virtual objects |
| CN105913288A (en) * | 2016-05-31 | 2016-08-31 | 知而行(上海)营销咨询有限公司 | O2O closed-loop marketing system based on discount enjoyed by code scanning |
| CN106156309A (en) * | 2016-07-01 | 2016-11-23 | 五八同城信息技术有限公司 | Method for reading data and device |
| CN108133399A (en) * | 2016-11-30 | 2018-06-08 | 北京京东尚科信息技术有限公司 | The second of high concurrent fast-response kills the method, apparatus and system that inventory precisely reduces |
| CN106815338A (en) * | 2016-12-25 | 2017-06-09 | 北京中海投资管理有限公司 | A kind of real-time storage of big data, treatment and inquiry system |
Non-Patent Citations (2)
| Title |
|---|
| ADA多一多: "构架稳定与可扩展的优惠券系统", HTTPS://WWW.CNBLOGS.COM/ADA-OPENMIND/P/8757794.HTML * |
| 懵懂AND无知: "php+redis消息队列抢购实现", HTTPS://BLOG.CSDN.NET/LINLIN_XIA/ARTICLE/DETAILS/68944907 * |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN112308599A (en) * | 2020-08-31 | 2021-02-02 | 北京沃东天骏信息技术有限公司 | Redemption code issuing method, system and device |
| CN112308599B (en) * | 2020-08-31 | 2024-08-20 | 北京沃东天骏信息技术有限公司 | Redemption code issuing method, redemption code issuing system and redemption code issuing device |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109447641B (en) | Method and device for transmitting blockchain data to blockchain browser | |
| CN107423085B (en) | Method and apparatus for deploying applications | |
| CN111061680B (en) | A method and device for data retrieval | |
| CN110209677A (en) | The method and apparatus of more new data | |
| CN110599277A (en) | Inventory deduction method and device | |
| CN107547548A (en) | Data processing method and system | |
| CN110909022B (en) | A data query method and device | |
| CN110019258A (en) | The method and apparatus for handling order data | |
| CN110704486B (en) | Data processing method, device, system, storage medium and server | |
| CN112948138A (en) | Method and device for processing message | |
| CN114297278A (en) | Batch data fast writing method, system and device | |
| CN110555068A (en) | Data export method and device | |
| CN113282589A (en) | Data acquisition method and device | |
| CN109918191A (en) | A kind of method and apparatus of the anti-frequency of service request | |
| CN113783924B (en) | A method and device for processing access request | |
| CN113761565B (en) | Data desensitization method and device | |
| CN115529271B (en) | Service request distribution method, device, equipment and medium | |
| CN107291923B (en) | Information processing method and device | |
| CN113326416B (en) | Method for searching data, method and device for sending search data to client | |
| CN110738507A (en) | Method and device for receiving a redemption code | |
| CN107657155B (en) | Method and device for authenticating user operation authority | |
| CN114581047A (en) | Request processing method and device | |
| CN113760860A (en) | Data reading method and device | |
| CN110110211B (en) | Data query method and device based on universal model | |
| CN112115165B (en) | Data processing method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| CB02 | Change of applicant information | ||
| CB02 | Change of applicant information |
Address after: 101111 Room 221, 2nd Floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone Applicant after: Jingdong Technology Holding Co.,Ltd. Address before: 101111 Room 221, 2nd Floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone Applicant before: Jingdong Digital Technology Holding Co.,Ltd. Address after: 101111 Room 221, 2nd Floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone Applicant after: Jingdong Digital Technology Holding Co.,Ltd. Address before: 101111 Room 221, 2nd Floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone Applicant before: JINGDONG DIGITAL TECHNOLOGY HOLDINGS Co.,Ltd. Address after: 101111 Room 221, 2nd Floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone Applicant after: JINGDONG DIGITAL TECHNOLOGY HOLDINGS Co.,Ltd. Address before: 101111 Room 221, 2nd Floor, Block C, 18 Kechuang 11th Street, Beijing Economic and Technological Development Zone Applicant before: BEIJING JINGDONG FINANCIAL TECHNOLOGY HOLDING Co.,Ltd. |
|
| RJ01 | Rejection of invention patent application after publication | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200131 |