A caching method based on OpenResty
Through the collaboration between OpenResty server and Redis memory database server, the slow-changing characteristics of username and password are used to achieve high availability in high concurrency and failure situations, solving the problem of declining user access experience in the existing technology, and improving the server service capabilities and user experience.
Patent Information
- Application Number
- CN202110019652.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-07
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2041-01-07
AI Technical Summary
Under large concurrent volume and massive data flow requests, the user access experience is declining, and existing caching technologies are difficult to maintain high availability and stability in the event of server failure.
Using OpenResty-based caching method, through the collaboration between the OpenResty server, Redis memory database server and backend source server, the slow-changing characteristics of username and password are used to realize data caching and verification, ensuring that it can still be done during peak periods and failure situations. Normal response.
Improves server service capabilities in high concurrency and failure situations, ensures user experience, and makes full use of caching technology to reduce the load on the database.
Smart Images

Figure CN112699152B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a caching method based on OpenResty. Background Art
[0002] In the face of the problem of high concurrency and massive data flow requests leading to a decline in user access experience, the server often uses caching technology to solve it. The memory caching mechanism is adopted to reduce the number of database accesses by giving priority to reading cached data in the memory, thereby reducing the database load. Performance test results and user experience feedback information show that this method can greatly improve the system throughput when accessed with high concurrency. At present, the general caching strategy is as follows: after the request arrives, first query whether there is the required data in the cache. If there is, directly return the data in the cache. If there is no required data, send it to the backend server to query the database, and return the request result returned by the backend server to the requester, and put the request result in the cache. In the account authentication service, account data such as passwords often change slowly, and most of them will not change for a long time. Therefore, in the actual authentication service, this feature can be fully utilized and combined with the caching technology to obtain high concurrency while ensuring higher service stability. Summary of the invention
[0003] The present invention proposes a caching method based on OpenResty, comprising the following steps:
[0004] It is implemented specifically through the following steps: first, build the client side and the service side. The service side includes the OpenResty server, the source server and the Redis memory database server. The client side includes the application or browser, which communicates with the OpenResty server through HTTP / HTTPS to receive the client's request. The OpenResty server receives the client's request and extracts the key fields in the request. According to the working status of the source server and the status of the related data in the memory database server, it determines to return the data cached in the Redis memory database server to the client; the OpenResty server either sends the request to the backend source server, and then sends the request result to the client, and processes the data according to the rules and sends it to the Redis memory database server.
[0005] Further, the method specifically includes the following steps:
[0006] S1: The OpenResty server receives the client's request and extracts the key fields in the request. Specifically, it processes the request URL, extracts the username and password information, and uses the processed username, username and password as keys to extract data from the Redis memory database server. The username and password data are hashed.
[0007] S2: Determine whether there is processed data with the user name and password as the key in the Redis memory database server;
[0008] S3: If the requested data exists in the Redis memory database server, the request result is sent directly to the client;
[0009] S4: If the requested data does not exist in the Redis memory database server, the request is sent to the backend source server to verify the original user name and password. The judgment of whether the verification is successful or not is specified in the configuration file through a regular expression to ensure the flexibility of the judgment.
[0010] S5: If the verification is successful, the processed user name data is used as the Key, the password and current time, and the request result data are saved as the Value in the Redis memory database server; if the verification fails, it is determined whether the Redis memory database server is wrong; the judgment of authentication failure and server internal errors are specified by setting regular expressions in the configuration file. The processing delay of the source server is also used as a criterion for determining server failures. If the delay is relatively large and exceeds a limit value, in the subsequent time, if the user name exists as the Key data, the cached password is used as the basis for determining whether the verification is successful or not.
[0011] S6: If not, save the processed user name data as Key, password and current time, and request result data as Value to the Redis memory database server; if it is an internal server error, determine again whether the processed user name is the Value of the Key in the Redis memory database server;
[0012] S7: If it exists, determine whether the password is consistent with the cached password; if it does not exist, close the current request;
[0013] S8: If it is determined that the password is consistent with the cached password, the request result is sent to the client;
[0014] S9: End.
[0015] Furthermore, the processing delay of the source server can also be used as a criterion for determining server failure. For example, if the delay is relatively large and exceeds a limit value, then in the following period of time, if the user name exists as the data of the Key, the cached password is used as the basis for determining whether the verification is successful or not, and the processing of step S6 is performed without requesting the source server. In steps S3 and S6, the slow-changing characteristics of information such as user names and passwords are fully utilized. Even if the server fails, the response to most normal requests can still be guaranteed, which can greatly improve the service capabilities of the server during peak traffic periods and unexpected failures, and improve the user experience.
[0016] Further, in step S2, the expiration time of the data is set to be permanent; the expiration time of the data is set through a configuration file; specifically, an ini file or a json file is used. The following is an example of an ini file. login is the interface name, yes corresponds to the regular expression for successful verification, no corresponds to the regular expression for failed verification, fail corresponds to the regular expression for internal server failure, and expired corresponds to the validity period when the user name and password are used as keys.
[0017] The advantages and positive effects of the present invention are: the method of the present invention caches data according to the return data and configuration files of the back-end server, and changes the use of cached data according to the response status of the back-end server. It can make full use of the cache to increase concurrency. It makes full use of the slow-changing characteristics of information such as user names and passwords, and can still guarantee the response of most normal requests even if the server fails, which can greatly improve the service capabilities of the server during peak traffic periods and unexpected failure situations, and improve user experience; this method is used in all cache systems where the data requested by the interface has the characteristic of slow changes. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is a flow chart of the data processing method of the present invention;
[0019] Figure 2 It is a system structure flow chart of the present invention. DETAILED DESCRIPTION
[0020] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments: A caching method based on OpenResty of the present invention first constructs a client side and a service side, wherein the service side includes an OpenResty server, a source server and a Redis memory database server, and the client side includes an application or a browser, which communicates with the OpenResty server through HTTP / HTTPS to receive a request from the client, and the OpenResty server receives the request from the client to extract key fields in the request, and determines to return the data cached in the Redis memory database server to the client based on the working status of the source server and the status of related data in the memory database server; the OpenResty server either sends the request to the backend source server, and then sends the request result to the client, and processes the data according to the rules, and sends it to the Redis memory database server.
[0021] In this embodiment, the following steps are specifically included:
[0022] S1: The OpenResty server receives the client's request and extracts the key fields in the request. Specifically, it processes the request URL, extracts the username and password information, and uses the processed username, username and password as keys to extract data from the Redis memory database server. The username and password data are hashed.
[0023] S2: Determine whether there is processed data with the user name and password as the key in the Redis memory database server;
[0024] S3: If the requested data exists in the Redis memory database server, the request result is sent directly to the client;
[0025] S4: If the requested data does not exist in the Redis memory database server, the request is sent to the backend source server to verify the original user name and password. The judgment of whether the verification is successful or not is specified in the configuration file through a regular expression to ensure the flexibility of the judgment.
[0026] S5: If the verification is successful, the processed user name data is used as the Key, the password and current time, and the request result data are saved as the Value in the Redis memory database server; if the verification fails, it is determined whether the Redis memory database server is wrong; the judgment of authentication failure and server internal errors are specified by setting regular expressions in the configuration file. The processing delay of the source server is also used as a criterion for determining server failures. If the delay is relatively large and exceeds a limit value, in the subsequent time, if the user name exists as the Key data, the cached password is used as the basis for determining whether the verification is successful or not.
[0027] S6: If not, save the processed user name data as Key, password and current time, and request result data as Value to the Redis memory database server; if it is an internal server error, determine again whether the processed user name is the Value of the Key in the Redis memory database server;
[0028] S7: If it exists, determine whether the password is consistent with the cached password; if it does not exist, close the current request;
[0029] S8: If it is determined that the password is consistent with the cached password, the request result is sent to the client;
[0030] S9: End.
[0031] In this embodiment, the processing delay of the source server can also be used as a criterion for determining server failure. For example, if the delay is relatively large and exceeds a limit value, then in the subsequent period of time, if the user name exists as the data of the Key, the cached password is used as the basis for determining whether the verification is successful or not, and the processing of step S6 is performed without requesting the source server. In steps S3 and S6, the slow-changing characteristics of information such as user names and passwords are fully utilized. Even if the server fails, the response to most normal requests can still be guaranteed, which can greatly improve the service capabilities of the server during peak traffic periods and unexpected failures, and improve user experience.
[0032] In this embodiment, in step S2, the expiration time of the data is set to be permanent; the expiration time of the data is set through a configuration file; specifically, an ini file or a json file is used. The following is an example of an ini file. login is the interface name, yes corresponds to the regular expression for determining successful verification, no corresponds to the regular expression for determining failed verification, fail corresponds to the regular expression for determining internal server failure, and expired corresponds to the validity period when the user name and password are used as keys.
[0033] The above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the purpose and scope of the technical solutions of the present invention, which should be included in the scope of the claims of the present invention. The techniques, shapes, and structural parts not described in detail in the present invention are all well-known technologies.
Claims
1. A caching method based on OpenResty, characterized in that: This is achieved through the following steps: First, the client side and the service side are built. The service side includes the OpenResty server, the source server, and the Redis memory database server. The client side includes an application or a browser, which communicates with the OpenResty server through HTTP / HTTPS to receive the client's request. The OpenResty server receives the client's request and extracts the key fields in the request. According to the working status of the source server and the status of the related data in the memory database server, it determines to return the data cached in the Redis memory database server to the client. The OpenResty server either sends the request to the backend source server, and then sends the request result to the client, and processes the data according to the rules and sends it to the Redis memory database server. The specific steps include: S1: The OpenResty server receives the client's request and extracts the key fields in the request. Specifically, it processes the request URL, extracts the username and password information, and uses the processed username, username and password as keys to extract data from the Redis memory database server. S2: Determine whether there is processed data with the user name and password as the key in the Redis memory database server; S3: If the requested data exists in the Redis memory database server, the request result is sent directly to the client; S4: If the requested data does not exist in the Redis memory database server, the request is sent to the backend source server to verify the original username and password; S5: If the verification is successful, the processed user name data is used as the key, the password and the current time, and the request result data are saved as the value in the Redis memory database server; if the verification is wrong, it is determined whether the Redis memory database server is wrong; S6: If not, save the processed user name data as Key, password and current time, and request result data as Value to the Redis memory database server; if it is an internal server error, determine again whether the processed user name is the Value of the Key in the Redis memory database server; S7: If it exists, determine whether the password is consistent with the cached password; if it does not exist, close the current request; S8: If it is determined that the password is consistent with the cached password, the request result is sent to the client; S9: End; In step S1, the user name and password data are hashed; In step S4, the request is sent to the backend source server to verify the original user name and password. The judgment of whether the verification is successful or not is specified in the configuration file through a regular expression to ensure the flexibility of the judgment; In step S5, the determination of authentication failure and server internal error is specified by setting a regular expression in the configuration file; In step S5, the processing delay of the source server is also used as a criterion for determining server failure. If the delay exceeds a limit value, in the subsequent period of time, if the user name exists as the Key data, the cached password is used as the basis for determining whether the verification is successful or not.
Citation Information
Patent Citations
Identity authentication system and method based on single sign-on
CN103188248A
Reading device, system and method for server address
CN106790601A
Login method, device and system based on distributed server
CN108769083A
An e-commerce platform implementing system and method based on micro-service technology
CN109284089A
Method for processing network request by proxy server side and proxy server
CN110661826A
