CN115695521A - Distributed session method and device - Google Patents

Distributed session method and device Download PDF

Info

Publication number
CN115695521A
CN115695521A CN202211274394.0A CN202211274394A CN115695521A CN 115695521 A CN115695521 A CN 115695521A CN 202211274394 A CN202211274394 A CN 202211274394A CN 115695521 A CN115695521 A CN 115695521A
Authority
CN
China
Prior art keywords
session
attribute
token
hash list
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211274394.0A
Other languages
Chinese (zh)
Inventor
李伟杰
周泊仰
黄星焱
蔡江
张若驰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Unionpay Co Ltd
Original Assignee
China Unionpay Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Unionpay Co Ltd filed Critical China Unionpay Co Ltd
Priority to CN202211274394.0A priority Critical patent/CN115695521A/en
Publication of CN115695521A publication Critical patent/CN115695521A/en
Pending legal-status Critical Current

Links

Images

Abstract

The embodiment of the application provides a distributed session method and a distributed session device, which are applied to the technical field of communication and comprise the following steps: receiving a service request sent by terminal equipment; if the service request carries the token, current session information of the session related to the token is obtained from the service request; obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps aiming at each current session attribute of the current session information: and aiming at a current session attribute, if one current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list. The session is determined by verifying the token in the service request header, so that the uniqueness of the session is ensured; and updating the session attribute (data) through the session hash list corresponding to the session, and ensuring the consistency of the data before and after updating under a high concurrency scene.

Description

Distributed session method and device
Technical Field
The present application relates to the field of communications technologies, and in particular, to a distributed session method and apparatus.
Background
Today's internet applications are mostly deployed in a distributed architecture in order to meet high availability. When a user accesses the server, a session is generated, the session is accompanied with the whole access process of the user, and the session is not ended or fails until the user exits the application or does not operate for a long time.
In a distributed system, sessions are centrally stored in third-party applications, so that the sessions can be shared across multiple nodes, and a common implementation manner of the scheme is Spring-Session. In a high concurrency scene, the persistent Session adopting the Spring-Session mode only stores the latest Session information, so that the data consistency cannot be ensured.
Disclosure of Invention
The embodiment of the application provides a distributed session method and a distributed session device, which are used for solving the problem of data update consistency in a high-concurrency scene.
In a first aspect, an embodiment of the present application provides a distributed session method, including:
receiving a service request sent by terminal equipment;
if the service request carries a token, acquiring current session information of a session associated with the token from the service request;
obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps aiming at each current session attribute of the current session information:
and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
The session is determined by verifying the token in the service request header, so that the uniqueness of the session is ensured; and updating the session attribute (data) through the session hash list corresponding to the session, and ensuring the consistency of the data before and after updating under a high concurrency scene.
Optionally, if the current session attribute matches a historical session attribute in the session hash list, the attribute value of the historical session attribute is updated to the attribute value of the current session attribute.
By replacing the attribute value of the historical session attribute in the session hash list with the attribute value of the current session attribute, the single session attribute can be updated, the fine granularity in the session is updated, and the consistency of the data before and after updating in a high-concurrency scene is also ensured.
Optionally, if the service request does not carry a token, establishing a session corresponding to the service request and generating a token corresponding to the session;
and integrating a plurality of session attributes in the current session information of the session to obtain a session hash list, and storing the token and the session hash list through a key value pair.
A plurality of session attributes in the session are stored by a token and a session hash list in a key value pair mode, and the key value pair only occupies the memory of one key in the storage space, so that the memory of the storage space is saved to a great extent.
Optionally, the token and the session hash list are saved in a Redis database by a key-value pair.
Session information is stored in a Redis database in a key value pair data form, and efficient reading and writing efficiency can be achieved by using a key value pair data model.
Optionally, inputting the token and the current session information into a Lua script;
the session hash list corresponding to the session is obtained based on the token query, and the following steps are respectively executed according to each current session attribute of the current session information: for a current session attribute, if the current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list, including:
through the Lua script, obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps aiming at each current session attribute of the current session information: and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
Optionally, when the session expires, deleting the token and the session hash list of the session based on a Redis expiration key deletion policy.
Optionally, a service response message corresponding to the service request is generated in the validity period of the session, and the service response message is sent to the terminal device.
In a second aspect, an embodiment of the present application provides a distributed session apparatus, including:
the acquisition module is used for receiving a service request sent by the terminal equipment;
the processing module is used for acquiring current session information of a session related to the token from the service request if the token is carried in the service request;
the processing module is further configured to obtain a session hash list corresponding to the session based on the token query, and perform the following steps for each current session attribute of the current session information, respectively:
and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
Optionally, the processing module is further specifically configured to:
and if the current session attribute is matched with the historical session attribute in the session hash list, updating the attribute value of the historical session attribute to the attribute value of the current session attribute.
Optionally, the processing module is further specifically configured to:
if the service request does not carry a token, establishing a session corresponding to the service request and generating a token corresponding to the session;
and integrating a plurality of session attributes in the current session information of the session to obtain a session hash list, and storing the token and the session hash list through a key value pair.
Optionally, the processing module is further specifically configured to:
storing the token and the session hash list in a Redis database by a key-value pair.
Optionally, the processing module is further specifically configured to:
inputting the token and the current session information into a Lua script;
the session hash list corresponding to the session is obtained based on the token query, and the following steps are respectively executed according to each current session attribute of the current session information: for a current session attribute, if the current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list, including:
through the Lua script, obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps for each current session attribute of the current session information: and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
Optionally, the processing module is further specifically configured to:
when the session is expired, deleting the token and the session hash list of the session based on a Redis expiration key deletion policy.
Optionally, the processing module is further specifically configured to:
and generating a service response message corresponding to the service request in the validity period of the session, and sending the service response message to the terminal equipment.
The session is determined by verifying the token in the service request header, so that the uniqueness of the session is ensured; and updating the session attribute (data) through the session hash list corresponding to the session, and ensuring the consistency of the data before and after updating under a high concurrency scene.
In a third aspect, an embodiment of the present application provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the distributed session method described in any of the first aspect.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium storing a computer program executable by a computer device, the program, when executed on the computer device, causing the computer device to perform the distributed session method according to any of the first aspects.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic diagram of a distributed session system architecture according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a distributed session flow according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a key-value pair storage method according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a distributed session device according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a computer device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Today's internet applications are mostly deployed in a distributed architecture in order to meet high availability. In a distributed system, sessions are centrally stored in a third-party application, so that the sessions can be shared across multiple nodes, and a common implementation manner of the scheme is Spring-Session. In a high concurrency scene, a Spring-Session mode is usually adopted for persistent Session, but because the Spring-Session operation granularity is large, only the latest Session information can be stored, and new data can directly cover old data, the Spring-Session does not have a concurrent updating function, so that the consistency of the data before and after updating cannot be ensured.
Referring to fig. 1, which is an architecture diagram of a distributed session system used in an embodiment of the present application, the distributed session system 100 includes a terminal device 101, a server 102, and a storage cluster 103. The terminal device 101 may be a smart phone, a tablet computer, a notebook computer, a desktop computer, a cash dispenser, an order receiving device, and the like, but is not limited thereto. The server 102 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a Network service, cloud communication, a middleware service, a domain name service, a security service, a Content Delivery Network (CDN), a big data and artificial intelligence platform, and the like. The storage cluster 103 is composed of a plurality of cache databases, and the storage cluster 103 may be integrated in the server 102 or exist independently of the server 102.
When a user accesses the server 102 through the terminal device 101, a Session (Session) is generated, and the Session is centrally stored in the storage cluster 103, so that the purpose of sharing the Session across multiple nodes is achieved. This session is accompanied by the user's access throughout, and the session will not end or fail until the user exits the server 102 access or is not operating for a long time.
Based on the above system architecture, fig. 2 exemplarily shows a flow of a distributed session method, where the flow of the method is executed by the server 102, and includes the following steps:
step S201, receiving a service request sent by a terminal device.
Specifically, after the terminal device establishes a session with the server, the user sends a service request to the server through the terminal device, and the server receives the service request.
Step S202, if the service request carries the token, the current session information of the session associated with the token is obtained from the service request.
Specifically, after a service request of a user enters a server, the server extracts a token (token) carried by the service request from a request header of the service request, and extracts all information of a current session associated with the token (token). The token (token) is a long character string encrypted by an MD5 information Digest Algorithm (MD 5Message-Digest Algorithm, abbreviated as MD 5); the token value is used to retrieve the user information corresponding to the current session, so as to determine the login state of the user.
Step S203, obtaining a session hash list corresponding to the session based on the token query, and executing the following steps for each current session attribute of the current session information: and aiming at a current session attribute, if one current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list.
Specifically, one session corresponds to one token, and the token can be a unique mark in the validity period of the session; one session corresponds to one session hash list, and the session hash list stores a plurality of session attributes (data) in the session in a hash structure mode, so that a one-to-one mapping relation can be established between the plurality of session attributes and storage positions. The current session also corresponds to at least one session attribute, and the server queries and obtains a session hash list corresponding to the token based on the extracted token. The server matches each attribute in the current session with each attribute in a session hash list obtained based on the token, and if each attribute in the session hash list is not matched, the server adds the attribute to the session hash list.
Taking one of the session attributes of the current session as an example, the server matches one session attribute a in the current session with each session attribute in the obtained session hash list, and if the same session attribute a is not matched in the session hash list, it indicates that a corresponding service request is not made in the session corresponding to the session hash list, and updates the session attribute a of the current session into the session hash list, that is, adds the session attribute a of the current session into the session hash list.
The session is determined by verifying the token in the service request header, so that the uniqueness of the session is ensured; and updating the session attribute (data) through the session hash list corresponding to the session, and ensuring the consistency before and after data updating under a high concurrency scene.
In step S203, if a current session attribute matches a historical session attribute in the session hash list, the attribute value of the historical session attribute is updated to the attribute value of the current session attribute.
Specifically, the server queries and obtains a session hash list corresponding to the token based on the extracted token. And the server matches each attribute in the current session with each attribute in the session hash list obtained based on the token, and if one attribute in the current session is matched with one historical session attribute in the session hash list, the server updates the attribute value of the historical session attribute to the attribute value of the current session attribute so as to finish updating.
For example, if the user wants to modify the password at the current website, the current session attribute is the password attribute, and there is a password attribute in the session hash list of the website. And the server matches the password attribute in the current session with all the attributes in the session hash list of the website, if the historical password attribute in the session hash list is successfully matched with the password attribute in the current session, the attribute value (old password) of the historical password attribute is updated to the attribute value (new password) of the current session attribute, and the password modification operation is finished.
By replacing the attribute value of the historical session attribute in the session hash list with the attribute value of the current session attribute, the single session attribute can be updated, the fine granularity in the session is updated, and the consistency of the data before and after updating in a high-concurrency scene is also ensured.
In some embodiments, if the service request does not carry a token, establishing a session corresponding to the service request and generating a token corresponding to the session; integrating a plurality of session attributes in the current session information of the session to obtain a session hash list, and storing the token and the session hash list through a key value pair.
Specifically, if the server does not extract the token (token) carried by the service request from the request header of the service request of the user, it indicates that the user enters the server for the first time. The server generates a unique token (token) value according to the user information and judges the login state of the user, after the user successfully logs in the server, the server returns the generated token value to the terminal device, and the terminal device also stores the token value. The algorithm in which the server generates a unique token (token) value may be a snowflake algorithm. The server integrates a plurality of session attributes in the current session information, stores the plurality of session attributes in a hash structure form, and further obtains a session hash list. Storing the obtained session hash list and the token in a key value pair mode; wherein, the key is a token, and the value is a session hash list of a hash structure.
A plurality of session attributes in the session are stored by means of key value pairs of the token and the session hash list, and the key value pairs only occupy the memory of one key in the storage space, so that the memory of the storage space is saved to a great extent.
In some embodiments, storing tokens and session hash lists by a key value pair includes: tokens and session hash lists are saved in the Redis database by a key-value pair.
In particular, redis (Remote Dictionary Server) is a high-performance, persisted log-type, key-value database. Because the data of Redis is stored in the memory, the read-write speed is high, and the method is widely applied to cache scenes. Redis supports relatively more value types to store, including string, list, set, zset, and hash. In the embodiment of the present application, a plurality of session attributes are integrated in a hash structure form to obtain a session hash list, and a key-value key value pair is formed by using a token and the session hash list, as shown in fig. 3, and is stored in a Redis database.
Session information is stored in a Redis database in a key value pair data form, and efficient reading and writing efficiency can be achieved by using a key value pair data model.
In some embodiments, before obtaining the session hash list corresponding to the session based on the token query, the method further includes: inputting the token and the current session information into a Lua script;
obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps aiming at each current session attribute of the current session information: for a current session attribute, if a current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list, including: through a Lua script, a session hash list corresponding to the session is obtained based on token query, and the following steps are respectively executed according to each current session attribute of the current session information: and aiming at a current session attribute, if one current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list.
Specifically, the Lua is a lightweight and compact scripting language, which is written in a standard C language and is open-source, can be easily integrated and extended with other programs, and is designed to be embedded in an application program to provide flexible extension and customization functions for the application program. And inputting the token and the current session information into the Lua script, namely, a unique mark (token) of the current session, the attribute of the current session and the value of the attribute of the current session are transmitted into the Lua script. And the server queries and obtains a session hash list corresponding to the token based on the extracted token. And the server matches each attribute in the current session with each attribute in a session hash list obtained based on the token, and if each attribute in the session hash list is not matched, the attribute and the attribute value are added into the session hash list.
The Lua script can send a plurality of attributes of the current session in a script form at one time, so that the time delay of session information transmission in a network is reduced; and the Lua script is executed as a whole, other requests cannot be inserted in the middle, and the stability of session information transmission is ensured.
In some embodiments, when a session expires, the session's token and session hash list are deleted based on the Redis expiration key deletion policy.
Specifically, in Redis, an Expire command is used to set the time of a key, where one key is a token, different session expiration times are set for different sessions according to the token, and the session expiration times are defined according to the requirements of a user. And when the key reaches the expiration time, deleting the key and the session hash list corresponding to the key by a Redis expiration key deletion strategy.
By setting an expiration time for the token in the session and deleting the invalid session by the Redis expiration key deletion strategy, the purpose of saving the Redis memory can be achieved.
In some embodiments, a service response message corresponding to the service request is generated in the validity period of the session, and the service response message is sent to the terminal device.
Specifically, after generating a service response message corresponding to the service request within the validity period of the session, the server returns the service response message to the terminal device.
Based on the same technical concept, an embodiment of the present application provides a schematic structural diagram of a distributed session apparatus, as shown in fig. 4, the apparatus 400 includes:
an obtaining module 401, configured to receive a service request sent by a terminal device;
a processing module 402, configured to, if the service request carries a token, obtain current session information of a session associated with the token from the service request;
the processing module 402 is further configured to obtain a session hash list corresponding to the session based on the token query, and perform the following steps for each current session attribute of the current session information:
and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
Optionally, the processing module 402 is further specifically configured to:
and if the current session attribute is matched with the historical session attribute in the session hash list, updating the attribute value of the historical session attribute to the attribute value of the current session attribute.
Optionally, the processing module 402 is further specifically configured to:
if the service request does not carry a token, establishing a session corresponding to the service request and generating a token corresponding to the session;
and integrating a plurality of session attributes in the current session information of the session to obtain a session hash list, and storing the token and the session hash list through a key value pair.
Optionally, the processing module 402 is further specifically configured to:
storing the token and the session hash list in a Redis database by a key-value pair.
Optionally, the processing module 402 is further specifically configured to:
inputting the token and the current session information into a Lua script;
the session hash list corresponding to the session is obtained based on the token query, and the following steps are respectively executed according to each current session attribute of the current session information: for a current session attribute, if the current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list, including:
through the Lua script, obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps aiming at each current session attribute of the current session information: and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
Optionally, the processing module 402 is further specifically configured to:
when the session is expired, deleting the token and the session hash list of the session based on a Redis expiration key deletion policy.
Optionally, the processing module 402 is further specifically configured to:
and generating a service response message corresponding to the service request in the validity period of the session, and sending the service response message to the terminal equipment.
The session is determined by verifying the token in the service request header, so that the uniqueness of the session is ensured; and updating the session attribute (data) through the session hash list corresponding to the session, and ensuring the consistency of the data before and after updating under a high concurrency scene.
Based on the same technical concept, the embodiment of the present application provides a computer device, which may be a terminal device or a server shown in fig. 1, as shown in fig. 5, and includes at least one processor 501 and a memory 502 connected to the at least one processor, where a specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application, and the processor 501 and the memory 502 are connected through a bus in fig. 5 as an example. The bus may be divided into an address bus, a data bus, a control bus, etc.
In the embodiment of the present application, the memory 502 stores instructions executable by the at least one processor 501, and the at least one processor 501 may execute the steps of the distributed session method by executing the instructions stored in the memory 502.
The processor 501 is a control center of the computer device, and can connect various parts of the computer device by using various interfaces and lines, and implement or execute the instructions stored in the memory 502 and call the data stored in the memory 502, thereby achieving the purpose of maintaining data consistency before and after updating. Optionally, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly handles an operating system, a user interface, an application program, and the like, and the modem processor mainly handles wireless communication. It will be appreciated that the modem processor described above may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 may be implemented on the same chip, or in some embodiments, they may be implemented separately on separate chips.
The processor 501 may be a general-purpose processor, such as a Central Processing Unit (CPU), a digital signal processor, an Application Specific Integrated Circuit (ASIC), a field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof, and may implement or perform the methods, steps, and logic blocks disclosed in the embodiments of the present Application. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in a processor.
The memory 502, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 502 may include at least one type of storage medium, and may include, for example, a flash Memory, a hard disk, a multimedia card, a card-type Memory, a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Programmable Read Only Memory (PROM), a Read Only Memory (ROM), a charge Erasable Programmable Read Only Memory (EEPROM), a magnetic Memory, a magnetic disk, an optical disk, and so on. The memory 502 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer device, but is not limited to such. The memory 502 in the embodiments of the present application may also be circuitry or any other device capable of performing a storage function for storing program instructions and/or data.
Based on the same inventive concept, embodiments of the present application provide a computer-readable storage medium storing a computer program executable by a computer device, which, when the program is run on the computer device, causes the computer device to perform the steps of the above-described distributed session method.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A distributed session method, comprising:
receiving a service request sent by terminal equipment;
if the service request carries a token, acquiring current session information of a session associated with the token from the service request;
obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps aiming at each current session attribute of the current session information:
and aiming at a current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
2. The method of claim 1, further comprising:
and if the current session attribute is matched with the historical session attribute in the session hash list, updating the attribute value of the historical session attribute to the attribute value of the current session attribute.
3. The method of claim 1, further comprising:
if the service request does not carry a token, establishing a session corresponding to the service request and generating a token corresponding to the session;
and integrating a plurality of session attributes in the current session information of the session to obtain a session hash list, and storing the token and the session hash list through a key value pair.
4. The method of claim 3, wherein said storing said token and said session hash list by a key-value pair comprises:
storing the token and the session hash list in a Redis database by a key-value pair.
5. The method of claim 1, wherein prior to obtaining the session hash list corresponding to the session based on the token query, further comprising:
inputting the token and the current session information into a Lua script;
the session hash list corresponding to the session is obtained based on the token query, and the following steps are respectively executed according to each current session attribute of the current session information: for a current session attribute, if the current session attribute does not exist in the session hash list, adding an attribute value of the current session attribute to the session hash list, including:
through the Lua script, obtaining a session hash list corresponding to the session based on the token query, and respectively executing the following steps for each current session attribute of the current session information: and aiming at a current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
6. The method of claim 1, further comprising:
when the session is expired, deleting the token and the session hash list of the session based on a Redis expiration key deletion policy.
7. The method of any of claims 1 to 6, further comprising:
and generating a service response message corresponding to the service request in the validity period of the session, and sending the service response message to the terminal equipment.
8. An apparatus for distributed sessions, comprising:
the acquisition module is used for receiving a service request sent by the terminal equipment;
the processing module is used for acquiring the current session information of the session related to the token from the service request if the service request carries the token;
the processing module is further configured to obtain a session hash list corresponding to the session based on the token query, and perform the following steps for each current session attribute of the current session information, respectively:
and aiming at one current session attribute, if the current session attribute does not exist in the session hash list, adding the attribute value of the current session attribute to the session hash list.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method of any one of claims 1 to 7 when executing the program.
10. A computer-readable storage medium, in which a computer program is stored which is executable by a computer device, and which, when run on the computer device, causes the computer device to carry out the steps of the method according to any one of claims 1 to 7.
CN202211274394.0A 2022-10-18 2022-10-18 Distributed session method and device Pending CN115695521A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211274394.0A CN115695521A (en) 2022-10-18 2022-10-18 Distributed session method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211274394.0A CN115695521A (en) 2022-10-18 2022-10-18 Distributed session method and device

Publications (1)

Publication Number Publication Date
CN115695521A true CN115695521A (en) 2023-02-03

Family

ID=85067106

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211274394.0A Pending CN115695521A (en) 2022-10-18 2022-10-18 Distributed session method and device

Country Status (1)

Country Link
CN (1) CN115695521A (en)

Similar Documents

Publication Publication Date Title
CN111506592B (en) Database upgrading method and device
CN110889142A (en) Data authority management method, device, system and equipment
CN113886743B (en) Method, device and system for refreshing cache resources
EP4310691A1 (en) Blockchain-based data processing method, apparatus, and device, and storage medium
CN112559529B (en) Data storage method, device, computer equipment and storage medium
US8352442B2 (en) Determination of an updated data source from disparate data sources
US20170155712A1 (en) Method and device for updating cache data
CN109302449B (en) Data writing method, data reading device and server
CN111767053A (en) Front-end page data acquisition method and device
CN115695521A (en) Distributed session method and device
CN113361236A (en) Method and device for editing document
CN115391188A (en) Scene test case generation method, device, equipment and storage medium
CN115858972A (en) Page display method and device of application program, storage medium and computer equipment
CN115794819A (en) Data writing method and electronic equipment
CN112052234B (en) Service data processing method and device, storage medium and electronic device
CN113918857A (en) Three-level cache acceleration method for improving performance of distributed WEB application system
CN109857719B (en) Distributed file processing method, device, computer equipment and storage medium
CN113364875B (en) Method, apparatus and computer readable storage medium for accessing data at block link points
CN113792031B (en) Key value data processing method, system, equipment and medium
CN117390078B (en) Data processing method, device, storage medium and computer equipment
CN117057799B (en) Asset data processing method, device, equipment and storage medium
CN114817285A (en) Data updating method, device, storage medium and device
CN117573388A (en) Cache updating method and related device
CN116455980A (en) Service reverse proxy method and system based on dynamic routing
CN117743721A (en) Data processing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination