CN109918191B - Method and device for preventing frequency of service request - Google Patents

Method and device for preventing frequency of service request Download PDF

Info

Publication number
CN109918191B
CN109918191B CN201711329279.8A CN201711329279A CN109918191B CN 109918191 B CN109918191 B CN 109918191B CN 201711329279 A CN201711329279 A CN 201711329279A CN 109918191 B CN109918191 B CN 109918191B
Authority
CN
China
Prior art keywords
frequency
return value
cache key
service code
configuration information
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.)
Active
Application number
CN201711329279.8A
Other languages
Chinese (zh)
Other versions
CN109918191A (en
Inventor
董焕强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201711329279.8A priority Critical patent/CN109918191B/en
Publication of CN109918191A publication Critical patent/CN109918191A/en
Application granted granted Critical
Publication of CN109918191B publication Critical patent/CN109918191B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a method and a device for preventing frequency of service requests, and relates to the technical field of computers. One embodiment of the method comprises: obtaining a cache key corresponding to the current service code, and updating the value of the cache key to obtain a return value; and comparing the return value with the anti-frequency times, and not executing the service code when the return value is determined to be greater than the anti-frequency times. The implementation mode solves the problems of high frequency failure prevention, high repeated writing rate, high workload, long network use time and the like, which are caused by simultaneously processing a plurality of services in the prior art, and has low safety reliability, thereby achieving the technical effects of reducing the frequency failure prevention and the workload, being beneficial to improving the program development efficiency and reducing the workload of programmers.

Description

Method and device for preventing frequency of service request
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for preventing frequency of service requests.
Background
With the development of the internet, more and more users bring a great pressure to providers of internet services through online shopping, making friends, obtaining information and the like, and in order to ensure that the services can bear a certain user access amount and concurrency amount, the services generally adopt a distributed deployment mode, that is, the same service is deployed to n servers, and the n servers simultaneously provide services to the outside. But because there is no communication between these n servers, it is easy to be attacked by malicious attackers (for example, DDoS attack); meanwhile, if the normal request of the user is repeatedly sent and processed by different servers, service confusion is easy to occur or a large number of exceptions occur to the servers, so that resources are wasted and the availability of the service is endangered. In order to guarantee the stability of the service, the access times of the user in a specific time are limited, namely frequency protection.
Currently, the mainstream distributed frequency prevention mode is realized by combining a SET command and a GET command in a cache Redis, wherein the Redis is a high-performance memory database and stores key value pair data. Redis uses a single-process single-thread mode, can ensure a concurrency sequence, directly processes all operations through a memory, has extremely high efficiency, and supports distributed cluster configuration.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
in the prior art, when a frequency prevention measure is taken, the problems of frequency prevention failure caused by simultaneous processing of a plurality of services, high workload caused by high repeated writing rate, long network use time and low safety and reliability exist.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for requesting frequency protection for a service, where annotation configuration information is preset in a service code, and then a comparison is performed between a return value and the annotation configuration information, so as to effectively reduce the problem of frequency failure protection and reduce workload.
To achieve the above object, according to an aspect of the embodiments of the present invention, a method for preventing a service request from being frequently generated is provided.
In the method for requesting frequency protection for a service according to an embodiment of the present invention, annotation configuration information is preset in a service code, and the annotation configuration information includes frequency protection times, and the method includes: obtaining a cache key corresponding to the current service code, and updating the value of the cache key to obtain a return value; and comparing the return value with the anti-frequency times, and not executing the service code when the return value is determined to be greater than the anti-frequency times.
Preferably, in the embodiment of the present invention, the injection configuration information further includes a cache key prefix, and the step of obtaining the cache key corresponding to the current service code includes: and splicing the obtained cache key prefix with the unique identification of the user to obtain the cache key, wherein the unique identification of the user is the unique identification of the user of the current service code.
Preferably, in the embodiment of the present invention, before the step of comparing the return value with the frequency prevention number, the method further includes: judging the size of the return value, and if the return value is equal to 1, directly executing the service code; and if the return value is greater than 1, executing a step of comparing the return value with the frequency prevention number.
Preferably, in the embodiment of the present invention, when it is determined that the return value is greater than the frequency protection number, it is determined whether the validity period of the cache key is permanent; if the data is permanent, throwing an exception; if the number of the throwing times is not permanent, the throwing times is out of limit.
Preferably, in the embodiment of the present invention, when the exception is thrown, the cache key is deleted and the service code is executed.
Preferably, the method is implemented by a profile-oriented programming framework Spring AOP configuration in the embodiment of the present invention.
To achieve the above object, according to another aspect of the present invention, there is provided a device for frequency-blocking a service request.
The device for requesting anti-frequency of service request of the embodiment of the invention presets annotation configuration information in service code, wherein the annotation configuration information comprises anti-frequency times, and the device comprises: the acquisition module is used for acquiring a cache key corresponding to the current service code and updating the value of the cache key to obtain a return value; and the processing module is used for comparing the return value with the anti-frequency times and not executing the service code when the return value is determined to be greater than the anti-frequency times.
Preferably, in the embodiment of the present invention, the injection configuration information further includes a cache key prefix, and the obtaining module is further configured to: and splicing the obtained cache key prefix with the unique identification of the user to obtain the cache key, wherein the unique identification of the user is the unique identification of the user of the current service code.
Preferably, the embodiment of the present invention further includes a determining module, configured to: judging the size of the return value, and if the return value is equal to 1, directly executing the service code; and if the return value is greater than 1, executing a step of comparing the return value with the frequency prevention number.
Preferably, in an embodiment of the present invention, the processing module is further configured to: when the return value is determined to be larger than the frequency prevention times, judging whether the validity period of the cache key is permanent or not; if the data is permanent, throwing an exception; if the number of the throwing times is not permanent, the throwing times is out of limit.
Preferably, in the embodiment of the present invention, when the exception is thrown, the cache key is deleted and the service code is executed.
Preferably, the method is implemented by a profile-oriented programming framework Spring AOP configuration in the embodiment of the present invention.
To achieve the above object, according to still another aspect of the present invention, an electronic apparatus is provided.
An electronic device of an embodiment of the present invention includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors realize the service request frequency-guard method.
To achieve the above object, according to still another aspect of the present invention, there is provided a computer-readable storage medium.
A computer-readable storage medium of an embodiment of the present invention stores thereon a computer program, wherein the computer program is executed by a processor to implement the method for preventing frequency of service request of the present invention.
One embodiment of the above invention has the following advantages or benefits: because the technical means of adding the annotation configuration information in the service code and preventing frequency by using the annotation configuration information is adopted, the problems of high frequency failure prevention, high repeated writing rate, high workload, long network use time and the like and low safety and reliability caused by simultaneous processing of a plurality of services in the prior art are solved, the technical effects of reducing the frequency failure prevention and the workload are further achieved, the program development efficiency is improved, and the workload of programmers is reduced.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts. In the drawings:
fig. 1 is a schematic diagram of a main flow of a method for service request frequency protection according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating a method for performing frequency protection on a service request according to an embodiment of the present invention;
fig. 3 is a schematic diagram of main modules of an apparatus for service request frequency protection according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
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 a main flow of a method for requesting frequency protection for a service according to an embodiment of the present invention, and as shown in fig. 1, the method for requesting frequency protection for a service according to an embodiment of the present invention mainly includes the following steps:
step S101: and obtaining a cache key corresponding to the current service code, and updating the value of the cache key to obtain a return value. The technical effect of the invention is achieved by presetting the annotation configuration information in the service code and utilizing the annotation configuration information to prevent frequency in the subsequent processing process, and the problems of high frequency failure prevention, high repeated writing rate, high workload, long network use time and the like and low safety and reliability in the prior art are solved. The manner in which the value of the cache key +1 is processed may be performed using a commonly used INCR command. The manner of updating the value of the cache key may be to update the value of the cache key itself, for example, the value of the cache key +1 is processed by the INCR command to obtain a return value. It should be noted that the value of the cache key in the present application is a numerical value returned after processing the service code, and indicates that the service code is specifically processed for the second time; the frequency protection is to ensure the stability of the service, so that a limiting mechanism needs to be made on the number of times of access of the user in a specific time.
In the embodiment of the present invention, the annotation configuration information further includes a cache key prefix, and the step of obtaining the cache key corresponding to the current service code includes: and splicing the obtained cache key prefix with the unique identification of the user to obtain the cache key, wherein the unique identification of the user is the unique identification of the user of the current service code. The unique identification of the user may take the form of a combination of the user's ID, IMS, and other forms.
Step S102: and comparing the return value with the anti-frequency times, and not executing the service code when the return value is determined to be greater than the anti-frequency times. Determining whether the current service code is abnormal or not through comparison, and if the result is that the return value is greater than the anti-frequency number, determining that the current service code is abnormal and not executing the service code; and if the return value is less than or equal to the frequency prevention times, continuously executing the service code (namely continuously judging the abnormality of the service code).
In an embodiment of the present invention, annotating configuration information further includes caching key survival time, and prior to the step of comparing the return value to the guard frequency number further includes: judging the size of the return value, if the return value is equal to 1, setting the validity period of the cache key according to the survival time of the cache key, and executing the service code; and if the return value is greater than 1, executing a step of comparing the return value with the frequency prevention number for comparison.
Specifically, after the return value is determined to be greater than the anti-frequency number, whether the validity period of the cache key is permanent needs to be judged; if the data is permanent, throwing an exception; if the number of the throwing times is not permanent, the throwing times is out of limit. The exception is classified by the message of the cache key, so that the subsequent further processing is facilitated.
In the embodiment of the present invention, a specific processing manner is that, when an exception is thrown, the cache key is deleted and the service code is executed. Of course, if the times are abnormal, and the times are abnormal. It should be noted that, in the present invention, when an exception is thrown, the cache key is deleted and the service code is executed, which is merely an example, and when a network times out or an error occurs, the cache key may also be deleted and the service code is executed.
In an embodiment of the present invention, the above determining and comparing processes are implemented by a section-oriented programming framework Spring AOP configuration. The execution step is performed after the analysis and judgment of the service code.
Fig. 2 is a flow chart illustrating a method for performing frequency protection on a service request according to an embodiment of the present invention, and before starting to describe an embodiment of the present invention, as shown in fig. 2, the following explanations are made for terms related to the present invention:
redis: a high performance memory-based key-value database can guarantee the sequentiality of command execution under the condition of concurrency.
INCR command in Redis: the value corresponding to the key is incremented and returned to the incremented value, and if the key does not exist, the value of the key is initialized to 0 and then the INCR operation is performed.
EXPIRE command in Redis: for setting the expiration time of the key.
DEL command in Redis: for deleting an existing key.
TTL Command in Redis: the remaining expiration time of the key is returned in seconds.
SET command in Redis: values are set for the specified keys and their expiration times.
GET command in Redis: for obtaining the value of the designated key.
Spring: is an open source framework and Spring is a lightweight Java development framework that arose in 2003 and was created by Rod Johnson. Briefly, Spring is a layered JavaSE/EEfullstack (one-stop) lightweight open source framework.
AOP: aspect organized Programming, cut-plane Oriented Programming. The AOP is mainly implemented for extracting a tangent plane in a business processing process, and is faced with a certain step or stage in the processing process to obtain an isolation effect of low coupling between parts in a logic process.
And annotating: also called metadata. A description of a code level. It is a feature introduced by JDK1.5 and later versions, at the same level as classes, interfaces, enumerations. It may be declared in front of a packet, class, field, method, local variable, method parameter, etc. to illustrate, annotate, etc. these elements.
DDOS: distributed Denial of Service (Distributed Denial of Service) attacks refer to the fact that a plurality of computers are combined together to serve as an attack platform by means of a client/server technology, and DDoS attacks are launched on one or more targets, so that the power of Denial of Service attacks is doubled.
The process of judging through a database Redis in the prior art is specifically divided into the following two steps:
firstly, after entering an executed service code method, obtaining a value corresponding to a key corresponding to the service in Redis through a GET command in Redis, giving an initial value of 0 if the Redis does not have the corresponding value, then storing the value in the Redis through a SET command, and simultaneously setting the expiration time of the key.
And secondly, judging whether the value corresponding to the service key acquired in the previous step is greater than the SET upper limit of times, if so, not executing the service code and directly returning an error prompt, otherwise, storing the value +1 acquired in the previous step into Redis through an SET command, and continuously executing the service code.
In the application, after a server in the distributed service receives a user request, whether a service code method requested to be executed has annotation configuration information is judged, and if the annotation configuration information does not exist, the service code is directly sent to an execution module to execute the service code.
If the configuration information is annotated, the user request is intercepted before the business code is executed, and the user request enters the anti-frequency processor module logic of the invention to analyze the business code.
Furthermore, annotation configuration information (cache key prefix information, cache key survival time information and anti-frequency information) is obtained, the cache key prefix information is spliced with the unique identification of the currently logged-in user to generate a cache key in the database Redis, an INCR command of the database Redis is executed (the INCR command adds 1 to a value corresponding to the cache key and then returns the value every time the INCR command is executed), and a return value is obtained. Judging whether the return value is 1 (namely judging whether the current return value is greater than or equal to 1), if the return value is 1, proving that the cache key does not exist before the request, and executing an EXPIRE command in Redis at the moment to set the validity period of the cache key as the survival time of the cache key in the annotation configuration information; if the return value is not 1, the cache key is proved to exist before the request and is not expired, whether the return value is larger than the frequency prevention information in the annotation configuration information or not is continuously judged, if the return value is smaller than or equal to the frequency prevention information, the request is released, if the return value is larger than the frequency prevention information, a TTL (transistor-transistor logic) command of a database Redis is executed to obtain the return value, whether the validity period of the cache key is permanent or not is further judged (namely whether the return value is-1 (-1 represents permanent)), and the validity period represents that the program is abnormal and the abnormality is directly thrown out; if the cache key is not permanent, the frequency control program is proved to be normally operated, the survival time of the cache key in the current service code exceeds the preset frequency prevention information, and the throwing frequency is abnormal beyond the limit. Then collecting all abnormal information thrown by the anti-frequency processor module (namely, the thrown exception, the thrown number overrun exception and the system exception) and judging whether the abnormal type is the number overrun exception or not, if the abnormal type is not the number overrun exception (namely, the analyzed cache key information error exception can be obtained, and the network overtime or the system exception can be obtained), proving that the anti-frequency program logic has an unexpected error, executing a DEL command in Redis to delete the cache key, and continuously executing the service code, namely, the service is still ensured to be available under the condition that the anti-frequency component has the error or the exception; if the exception type is the times overrun exception, the service code is not executed and the prompt information of requesting the times overrun by the requester is returned.
According to the method for requesting frequency protection by the service, the technical means of adding the annotation configuration information in the service code and using the annotation configuration information to protect the frequency is adopted, so that the problems of high frequency protection failure, high repeated writing rate, high workload, long time for network use and the like and low safety and reliability in the prior art caused by simultaneous processing of a plurality of services are solved, the technical effects of reducing the frequency protection failure and the workload are further achieved, the program development efficiency is improved, and the workload of programmers is reduced. When the method for requesting frequency protection for the service is used, the annotation configuration information of the frequency protection is preset in the service code, and the prefix information of the cache key, the survival time information of the cache key and the frequency protection frequency number information are specified in the annotation configuration information, so that the method is high in efficiency, easy to maintain and completely not coupled with the service code module.
Fig. 3 is a schematic diagram of main modules of a device for requesting frequency protection for a service according to an embodiment of the present invention, and as shown in fig. 3, the device 300 for code frequency protection for a service according to an embodiment of the present invention mainly includes: an acquisition module 301 and a processing module 302, wherein:
an obtaining module 301, configured to obtain a cache key corresponding to a current service code, and update a value of the cache key to obtain a return value; the processing module 302 is configured to compare the return value with the anti-frequency times, and when it is determined that the return value is greater than the anti-frequency times, the service code is not executed. The technical effect of the invention is achieved by the technical means of presetting the annotation configuration information in the service code and utilizing the annotation configuration information to prevent frequency.
Further, the annotation configuration information further includes a cache key prefix, and the obtaining module is further configured to: and splicing the obtained cache key prefix with the unique identification of the user to obtain the cache key, wherein the unique identification of the user is the unique identification of the user of the current service code.
In an embodiment of the present invention, the apparatus further includes a determining module (not shown in the figure) configured to: judging the size of the return value, and if the return value is equal to 1, directly executing the service code; and if the return value is greater than 1, executing a step of comparing the return value with the frequency prevention number.
In addition, the processing module is further configured to: when the return value is determined to be larger than the frequency prevention times, judging whether the validity period of the cache key is permanent or not; if the data is permanent, throwing an exception; if the number of the throwing times is not permanent, the throwing times is out of limit.
In embodiments of the present invention, when an exception is thrown, the cache key is deleted and the service code is executed.
Specifically, the method is implemented by a profile-oriented programming framework Spring AOP configuration in an embodiment of the present invention.
It can be seen from the above description that, because the technical means of adding annotation configuration information in a service code and using the annotation configuration information to prevent frequency is adopted, the problems of frequency failure prevention, high repeated writing rate, large workload, long network use time and other low safety and reliability caused by simultaneous processing of a plurality of services in the prior art are solved, thereby achieving the technical effects of reducing frequency failure prevention and workload reduction, being beneficial to improving the program development efficiency and reducing the workload of programmers. When the method for requesting frequency protection for the service is used, the annotation configuration information of the frequency protection is preset in the service code, and the prefix information of the cache key, the survival time information of the cache key and the frequency protection frequency number information are specified in the annotation configuration information, so that the method is high in efficiency, easy to maintain and completely not coupled with the service code module.
Fig. 4 shows an exemplary system architecture 400 of a service request frequency protection method or a service code frequency protection device to which an embodiment of the present 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 installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
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 providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 401, 402, 403. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for preventing the frequency of the service request provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the device for preventing the frequency of the service code is generally disposed 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.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments 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 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.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one 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. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic 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, which comprises one or more executable instructions for implementing the specified logical function(s). 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. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which 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. The described modules may also be provided in a processor, which may be described as: a processor includes an acquisition module and a processing module. Wherein the names of the modules do not in some cases constitute a limitation of the module itself.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: obtaining a cache key corresponding to the current service code, and updating the value of the cache key to obtain a return value; and comparing the return value with the anti-frequency times, and not executing the service code when the return value is determined to be greater than the anti-frequency times.
According to the technical scheme of the embodiment of the invention, because the technical means of adding the annotation configuration information in the service code and preventing frequency by using the annotation configuration information is adopted, the problems of frequency failure prevention, high repeated writing rate, large workload, long network use time and the like and low safety and reliability in the prior art caused by simultaneous processing of a plurality of services are solved, the technical effects of reducing frequency failure prevention and workload are further achieved, the improvement of the program development efficiency is facilitated, and the workload of programmers is reduced.
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.

Claims (12)

1. A method for preventing frequency of service request is characterized in that annotation configuration information is preset in service code, the annotation configuration information includes frequency prevention times, the method includes:
receiving a service request, and acquiring annotation configuration information in a service code to be executed by the request to obtain an anti-frequency number;
obtaining a cache key corresponding to the current service code, and updating the value of the cache key to obtain a return value;
comparing the return value with the anti-frequency times, and not executing the service code when the return value is determined to be greater than the anti-frequency times;
wherein, the annotation configuration information further includes a cache key prefix, and the step of obtaining the cache key corresponding to the current service code includes:
and splicing the obtained cache key prefix with the unique identification of the user to obtain the cache key, wherein the unique identification of the user is the unique identification of the user of the current service code.
2. The method of claim 1, further comprising, prior to the step of comparing the return value to the guard frequency number:
judging the size of the return value, and if the return value is equal to 1, directly executing the service code; and if the return value is greater than 1, executing a step of comparing the return value with the frequency prevention number.
3. The method of claim 1, wherein when it is determined that the return value is greater than the anti-frequency count, determining whether the validity period of the cache key is permanent; if the data is permanent, throwing an exception; if the number of the throwing times is not permanent, the throwing times is out of limit.
4. The method of claim 3, wherein when the throw exception occurs, deleting the cache key and executing the service code.
5. The method according to any one of claims 1-4, implemented by a facet-oriented programming framework Spring AOP configuration.
6. A device for preventing frequency of service request is characterized in that annotation configuration information is preset in service code, the annotation configuration information includes frequency prevention times, the device includes:
the acquisition module is used for receiving a service request and acquiring annotation configuration information in a service code to be executed by the request so as to obtain an anti-frequency number; obtaining a cache key corresponding to the current service code, and updating the value of the cache key to obtain a return value; wherein the annotation configuration information further includes a cache key prefix, and the obtaining module is further configured to:
splicing the obtained cache key prefix with a unique identifier of a user to obtain a cache key, wherein the unique identifier of the user is the unique identifier of the user of the current service code;
and the processing module is used for comparing the return value with the anti-frequency times and not executing the service code when the return value is determined to be greater than the anti-frequency times.
7. The apparatus of claim 6, further comprising a determining module configured to:
judging the size of the return value, and if the return value is equal to 1, directly executing the service code; and if the return value is greater than 1, executing a step of comparing the return value with the frequency prevention number.
8. The apparatus of claim 6, wherein the processing module is further configured to: when the return value is determined to be larger than the anti-frequency times, judging whether the validity period of the cache key is permanent or not; if the data is permanent, throwing an exception; if the number of the throwing times is not permanent, the throwing times is out of limit.
9. The apparatus of claim 8, wherein when the throw exception occurs, the cache key is deleted and the transaction code is executed.
10. The device according to any of claims 6-9, implemented by a profile-oriented programming framework Spring AOP configuration.
11. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201711329279.8A 2017-12-13 2017-12-13 Method and device for preventing frequency of service request Active CN109918191B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711329279.8A CN109918191B (en) 2017-12-13 2017-12-13 Method and device for preventing frequency of service request

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711329279.8A CN109918191B (en) 2017-12-13 2017-12-13 Method and device for preventing frequency of service request

Publications (2)

Publication Number Publication Date
CN109918191A CN109918191A (en) 2019-06-21
CN109918191B true CN109918191B (en) 2021-02-26

Family

ID=66958795

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711329279.8A Active CN109918191B (en) 2017-12-13 2017-12-13 Method and device for preventing frequency of service request

Country Status (1)

Country Link
CN (1) CN109918191B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110674168A (en) * 2019-08-29 2020-01-10 北京大米科技有限公司 Cache key abnormity detection method, device, storage medium and terminal
CN110661863B (en) * 2019-09-20 2022-11-25 政采云有限公司 Request processing method and device, electronic equipment and storage medium
CN113254464B (en) * 2021-05-19 2023-12-05 北京沃东天骏信息技术有限公司 Data loading method and device
CN113254465B (en) * 2021-05-25 2022-11-01 四川虹魔方网络科技有限公司 Cache final consistency updating method
CN114844947B (en) * 2022-04-29 2024-03-26 北京达佳互联信息技术有限公司 Request processing method and device, electronic equipment and computer readable medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106453500A (en) * 2016-09-07 2017-02-22 努比亚技术有限公司 Cache generation and control method, cache server and interface server

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106453500A (en) * 2016-09-07 2017-02-22 努比亚技术有限公司 Cache generation and control method, cache server and interface server

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Redis 实现接口访问频率限制,博客园,https://www.cnblogs.com/duhuo/p/5002319.html;都市烟火;《Redis 实现接口访问频率限制》;20151128;正文1-2页,附图1 *
使用Spring注解获取配置文件信息,博客园,https://www.cnblogs.com/Dylansuns/p/7302467.html?utm_medium=referral&utm_source=itdadao;闲情偶寄;《使用Spring注解获取配置文件信息》;20170807;正文1-2页 *

Also Published As

Publication number Publication date
CN109918191A (en) 2019-06-21

Similar Documents

Publication Publication Date Title
CN109918191B (en) Method and device for preventing frequency of service request
CN111865970B (en) Method and apparatus for implementing interface idempotency
CN112000394B (en) Method, apparatus, device and storage medium for accessing applet
CN113517985B (en) File data processing method and device, electronic equipment and computer readable medium
CN110795315A (en) Method and device for monitoring service
CN111782254A (en) Method, device, equipment and storage medium for upgrading object
CN111831461A (en) Method and device for processing business process
CN110909022A (en) Data query method and device
US9507655B2 (en) Tracking asynchronous entry points for an application
US9473565B2 (en) Data transmission for transaction processing in a networked environment
CN110895468A (en) Method and device for realizing service enhancement
US10762180B2 (en) Broker-based messaging through SQL
KR102583532B1 (en) Scheduling method and apparatus, device and storage medium
CN112819638A (en) Transaction weight judging method, device, equipment and computer readable medium
CN112948138A (en) Method and device for processing message
CN114115941A (en) Resource sending method, page rendering method, device, electronic equipment and medium
CN114398372A (en) Data caching method and device
CN109087097B (en) Method and device for updating same identifier of chain code
CN110019671B (en) Method and system for processing real-time message
CN113220981A (en) Method and device for optimizing cache
CN109213815B (en) Method, device, server terminal and readable medium for controlling execution times
CN113347052A (en) Method and device for counting user access data through access log
CN113132447A (en) Reverse proxy method and system
CN112241332A (en) Interface compensation method and device
CN110262756B (en) Method and device for caching data

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
GR01 Patent grant
GR01 Patent grant