Interface call counting method and device
By using Redis's Zset structure for counting, the performance and accuracy issues of relational databases and Redis List structures under massive requests are solved, achieving simple, fast, and accurate counting processing.
Patent Information
- Application Number
- CN201810072556.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-01-25
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2038-01-25
AI Technical Summary
Under massive requests, relational database operations and queries are time-consuming, affecting the performance and response time of the counting service. Operations on the List structure in Redis are complex and not very accurate.
It uses Redis's Zset structure for counting, determines the key through an interface call command, determines the order through the current time, determines the value through a random number, inserts into the sorted set, sets the expiration time, deletes expired members, and integrates Redis commands into a single request packet for processing.
It achieves a simple counting process, low time consumption, accurate results, and easy maintenance, reducing network round-trip latency, improving performance, and reducing network request failure rate.
Smart Images

Figure CN110083501B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an interface call counting method and device. Background Art
[0002] In the current Internet era, e-commerce and Internet finance are developing rapidly, and various transactions have also moved from offline to online. However, the Internet is an open, transparent and unsafe environment, and there are endless cases of criminals grabbing resources, such as snapping up discounted products and merchants swiping orders. Therefore, in order to protect the fair rights and interests of legitimate users and maintain the stability and security of the system, a reliable risk control system is needed to ensure the security of transactions and access.
[0003] In the risk control system architecture, there is an important component called the counter server. It plays the role of traffic calculation and control. By counting traffic and requests, requests that exceed the configured threshold are controlled and restricted. Unlike the counting and statistics of data such as the number of users, access PV (Page View) and access UV (Unique Visitor) in the monitoring system, the counter server in the risk control system has high requirements for counting performance and real-time performance. For example, promotions on e-commerce platforms are all promotions at the hour. If the performance and real-time performance are not high, when criminals swipe orders to buy discounted products at the promotion time, the restriction processing will lag behind and fail to achieve the purpose of preventing swiping.
[0004] Currently, we can count user login-related requests through relational databases or based on the List structure in Redis to prevent illegal users from frequent registration and violent login.
[0005] However, in the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0006] Under massive requests, relational database operations and queries take a long time, which seriously affects the performance and response time of the counting service. Even if sharding is used for optimization, it is difficult to reduce the processing time to less than 100 milliseconds when the number of requests is large.
[0007] Although using the List structure in Redis for counting can reduce a certain amount of time consumption, different Lists need to be created for different time intervals, which increases the operation steps and processing time; it is prone to errors and has low accuracy. Summary of the invention
[0008] In view of this, an embodiment of the present invention provides an interface call counting method and device, which has a simple counting process, saves time, produces accurate results, is easy to maintain, and can count based on a specific time interval.
[0009] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, there is provided an interface call counting method, comprising: receiving an interface call instruction, inserting a new member into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order; receiving a counting instruction, wherein the counting instruction includes a start and end time of the counting; determining the number of members in the ordered set within the start and end time according to the counting instruction, and using the number of members as the number of times the interface has been called.
[0010] Optionally, the members in the ordered set have three attributes: key, order and value; the three attributes are determined according to the following process: determining the key according to the interface call instruction; determining the order according to the current time; determining the value according to the current time and a random number.
[0011] Optionally, determining the key according to the interface calling instruction comprises: determining an interface name and a user identifier according to the interface calling instruction; determining the key according to the interface name and the user identifier;
[0012] Determining the order according to the current time includes: obtaining a current timestamp and using the current timestamp as the order;
[0013] Determining the value according to the current time and the random number includes: determining the value according to the current timestamp and the random number.
[0014] Optionally, the method further includes: setting an expiration time of the ordered set; and deleting expired members in the ordered set in response to a deletion instruction.
[0015] Optionally, the ordered set is a Zset structure of Redis, and inserting new members into the ordered set, determining the number of members in the ordered set within the start and end time, setting the expiration time of the ordered set, and deleting expired members in the ordered set are respectively implemented through Redis commands.
[0016] Optionally, the method also includes integrating a Redis command for inserting a new member into the ordered set, a Redis command for determining the number of members in the ordered set within the start and end time, a Redis command for setting the expiration time of the ordered set, and a Redis command for deleting expired members in the ordered set into a request package, and sending it to the Redis server for processing.
[0017] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, there is provided an interface call counting device, comprising: a member adding module, used to receive an interface call instruction, and insert a new member into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order; a receiving module, used to receive a counting instruction, wherein the counting instruction includes a start and end time of the counting; and a counting module, used to determine the number of members in the ordered set within the start and end time according to the counting instruction, and use the number of members as the number of times the interface has been called.
[0018] Optionally, the members in the ordered set have three attributes: key, order and value; the member addition module determines the three attributes according to the following process: determining the key according to the interface call instruction; determining the order according to the current time; determining the value according to the current time and a random number.
[0019] Optionally, the member addition module determines the three attributes according to the following process: determine the interface name and user ID according to the interface call instruction; determine the key according to the interface name and user ID; obtain the current timestamp and use the current timestamp as the order; determine the value according to the current timestamp and a random number.
[0020] Optionally, the device further comprises a setting module and a deleting module, wherein the setting module is used to set an expiration time of the ordered set; and the deleting module is used to delete expired members in the ordered set in response to a deletion instruction.
[0021] Optionally, the ordered set is a Zset structure of Redis, and the member adding module, counting module, setting module and deleting module are respectively implemented through Redis commands.
[0022] Optionally, the device also includes an integration module, which is used to integrate the Redis command for implementing the member addition module, the Redis command for implementing the counting module, the Redis command for implementing the setting module and the Redis command for implementing the deletion module into a request packet, and send it to the Redis server for processing.
[0023] To achieve the above-mentioned purpose, according to another aspect of an embodiment of the present invention, there is provided an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the interface call counting method of an embodiment of the present invention.
[0024] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the interface call counting method of the embodiment of the present invention is implemented.
[0025] An embodiment of the above invention has the following advantages or beneficial effects: because an interface call instruction is received to insert a new member into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order; a counting instruction is received, wherein the counting instruction includes the start and end time of the counting; the number of members in the ordered set within the start and end time is determined according to the counting instruction, and the number of members is used as the number of times the interface is called, thereby overcoming the technical problems of inaccurate counting, complex operation and long time consumption in the prior art, thereby achieving the technical effect of simple counting processing, less time consumption, accurate results, and easy maintenance.
[0026] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0028] Figure 1 is a schematic diagram of the main process of the interface call counting method according to an embodiment of the present invention;
[0029] Figure 2 is a schematic diagram of the main process of an interface call counting method according to another embodiment of the present invention;
[0030] Figure 3 is a schematic diagram of main modules of an interface call counting device according to an embodiment of the present invention;
[0031] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0032] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0034] Figure 1 FIG. 1 is a schematic diagram of the main process of the interface call counting method according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0035] Step S101: receiving an interface call instruction, inserting a new member into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order;
[0036] Step S102: receiving a counting instruction, wherein the counting instruction includes a start and end time of counting;
[0037] Step S103: determining the number of members in the ordered set within the start and end time according to the counting instruction, and using the number of members as the number of times the interface is called.
[0038] The interface call counting method of the embodiment of the present invention can be applied to systems with counting requirements such as registration systems, login systems, verification code systems or risk control systems. For example, taking the verification code system as an example, the method can count the interface for requesting a verification code image, the interface for refreshing a verification code, or the interface for checking whether the verification code is correct.
[0039] For step S101, in the ordered set, each member has three attributes, namely: key, order and value.
[0040] As a specific example, the ordered set can be a Zset structure of Redis. Among them, Redis is a Key-Value storage system that can store mappings between keys and 5 different types of values. The types of values it supports for storage include String, List, Set, Zset (sorted set), and Hash. Zset does not allow duplicate members, and each member is associated with a score, which is used to sort the members in the set from small to large. In this embodiment, the order of the above three attributes is the score.
[0041] In this embodiment, the key can be determined according to the interface calling instruction, the order can be determined according to the current time, and the value can be determined according to the current time and a random number.
[0042] Specifically, the interface call instruction may include the name and user identifier of the called interface, and the key may be determined based on the interface name and user identifier, for example, by concatenating the interface name and user identifier to obtain the key. The user identifier is used to distinguish the identity characteristics of the user. For example, the user identifier may be information such as the user's IP address, user name, device ID, or device fingerprint (device fingerprint refers to a device feature or unique device identifier that can be used to uniquely identify the device). In an optional embodiment, one of the above information, such as an IP address, may be used as a user identifier, or a combination of multiple information, such as an IP address, user name, and device ID, may be used as a user identifier. Using a combination of multiple information as a user identifier may increase the difficulty for some users to seize resources and reduce risks. As a specific example, the key is 10.8.12.232@REFRESH, which represents a refresh verification code interface call request by a user with an IP address of 10.8.12.232.
[0043] The order can be determined by the current timestamp. A timestamp refers to the total number of seconds from 00:00:00 Greenwich Mean Time (08:00:00 Beijing Time) on January 1, 1970 to the present.
[0044] The value can be determined by the current timestamp and the random number, for example, by concatenating the current timestamp and the random number to obtain the value. Because the members of Zset cannot be repeated, and the value is determined by concatenating the current timestamp and the random number, the possibility of repetition is almost zero. As a specific example, the current timestamp timestamp is 1509104637, and the random number rand=8675367, then the value is 15091046378675367.
[0045] Each time a user calls an interface, they will receive an interface call instruction. For example, each time a user refreshes a verification code, they will receive a call instruction for the verification code refresh interface. When an interface call instruction is received, a new member is inserted into the ordered set. For example, a new member can be inserted through the Redis command "zadd key timestamp value".
[0046] For step S103, the number of members in the ordered set within the start and end time is determined according to the start and end time in the counting instruction, and the number is the number of times the interface is called within the start and end time. For example, the number of calls to the interface in the last minute is obtained through the Redis command "zcount key timestamp-60 timestamp".
[0047] In the embodiment of the present invention, only one ordered set may be created to determine the number of interface calls within different time intervals.
[0048] The interface call counting method of the embodiment of the present invention adopts the method of creating an ordered set, wherein the members in the ordered set are unique and arranged in chronological order; receiving an interface call instruction, inserting a new member into the ordered set; receiving a counting instruction, wherein the counting instruction includes a start and end time of the counting; determining the number of members in the ordered set within the start and end time according to the counting instruction, and using the number of members as a technical means for the number of times the interface is called, thereby overcoming the technical problems of inaccurate counting, complex operation and long time consumption in the prior art, and thereby achieving the technical effect of simple counting processing, less time consumption, accurate results, and easy maintenance.
[0049] In an optional embodiment, the method further comprises:
[0050] Set the expiration time of the ordered set;
[0051] In response to the deletion instruction, the expired members in the ordered set are deleted.
[0052] The embodiment of the present invention can reset the expiration time of the ordered set each time a new member is inserted into the ordered set. The purpose of this operation is to prevent the members in the ordered set from occupying and wasting memory resources when the user no longer calls the interface within a day. Because the expiration time of the ordered set is reset each time a new member is inserted into the ordered set, if the user continues to call the interface, the ordered set will always exist.
[0053] Continuing with the Zset structure as an example, the expiration time of the ordered set can be set to one day through the Redis command "expire key 86400", where 86400 refers to the number of seconds in a day.
[0054] In addition, the embodiment of the present invention can also delete expired members in the ordered set based on a delete instruction. For example, the command "zremrangebyscore key 0 timestamp-86399" is used to delete members in Zset that are older than 1 day. This command can be regarded as "zremrangebyscore key 0 timestamp-86400-1", and the effect of subtracting 1 is not to delete the record that is exactly 1 day ago.
[0055] In an optional embodiment, the method further includes integrating a Redis command for inserting a new member into the ordered set, a Redis command for determining the number of members in the ordered set within the start and end time, a Redis command for setting the expiration time of the ordered set, and a Redis command for deleting expired members in the ordered set into a request packet, and sending it to the Redis server for processing. For example, using the pipeline processing method of Redis, all the above Redis commands are integrated into a network request packet, and sent to the Redis server for processing. Pipeline refers to a transmission method in Redis, which combines multiple Redis commands into the same network request packet.
[0056] The embodiment of the present invention integrates the above-mentioned multiple Redis commands into a request packet and sends it to the Redis server for processing. This method greatly reduces the network round-trip delay, especially in cross-computer room processing, avoiding the high transmission delay between computer rooms affecting the overall time consumption of counting processing, improving performance while also reducing the network request failure rate.
[0057] Please refer to Figure 2 , taking Zset as an ordered set and IP address as a user identifier as an example to illustrate the interface call counting method of an embodiment of the present invention.
[0058] Step S201: extract the IP address and interface name interface_name from the counting request data, and determine the key of the Zset member, for example, the key is 10.8.12.232@REFRESH, which indicates a refresh verification code interface call request from the user with the IP address 10.8.12.232.
[0059] Step S202: Calculate the timestamp of the current system as the score of the Zset member, and the score is the order of the member.
[0060] Step S203: Generate a random number rand, concatenate timestamp and rand to get the value of Zset, for example, the current timestamp is 1509104637, the random number rand = 8675367, then value = 15091046378675367. Because the value of Zset cannot be repeated, and value is generated by concatenating timestamp and random number, the possibility of repetition is almost zero.
[0061] Step S204: insert a new member through the Redis command "zadd key timestamp value".
[0062] Step S205: Set the expiration time of the Zset to one day through the Redis command "expire key 86400". Because, in this embodiment, the maximum time interval of counting is 1 day, the purpose of this operation is to prevent the data in the Zset from occupying and wasting memory resources when the IP will not request the interface in the future. Moreover, because the expiration time will be reset every time the counting process is processed, if the user of the IP continues to request, the Zset will always exist.
[0063] Step S206: Determine whether to delete the expired member, if yes, execute step S207, if not, return to execute step S201.
[0064] Step S207: Use the Redis command "zremrangebyscore key 0 timestamp-86399" to delete members older than one day to avoid occupying memory resources.
[0065] The embodiment of the present invention only needs to create a Zset to achieve counting of different time intervals, which is simpler and more efficient than the existing counting method that requires creating different Lists for different time intervals. For example, for a login request from a user with an IP address of 10.8.12.232, it is necessary to insert members into the Lists of the following three time intervals through the rpush command:
[0066] 10.8.12.232@LOGIN_MINUTE_LIMIT;
[0067] 10.8.12.232@LOGIN_HOUR_LIMIT;
[0068] 10.8.123.232@LOGIN_DAY_LIMIT;
[0069] The embodiment of the present invention only needs to insert a new member through Zset, and only needs to change the parameters in the zcount command when determining the number of interface calls in different time intervals. For example, the command to determine the number of interface calls in the last minute is "zremrangebyscore key 0 timestamp-86399", and the command to determine the number of interface calls in the last hour is "zremrangebyscore key 3600 timestamp-86399".
[0070] The embodiment of the present invention can integrate multiple Redis commands into one request packet, and when inserting members into List, it is necessary to first obtain the number of members in the List. If the number is 0, then it is necessary to first create the List and set the expiration time. If the number is greater than 0, then the new member is directly inserted. For List, the two operations of obtaining the number of members and inserting new members cannot be sent to the Redis server as a Redis pipeline request. Therefore, the embodiment of the present invention can reduce the network round-trip delay and the number of network transmissions, and thus reduce the request failure rate, especially in cross-computer room processing, avoiding the high transmission delay between computer rooms affecting the overall time consumption of counting processing, improving performance while also reducing the network request failure rate.
[0071] The interface call counting method of the embodiment of the present invention is more accurate. In this method, the expiration time of Zset is one day, which avoids the situation where the member count times in the current List cannot be accumulated to the next List in the same time interval after the current List expires and is deleted.
[0072] In addition, by using the timestamp as the score of the Zset member, the zcount command can be used to easily calculate the number of interface calls within a specified time interval. For example, to obtain the number of interface calls within the last minute, you can use the command "zcount key timestamp-60 timestamp".
[0073] The method of the embodiment of the present invention can realize the counting in different time intervals only through a Redis Zset structure, and only one Redis pipeline request is needed to complete the counting process, which reduces the network RTT time (Round-Trip Time, network round trip delay) and also reduces the network request failure rate. It can be seen that the counting process of the method of the embodiment of the present invention is simpler and the result is more accurate.
[0074] Figure 3 FIG. 1 is a schematic diagram of the main modules of the interface call counting device according to an embodiment of the present invention. Figure 3 As shown, the device 300 includes:
[0075] A member adding module 301 is used to receive an interface call instruction and insert a new member into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order;
[0076] A receiving module 302 is used to receive a counting instruction, where the counting instruction includes a start and end time of the counting;
[0077] The counting module 303 is used to determine the number of members in the ordered set within the start and end time according to the counting instruction, and use the number of members as the number of times the interface is called.
[0078] Optionally, the members in the ordered set include three attributes: key, order and value members; the member adding module 301 determines the three attributes according to the following process: determining the key according to the interface calling instruction; determining the order according to the current time; determining the value according to the current time and a random number.
[0079] Optionally, the member adding module 301 determines the three attributes according to the following process: according to the interface calling instruction, determine the interface name and user ID; according to the interface name and user ID, determine the key; obtain the current timestamp and use the current timestamp as the order; the member determines the value based on the current timestamp and the random number.
[0080] Optionally, the device further comprises a setting module and a deleting module, wherein the setting module is used to set an expiration time of the ordered set; and the deleting module is used to delete expired members in the ordered set in response to a deletion instruction.
[0081] Optionally, the ordered set is a Zset structure of Redis, and the member adding module 301, the counting module 303, the setting module and the deleting module are respectively implemented by Redis commands.
[0082] Optionally, the device also includes an integration module, which is used to integrate the Redis command for implementing the member addition module, the Redis command for implementing the counting module, the Redis command for implementing the setting module and the Redis command for implementing the deletion module into a request packet, and send it to the Redis server for processing.
[0083] The interface call counting device of the embodiment of the present invention adopts the method of receiving interface call instructions, inserting new members into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order; receiving counting instructions, wherein the counting instructions include the start and end time of counting; determining the number of members in the ordered set within the start and end time according to the counting instructions, and using the number of members as the number of times the interface is called, thereby overcoming the technical problems of inaccurate counting, complex operation and long time consumption in the prior art, and achieving the technical effect of simple counting processing process, less time consumption, accurate results and easy maintenance.
[0084] The above device can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.
[0085] Figure 4 An exemplary system architecture 400 to which the interface call counting method or interface call counting device according to the embodiment of the present invention can be applied is shown.
[0086] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0087] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0088] The terminal devices 401 , 402 , and 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, and desktop computers.
[0089] Server 405 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using terminal devices 401, 402, and 403. The backend management server may analyze and process received data such as product information query requests, and feed back processing results (such as target push information and product information) to the terminal device.
[0090] It should be noted that the interface call counting method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the interface call counting device is generally disposed in the server 405 .
[0091] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0092] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0093] like Figure 5As shown, the computer system 500 includes a central processing unit (CPU) 501, which 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 part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0094] 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, etc. 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 installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0095] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0096] 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 may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0097] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0098] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor. For example, they may be described as: a processor includes a sending module, an acquisition module, a determination module, and a first processing module. The names of these modules do not, in some cases, constitute a limitation on the unit itself. For example, the sending module may also be described as a "module for sending a picture acquisition request to the connected server."
[0099] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device can execute the interface call counting method of the embodiment of the present invention.
[0100] The method comprises: receiving an interface call instruction, inserting a new member into the ordered set, wherein the members in the ordered set are unique and arranged in chronological order; receiving a counting instruction, wherein the counting instruction comprises a start and end time of the counting; determining the number of members in the ordered set within the start and end time according to the counting instruction, and using the number of members as the number of times the interface has been called.
[0101] The technical solution of the embodiment of the present invention inserts a new member into the ordered set by receiving an interface call instruction, wherein the members in the ordered set are unique and arranged in chronological order; receives a counting instruction, wherein the counting instruction includes a start and end time of the counting; determines the number of members in the ordered set within the start and end time according to the counting instruction, and uses the number of members as a technical means of the number of times the interface is called, thereby overcoming the technical problems of inaccurate counting, complex operation and long time consumption in the prior art, and thereby achieving the technical effect of simple counting processing, less time consumption, accurate results, and easy maintenance.
[0102] The above specific implementations 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 modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An interface call counting method, characterized in that: include: receiving an interface call instruction, inserting a new member into an ordered set, wherein the members in the ordered set are unique and arranged in chronological order, and the attributes of the member include a key generated by an interface name and a user identifier determined by the interface call instruction, and a user identifier generated by selecting a combination of multiple user information; In response to each insertion of a new member into the ordered set, resetting the expiration time of the ordered set; receiving a counting instruction, wherein the counting instruction includes a start and end time of counting; The number of members in the ordered set within the start and end time is determined according to the counting instruction, and the number of members is used as the number of times the interface is called.
2. The method according to claim 1, wherein the members in the ordered set have three attributes: key, order and value; The three attributes are determined according to the following process: Determining the key according to the interface calling instruction; Determining the order according to the current time; The value is determined according to the current time and the random number.
3. The method according to claim 2, characterized in that Determining the key according to the interface calling instruction includes: determining an interface name and a user identifier according to the interface calling instruction; determining the key according to the interface name and the user identifier; Determining the order according to the current time includes: obtaining a current timestamp and using the current timestamp as the order; Determining the value according to the current time and the random number includes: determining the value according to a current timestamp and a random number.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Set the expiration time of the ordered set; In response to the deletion instruction, the expired members in the ordered set are deleted.
5. The method according to claim 4, characterized in that The ordered set is a Zset structure of Redis. Inserting a new member into the ordered set, determining the number of members in the ordered set within the start and end time, setting the expiration time of the ordered set, and deleting expired members in the ordered set are respectively implemented through Redis commands.
6. The method according to claim 5, characterized in that The method also includes integrating a Redis command for inserting a new member into the ordered set, a Redis command for determining the number of members in the ordered set within the start and end time, a Redis command for setting the expiration time of the ordered set, and a Redis command for deleting expired members in the ordered set into a request packet, and sending the request to a Redis server for processing.
7. An interface call counting device, characterized in that: include: A member adding module is used to receive an interface call instruction and insert a new member into an ordered set, wherein the members in the ordered set are unique and arranged in chronological order, and the attributes of the member include a key generated by an interface name and a user identifier determined by the interface call instruction, and a user identifier generated by selecting a combination of multiple user information; in response to each insertion of a new member into the ordered set, the expiration time of the ordered set is reset; A receiving module, used for receiving a counting instruction, wherein the counting instruction includes a start and end time of the counting; A counting module is used to determine the number of members in the ordered set within the start and end time according to the counting instruction, and use the number of members as the number of times the interface is called.
8. The apparatus according to claim 7, wherein the members in the ordered set have three attributes: key, order and value; The member adding module determines the three attributes according to the following process: Determining the key according to the interface calling instruction; Determining the order according to the current time; The value is determined according to the current time and the random number.
9. The device according to claim 8, characterized in that The member adding module determines the three attributes according to the following process: Determine the interface name and the user identifier according to the interface call instruction; determine the key according to the interface name and the user identifier; Obtaining a current timestamp, and using the current timestamp as the order; The value is determined based on the current timestamp and a random number.
10. The device according to any one of claims 7 to 9, characterized in that: The device also includes a setting module and a deletion module. The setting module is used to set the expiration time of the ordered set; The deletion module is used to delete expired members in the ordered set in response to a deletion instruction.
11. The device according to claim 10, characterized in that The ordered set is a Zset structure of Redis. The member adding module, counting module, setting module and deleting module are respectively implemented through Redis commands.
12. The device according to claim 11, characterized in that The device also includes an integration module, which is used to integrate the Redis command of the member addition module, the Redis command of the counting module, the Redis command of the setting module and the Redis command of the deletion module into a request packet and send it to the Redis server for processing.
13. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
14. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
High-concurrency REDIS database operation method and system
CN107463612A