Gateway product session remote storage method and device, gateway equipment and storage medium
By building and encapsulating request payload form information, obtaining and storing gateway product session data, the problem of fixed session log sending frequency and version limitation is solved, and flexible session off-site storage and efficient data acquisition are achieved.
Patent Information
- Application Number
- CN202411461680.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-01-10
AI Technical Summary
The sending frequency of session logs in existing gateway products is fixed and cannot be flexibly provisioned. Session records are only applicable to the latest version, resulting in low efficiency and applicability of sessions off-site storage.
By building request payload form information, including session request frequency and number of sessions corresponding to each session request, it is encapsulated and sent to the requests module, obtain gateway product session data, and store it in the database, realizing flexible session data acquisition and storage .
It realizes flexible storage of session data for any version of the gateway product, improves the efficiency and applicability of session off-site storage, does not rely on session logging, and is not restricted by version.
Smart Images

Figure CN119299473A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of session data storage, and in particular to a method and device for storing gateway product session remotely, a gateway device and a storage medium. Background Art
[0002] The storage of gateway sessions is of great significance to the performance of gateway products.
[0003] In existing gateway products, sessions are stored off-site by recording session logs, but the frequency of sending session logs is fixed and cannot be flexibly adjusted. In addition, session log recording can only be implemented in the latest version. Old versions of gateway products cannot implement session log recording, resulting in the inability to store gateway sessions off-site.
[0004] Therefore, there is an urgent need to provide a gateway product session off-site storage method, apparatus, gateway device and storage medium to achieve flexible storage of gateway product session data of any version of gateway products. Summary of the invention
[0005] In view of this, it is necessary to provide a method, apparatus, gateway device and storage medium for off-site storage of gateway product sessions, so as to solve the technical problems in the prior art that the frequency of sending session logs is fixed and the session records are only applicable to the latest version of the gateway product, resulting in low efficiency and applicability of off-site storage of gateway product sessions.
[0006] On the one hand, in order to solve the above technical problems, the present invention provides a method for storing a gateway product session remotely, comprising: Constructing request payload form information; the request payload form information includes the session request frequency and the number of sessions corresponding to each session request; Encapsulating the request payload form information to obtain encapsulation information; Send the package information to the requests module to obtain gateway product session data; The gateway product session data is stored in a database.
[0007] In a possible implementation, the constructing request payload form information includes: Determine the number of pages and the number of data items on each page based on demand, and use the number of data items on each page as the number of sessions; The request interval between adjacent pages is determined based on the demand, and the request interval is used as the session request frequency.
[0008] In a possible implementation, before constructing the request payload form information, the process further includes: Obtain the request authentication information of the data request interface, and encrypt and encapsulate the request authentication information to obtain a token authentication string; Then, encapsulating the request payload form information to obtain encapsulation information includes: The request payload form information is passed into the token authentication string to obtain the encapsulation information.
[0009] In a possible implementation, the number of pages includes a first page and a second page, and the gateway product session data includes first session data corresponding to the first page and second session data corresponding to the second page; Then the encapsulation information is sent to the requests module to obtain the gateway product session data, including: Automatically generating a data request based on the encapsulation information, and generating a loop counter based on the number of pages; the count in the loop counter is the same as the total number of pages; acquiring the first session data based on the data request, and storing the first session data in an intermediate transition database; Decrement the count in the loop counter by one, and determine whether the count is zero; When the count is not zero, the second session data is acquired based on the data request, and the second session data is stored in an intermediate transition database.
[0010] In a possible implementation, storing the gateway product session data in the database includes: When the count is zero, transferring the gateway product session data in the intermediate transition database to the database; Among them, the transition database is a Redis database, and the database is a MySQL database.
[0011] In a possible implementation manner, before storing the first session data in the intermediate transition database, the method further includes: The first session data is cleaned.
[0012] In a possible implementation, the data structure of the gateway product session data is in JSON format.
[0013] On the other hand, the present invention also provides a gateway product session off-site storage device, comprising: A form information construction unit, used to construct request load form information; the request load form information includes a session request frequency and a number of sessions corresponding to each session request; An information encapsulation unit, used to encapsulate the request payload form information to obtain encapsulation information; A session data acquisition unit, used to send the encapsulation information to the requests module to acquire gateway product session data; The session data storage unit is used to store the gateway product session data in a database.
[0014] On the other hand, the present invention also provides a gateway device, including a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the method for storing gateway product sessions off-site as described in any one of the possible implementations above.
[0015] On the other hand, the present invention also provides a computer-readable storage medium for storing computer-readable programs or instructions, which, when executed by a processor, can implement the steps of the gateway product session off-site storage method described in any of the above possible implementation methods.
[0016] The beneficial effect of the present invention is that the off-site storage method for gateway product sessions provided by the present invention constructs request payload form information including the session request frequency and the number of sessions corresponding to each session request, and can flexibly obtain gateway product session data by modifying the session request frequency and the number of sessions in the request payload form information. For example, the session request frequency and the number of sessions can be flexibly set according to the performance of the local server and the gateway.
[0017] Furthermore, the present invention does not need to obtain gateway product session data based on session log records, that is, the gateway product does not need to support session log records and is not restricted by the version of the gateway product, thereby improving the applicability of the gateway product session off-site storage method. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 A schematic diagram of a flow chart of an embodiment of a method for storing a gateway product session remotely provided by the present invention; Figure 2 For the present invention Figure 1 A schematic flow chart of an embodiment of S101; Figure 3 For the present invention Figure 1A schematic flow chart of an embodiment of S103; Figure 4 A flowchart of a specific embodiment of the method for storing a gateway product session remotely provided by the present invention; Figure 5 A schematic diagram of the structure of an embodiment of a gateway product session off-site storage device provided by the present invention; Figure 6 A schematic diagram of the structure of a gateway device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0021] It should be understood that the schematic drawings are not drawn to scale. The flowchart used in the present invention shows the operations implemented according to some embodiments of the present invention. It should be understood that the operations of the flowchart can be implemented out of order, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art, under the guidance of the content of the present invention, can add one or more other operations to the flowchart, and can also remove one or more operations from the flowchart. Some of the block diagrams shown in the accompanying drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor systems and / or microcontroller systems.
[0022] Reference to an "embodiment" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiment may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0023] The present invention provides a method, an apparatus, a gateway device and a storage medium for storing a gateway product session remotely, which are described below respectively.
[0024] Figure 1 A flow chart of an embodiment of the method for storing a gateway product session remotely provided by the present invention is shown as follows: Figure 1 As shown, the off-site storage method of the gateway product session includes: S101, constructing request payload form information; the request payload form information includes the session request frequency and the number of sessions corresponding to each session request; S102, encapsulating the request payload form information to obtain encapsulation information; S103, sending the encapsulation information to the requests module to obtain gateway product session data; S104: Store the gateway product session data in a database.
[0025] The requests module is open source under the Apache 2.0 license. The requests module is a Python module for sending HTTP requests. It provides a simple and easy-to-use API, supports sending various types of requests such as GET, POST, PUT, DELETE, and handles complex sessions, authentication, cookies, and redirection functions, making it easy to interact with web services and exchange data.
[0026] Since the gateway product session data is obtained from the interface of the gateway session monitoring data, when executing step S103, the interface of the gateway session monitoring data needs to be synchronously specified, that is, the data source of the gateway product session data interface needs to be indicated.
[0027] Compared with the prior art, the off-site storage method for gateway product sessions provided by the embodiment of the present invention constructs request payload form information including the session request frequency and the number of sessions corresponding to each session request, and can flexibly obtain gateway product session data by modifying the session request frequency and the number of sessions in the request payload form information. For example, the session request frequency and the number of sessions can be flexibly set according to the performance of the local server and the gateway.
[0028] Furthermore, the embodiments of the present invention do not need to obtain gateway product session data based on session log records, that is, the gateway product does not need to support session log records and is not restricted by the version of the gateway product, thereby improving the applicability of the gateway product session off-site storage method.
[0029] In some embodiments of the present invention, Figure 2 As shown, step S101 includes: S201, determine the number of pages and the number of data items on each page based on demand, and use the number of data items on each page as the number of sessions; S202: Determine the request interval between adjacent pages based on demand, and use the request interval as the session request frequency.
[0030] The embodiment of the present invention splits the gateway product session data to be obtained from two dimensions: the number of pages and the number of sessions per page, and takes each page as a data request cycle. Each data request cycle will obtain the same number of session data as the number of data items, thereby achieving orderly acquisition of a large amount of session data.
[0031] In a specific embodiment of the present invention, the default number of pages is 1, and the default number of data items is 20, that is, if no additional settings are made, there is one page of data, and the number of data items on each page is 20. The default request interval is zero, that is, if no additional settings are made, after obtaining the session data of one page, the session data of the next page is obtained immediately.
[0032] To ensure data security when transmitting sensitive data between the client and the server, the monitoring data interface of the gateway session has a token authentication string. To ensure successful acquisition of session data, in some embodiments of the present invention, before step S101, the following is further included: Get the request authentication information of the data request interface, encrypt and encapsulate the request authentication information, and obtain the token authentication string.
[0033] That is: according to the gateway token encapsulation logic, construct the same token authentication string as the gateway session monitoring interface to implement interface authentication, so that the session data can be obtained normally.
[0034] The authentication request information includes the login cookie information.
[0035] The embodiment of the present invention can realize the safe and successful transmission of data between the data request interface and the data monitoring interface by encrypting and encapsulating the request authentication information.
[0036] It should be noted that the encryption algorithm of the encryption package adopts the RSA asymmetric encryption algorithm. Specifically, the jsencrypt module in javascript is used to encrypt and package the request authentication information.
[0037] Among them, jsencrypt is a library for RSA encryption and decryption in JavaScript. It supports public key encryption and private key decryption and is often used to ensure data security when transmitting sensitive data between the client and the server.
[0038] From the above description, it can be seen that the embodiment of the present invention is a method implemented based on Python and JavaScript languages. Due to the cross-platform properties of Python and JavaScript, it can be easily ported to other operating systems or platforms and is easy to deploy, further improving the applicability of the gateway product session off-site storage method.
[0039] Since Python and JavaScript have different environments, in order to realize the common use of the two languages, in some embodiments of the present invention, pyexecjs is used to implement Python calling the JavaScript runtime environment. Pyexecjs is a library for executing JavaScript code in Python. It can call various JavaScript runtime environments (such as Node.js, JScript, etc.), allowing JavaScript code to be embedded and executed in Python programs, thereby realizing cross-language programming and data processing.
[0040] Since the request payload form information includes the information that the server informs the gateway of, the step S102 is specifically as follows: Pass the request payload form information into the token authentication string to obtain the encapsulation information.
[0041] By passing the request payload form information into the token authentication string, the requests module can inform the gateway of the gateway product session data that needs to be obtained, thereby improving the success rate of obtaining the gateway product session data.
[0042] In a specific embodiment of the present invention, the number of pages includes a first page and a second page, and the gateway product session data includes first session data corresponding to the first page and second session data corresponding to the second page; If Figure 3 As shown, step S103 includes: S301, automatically generating a data request based on the encapsulation information, and generating a loop counter based on the number of pages; the count in the loop counter is the same as the total number of pages; S302: Acquire first session data based on the data request, and store the first session data in an intermediate transition database; S303, reducing the count in the loop counter by one, and determining whether the count is zero; S304: When the count is not zero, obtain the second session data based on the data request, and store the second session data in the intermediate transition database.
[0043] The embodiment of the present invention controls the acquisition of gateway product session data through a loop counter. Each time the loop counter cycles once, it represents a session request, and one page of gateway product session data will be acquired until all pages of session data are acquired.
[0044] In a specific embodiment of the present invention, the intermediate transition database is a Redis database, which is an open source in-memory key-value database that supports multiple data structures, such as strings, hashes, lists, sets, and ordered sets. It has high performance, persistence, publish-subscribe, Lua scripting, and other functions, and is often used in scenarios such as caching, session storage, and real-time analysis.
[0045] When the amount of session data of the gateway product is huge, the number of sessions on each page is also large. To achieve rapid acquisition of session data in this scenario, in some embodiments of the present invention, the first session data is stored in the intermediate transition database as follows: Threading is used to perform multi-threaded request operations on the first session data, and the first session data is stored in an intermediate transition database to implement concurrent operations of requests, so that more data can be obtained more quickly.
[0046] threading is a module in the Python standard library that is used to create and manage threads to implement concurrent execution of tasks. It provides functions such as thread creation, startup, synchronization, and locking mechanisms, and is suitable for applications that require concurrent processing.
[0047] The embodiment of the present invention realizes rapid and massive acquisition of session data by setting threading to process the first session data, thereby improving the acquisition and storage efficiency of the session data.
[0048] Similarly, the process of storing the second session data in the intermediate transition database is the same as the process of storing the first session data in the intermediate transition database, which will not be described in detail here.
[0049] After the session data of all pages are obtained, the session data needs to be stored permanently. Therefore, step S104 is specifically as follows: When the count is zero, the gateway product session data in the intermediate transition database is transferred to the database.
[0050] In a specific embodiment of the present invention, the database is a MySQL database, which is known for its high performance, high reliability and ease of use, and is widely used in various applications, such as websites, data warehouses and online transaction processing systems. MySQL supports multi-user and multi-threading, has a rich storage engine and a flexible plug-in mechanism, and is suitable for processing large-scale data and high concurrent requests.
[0051] Furthermore, since the first session data and the second session data directly obtained from the session monitoring data interface contain a lot of junk information, such as empty data, duplicate data, and invalid data, in order to improve the readability of the session data stored in the intermediate transition database, in some embodiments of the present invention, before storing the first session data in the intermediate transition database, the method further includes: Clean the first session data.
[0052] Among them, cleaning specifically includes removing empty data, duplicate data and invalid data.
[0053] Similarly, before storing the second session data in the intermediate transition database, the process further includes: Clean the second session data.
[0054] The embodiment of the present invention cleans the first session data and the second session data before storing them in the intermediate transition database, thereby enhancing the readability of the session data in the intermediate transition database.
[0055] In a specific embodiment of the present invention, the data structure of the gateway product session data is in json format.
[0056] Among them, JSON is a lightweight data exchange format used to represent structured data in an easy-to-read text format.
[0057] In some specific embodiments of the present invention, Figure 4 As shown, the process of the off-site storage method of the gateway product session is as follows: encrypt and encapsulate the request authentication information of the data request interface, obtain the token authentication string, and pass the request payload form information to the token authentication string to obtain the encapsulation information, determine the number of request loops according to the number of pages in the request payload form information, enter the request loop, and obtain the session data, clean the obtained session data, and temporarily store the cleaned data in the Redis database, and at the same time reduce the number of loops by one to determine whether the number of loops is zero. If so, transfer the session data in the Redis database to the MySQL database. If not, continue to enter the request loop to obtain the session data until the number of loops is zero.
[0058] In order to better implement the off-site storage method for gateway product sessions in the embodiment of the present invention, based on the off-site storage method for gateway product sessions, the embodiment of the present invention also provides an off-site storage device for gateway product sessions, such as Figure 5 As shown, the gateway product session off-site storage device 500 includes: The form information construction unit 501 is used to construct the request load form information; the request load form information includes the session request frequency and the number of sessions corresponding to each session request; The information encapsulation unit 502 is used to encapsulate the request payload form information to obtain encapsulation information; The session data acquisition unit 503 is used to send the encapsulation information to the requests module to obtain the gateway product session data; The session data storage unit 504 is used to store the gateway product session data into a database.
[0059] The gateway product session off-site storage device 500 provided in the above embodiment can implement the technical solution described in the above gateway product session off-site storage method embodiment. The specific implementation principles of the above modules or units can refer to the corresponding contents in the above gateway product session off-site storage method embodiment, which will not be repeated here.
[0060] like Figure 6 As shown, the present invention also provides a gateway device 600. The gateway device 600 includes a processor 601, a memory 602 and a display 603. Figure 6 Only some components of the gateway device 600 are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0061] In some embodiments, the processor 601 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run program codes or process data stored in the memory 602, such as the off-site storage method for gateway product sessions in the present invention.
[0062] In some embodiments of the present invention, the processor 601 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 601 may be local or remote. In some embodiments, the processor 601 may be implemented in a cloud platform. In one embodiment, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, a multi-cloud, etc., or any combination thereof.
[0063] In some embodiments, the memory 602 may be an internal storage unit of the gateway device 600, such as a hard disk or memory of the gateway device 600. In other embodiments, the memory 602 may also be an external storage device of the gateway device 600, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the gateway device 600.
[0064] Furthermore, the memory 602 may include both an internal storage unit of the gateway device 600 and an external storage device. The memory 602 is used to store application software installed in the gateway device 600 and various data.
[0065] In some embodiments, the display 603 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 603 is used to display information of the gateway device 600 and to display a visual user interface. The components 601-603 of the gateway device 600 communicate with each other through a system bus.
[0066] In some embodiments of the present invention, when the processor 601 executes the gateway product session off-site storage program in the memory 602, the following steps may be implemented: Constructing request payload form information; the request payload form information includes the session request frequency and the number of sessions corresponding to each session request; Encapsulate the request payload form information to obtain encapsulation information; Send the encapsulated information to the requests module to obtain the gateway product session data; Store gateway product session data into the database.
[0067] It should be understood that: when the processor 601 executes the gateway product session remote storage program in the memory 602, in addition to the above functions, other functions can also be implemented. For details, please refer to the description of the corresponding method embodiment above.
[0068] Furthermore, the embodiment of the present invention does not specifically limit the type of the gateway device 600 mentioned, and the gateway device 600 may be a portable gateway device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a wearable device, a laptop computer, etc. Exemplary embodiments of portable gateway devices include but are not limited to portable gateway devices equipped with IOS, Android, Microsoft or other operating systems. The above-mentioned portable gateway device may also be other portable gateway devices. It should also be understood that in some other embodiments of the present invention, the gateway device 600 may not be a portable gateway device, but a desktop computer with a touch-sensitive surface (such as a touch panel).
[0069] Correspondingly, an embodiment of the present invention also provides a computer-readable storage medium, which is used to store computer-readable programs or instructions. When the program or instructions are executed by a processor, it can implement the steps or functions of the gateway product session off-site storage method provided in the above-mentioned method embodiments.
[0070] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0071] The above is a detailed introduction to a gateway product session off-site storage method, device, gateway device and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for storing a gateway product session remotely, characterized in that: include: Construct request payload form information; The request payload form information includes the session request frequency and the number of sessions corresponding to each session request; Encapsulating the request payload form information to obtain encapsulation information; Send the package information to the requests module to obtain gateway product session data; The gateway product session data is stored in a database.
2. The method for storing gateway product sessions remotely according to claim 1, characterized in that: The construction request payload form information includes: Determine the number of pages and the number of data items on each page based on demand, and use the number of data items on each page as the number of sessions; The request interval between adjacent pages is determined based on the demand, and the request interval is used as the session request frequency.
3. The method for storing gateway product sessions remotely according to claim 1, characterized in that: Before constructing the request payload form information, it also includes: Obtain the request authentication information of the data request interface, and encrypt and encapsulate the request authentication information to obtain a token authentication string; Then, encapsulating the request payload form information to obtain encapsulation information includes: The request payload form information is passed into the token authentication string to obtain the encapsulation information.
4. The method for storing gateway product sessions remotely according to claim 2, characterized in that: The number of pages includes a first page and a second page, and the gateway product session data includes first session data corresponding to the first page and second session data corresponding to the second page; Then the encapsulation information is sent to the requests module to obtain the gateway product session data, including: Automatically generating a data request based on the encapsulation information, and generating a loop counter based on the number of pages; the count in the loop counter is the same as the total number of pages; acquiring the first session data based on the data request, and storing the first session data in an intermediate transition database; Decrement the count in the loop counter by one, and determine whether the count is zero; When the count is not zero, the second session data is acquired based on the data request, and the second session data is stored in an intermediate transition database.
5. The method for storing a gateway product session remotely according to claim 4, characterized in that: The storing the gateway product session data into the database comprises: When the count is zero, transferring the gateway product session data in the intermediate transition database to the database; Among them, the transition database is a Redis database, and the database is a MySQL database.
6. The method for storing gateway product sessions remotely according to claim 4, characterized in that: Before storing the first session data in the intermediate transition database, the method further includes: The first session data is cleaned.
7. The method for storing gateway product sessions remotely according to any one of claims 1 to 6, characterized in that: The data structure of the gateway product session data is in json format.
8. A gateway product session off-site storage device, characterized in that: include: A form information building unit, used to build request payload form information; The request payload form information includes the session request frequency and the number of sessions corresponding to each session request; An information encapsulation unit, used to encapsulate the request payload form information to obtain encapsulation information; A session data acquisition unit, used to send the encapsulation information to the requests module to acquire gateway product session data; The session data storage unit is used to store the gateway product session data in a database.
9. A gateway device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the method for storing gateway product sessions off-site as described in any one of claims 1 to 7 above.
10. A computer-readable storage medium, characterized in that: Used to store computer-readable programs or instructions, which, when executed by a processor, can implement the steps in the method for storing gateway product sessions off-site as described in any one of claims 1 to 7 above.