Tenant data processing method, proxy component, electronic device and storage medium
By deploying a proxy component in front of the Redis server, each tenant has only one connection between the proxy component and the Redis server, solving the problems of low resource utilization and performance degradation caused by the increase in the number of tenants, and improving the resource utilization and performance of the Redis server.
Patent Information
- Application Number
- CN202310351369.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2043-03-28
AI Technical Summary
As the number of tenants increases, the number of connections to the Redis server increases, leading to low resource utilization and performance degradation.
By deploying a proxy component in front of the Redis server, each tenant has only one connection between the proxy component and the Redis server. The proxy component is responsible for forwarding and authenticating request information, ensuring that multiple clients of the same tenant reuse the same connection.
It improves the resource utilization of the Redis server, reduces the number of connections, reduces the difficulty of operation and maintenance, and avoids resource waste and performance degradation.
Smart Images

Figure CN116320017B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a tenant data processing method, an agent component, an electronic device, and a storage medium. Background Art
[0002] Currently, as the number of tenants increases, the number of connections to the Redis server also increases. Clients under each tenant need to establish connections to the Redis server. A large number of connections will occupy too many Redis server resources, resulting in a decrease in Redis server performance. Summary of the Invention
[0003] In order to solve the above problems, embodiments of the present invention provide a tenant data processing method, a proxy component, an electronic device, and a storage medium, so as to at least solve the problem of low resource utilization of Redis tenants in the related art.
[0004] The technical solution of the present invention is achieved as follows:
[0005] In one aspect, an embodiment of the present invention provides a tenant data processing method, which is applied to a proxy component of a Redis server. The method includes:
[0006] Get the client's request information;
[0007] Determine the tenant corresponding to the client based on the request information; each tenant of the Redis server corresponds to multiple clients;
[0008] Determine whether there is a connection corresponding to the tenant between the proxy component and the Redis server; each tenant corresponds to only one connection between the proxy component and the Redis server;
[0009] If there is a connection corresponding to the tenant between the proxy component and the Redis server, the request information is forwarded to the Redis server based on the connection.
[0010] In the above solution, determining whether there is a connection corresponding to the tenant between the proxy component and the Redis server includes:
[0011] querying a setting database based on the identification information of the tenant to determine whether the setting database stores a socket corresponding to the identification information of the tenant; wherein different connections between the proxy component and the Redis server correspond to different sockets;
[0012] If the setting database stores a socket corresponding to the identification information of the tenant, it is determined that a connection corresponding to the tenant exists between the proxy component and the Redis server.
[0013] In the above solution, forwarding the request information to the Redis server based on the connection includes:
[0014] determining a status of the connection;
[0015] If the connection is in an unused state, the request information is forwarded to the Redis server based on the connection, and the connection is marked as in used state.
[0016] In the above solution, if the request information represents an authentication request, after obtaining the request information from the client, the method further includes:
[0017] Obtain the username and password in the request information;
[0018] Forwarding the username and password to the Redis server for authentication; wherein each tenant includes a unique username and password;
[0019] Obtain the authentication result sent by the Redis server; if the authentication is successful, the authentication result includes identification information of the tenant corresponding to the client.
[0020] On the other hand, an embodiment of the present invention provides a tenant data processing method, which is applied to the above-mentioned Redis server, and the method includes:
[0021] Obtaining client request information forwarded by the proxy component of the Redis server;
[0022] Processing the request information to obtain response information;
[0023] The response information is sent to the proxy component based on the connection between the proxy component and the Redis server corresponding to the tenant of the client, so that the proxy component forwards the response information to the client.
[0024] In the above solution, the method further includes:
[0025] Obtain the username and password sent by the proxy component;
[0026] Authenticating the username and password; wherein each tenant includes a unique username and password pair;
[0027] If the authentication is successful, the client is marked as the tenant corresponding to the username and password;
[0028] The authentication result is sent to the proxy module.
[0029] In the above solution, processing the request information includes:
[0030] The request information is processed in the database of the tenant corresponding to the client; wherein each tenant of the Redis server corresponds to a unique database
[0031] On the other hand, an embodiment of the present invention provides an agent component, which includes:
[0032] The first acquisition module is used to obtain the request information of the client;
[0033] A first determining module is configured to determine a tenant corresponding to the client based on the request information; each tenant of the Redis server corresponds to multiple clients;
[0034] A second determination module is configured to determine whether there is a connection corresponding to the tenant between the proxy component and the Redis server; each tenant corresponds to only one connection between the proxy component and the Redis server;
[0035] A forwarding module is used to forward the request information to the Redis server based on the connection if there is a connection corresponding to the tenant between the proxy component and the Redis server.
[0036] In another aspect, an embodiment of the present invention provides a tenant data processing device, the device comprising:
[0037] A second acquisition module is used to obtain the client's request information forwarded by the proxy component of the Redis server;
[0038] A request processing module, configured to process the request information and obtain response information;
[0039] A sending module is used to send the response information to the proxy component based on the connection between the proxy component and the Redis server corresponding to the tenant of the client, so that the proxy component forwards the response information to the client.
[0040] On the other hand, an embodiment of the present invention provides an electronic device, including a processor and a memory, which are connected to each other, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the steps of the tenant data processing method provided by the above aspects of the embodiment of the present invention.
[0041] In another aspect, an embodiment of the present invention provides a computer-readable storage medium, comprising: the computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the steps of the tenant data processing method provided in the above aspect of the embodiment of the present invention are implemented.
[0042] The embodiment of the present invention obtains the client's request information through the proxy component, determines the tenant corresponding to the client based on the request information, determines whether there is a connection corresponding to the tenant between the proxy component and the Redis server, and if there is a connection corresponding to the tenant between the proxy component and the Redis server, forwards the request information to the Redis server based on the connection. Among them, each tenant of the Redis server corresponds to multiple clients, and each tenant corresponds to only one connection between the proxy component and the Redis server. In this embodiment, since each tenant corresponds to only one connection between the proxy component and the Redis server, the proxy component sends all the tenant's client requests to the Redis server through the connection corresponding to the tenant, so that multiple clients of the same tenant can reuse the same connection, thereby reducing the number of connections of the Redis server, realizing resource reuse, and improving the resource utilization of the Redis server. It also reduces the difficulty of operation and maintenance, avoids the waste of resources of the Redis server and the performance degradation caused by too many connections. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is a schematic diagram of an implementation flow of a tenant data processing method provided by an embodiment of the present invention;
[0044] Figure 2 This is a schematic diagram of an implementation flow of another tenant data processing method provided by an embodiment of the present invention;
[0045] Figure 3 This is a schematic diagram of a Redis multi-tenant architecture provided by an application embodiment of the present invention;
[0046] Figure 4 This is a network topology diagram of a proxy component and a Redis server provided by an application embodiment of the present invention;
[0047] Figure 5 is a schematic diagram of an agent component provided by an embodiment of the present invention;
[0048] Figure 6 is a schematic diagram of a tenant data processing device provided by an embodiment of the present invention;
[0049] Figure 7 FIG. 1 is a schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0050] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0051] Redis is an open source key-value storage database written in ANSI C, compliant with the BSD protocol, network-supported, memory-based, distributed, and optionally persistent.
[0052] Tenants in cloud platforms are a logical concept. Once a user (an individual or an enterprise) registers an account on a public cloud platform, the platform considers that user a tenant and allocates resources based on the tenant. A tenant is a user who uses the system or computing resources. This includes all data within the system that identifies a specific user, such as accounts created within the system and their statistical information (Accounting Data), as well as various system data and customized application environments configured by the user.
[0053] Multi-tenancy is a software architecture in which a single software instance can serve multiple distinct user groups. In cloud computing, multi-tenancy can also refer to shared hosting, where server resources are distributed among different customers. The more resources shared between tenants, the higher the utilization of underlying resources, the lower the unit resource cost, and the less isolation between tenants.
[0054] Currently, one method for implementing multi-tenancy in related technologies is to use the tenant name as the key prefix to achieve simple data isolation. This method has the following disadvantages:
[0055] 1. Data between different tenants can be accessed and operated by each other, resulting in low data security.
[0056] 2. The implementation method is on the client side, which increases the user's learning cost and increases the risk of data damage.
[0057] 3. The allocation of key prefixes requires prior communication, which increases communication costs and is not easy to promote and use.
[0058] 4. The increase in the number of tenants is accompanied by an increase in the number of connections, which will cause a serious decline in Redis performance.
[0059] Another method for implementing multi-tenancy in related technologies is to allocate a Redis instance to each tenant. This method has the following disadvantages:
[0060] 1. The increase in the number of tenants and the number of Redis instances has brought great difficulties to operation and maintenance.
[0061] 2. For small tenant scenarios, tenants only use a small amount of Redis resources, but require an entire Redis to provide services, resulting in low resource utilization and waste, while also increasing tenant usage costs.
[0062] In view of the shortcomings of the above-mentioned related technologies, an embodiment of the present invention provides a tenant data processing method that can improve resource utilization. In order to illustrate the technical solution of the present invention, a specific embodiment is described below.
[0063] Figure 1 This is a schematic diagram of the implementation flow of a tenant data processing method provided by an embodiment of the present invention. This tenant data processing method is applied to the proxy component of a Redis server. The proxy component can forward client request information and also forward Redis server response information. The proxy component is a component in a Redis instance. In practical applications, the proxy component can specifically be Redis-Proxy middleware. Redis-Proxy is a high-performance and stable proxy middleware service based on the Redis protocol. It does not intrude on business code, has no connection to the business, does not require any application code changes, and naturally supports distributed deployment.
[0064] refer to Figure 1 , tenant data processing methods include:
[0065] S101, obtaining client request information.
[0066] The concept of multi-tenancy refers to the software architecture that supports one application instance to serve multiple users (Customers), and multiple users are isolated from each other. Each user is called a tenant.
[0067] The Redis server is a typical one-to-many server: a server can establish a network connection with multiple clients, each client can send command requests to the server, and the server receives and processes the command requests sent by the client and returns command replies to the client.
[0068] Each tenant of the Redis server can correspond to multiple clients, and each client can use the corresponding tenant's account name and password to log in to the Redis server to perform operations.
[0069] In related technologies, the client directly sends request information to the Redis server. In this embodiment, a proxy component is deployed. The proxy component can receive the client's request information instead of the Redis server, and the client cannot perceive the proxy operation of the proxy component.
[0070] Here, the request information may include the content of the request, client information, and tenant information corresponding to the client.
[0071] S102, determining the tenant corresponding to the client based on the request information; each tenant of the Redis server corresponds to multiple clients.
[0072] For example, a database may be stored in the proxy component, in which the correspondence between clients and tenants is stored. The client identifier is obtained from the request information, and the database is queried using the client identifier to obtain the corresponding tenant information.
[0073] Alternatively, the request information includes the tenant information corresponding to the client, so that the tenant information corresponding to the client can be directly parsed from the request information.
[0074] S103, determining whether there is a connection corresponding to the tenant between the proxy component and the Redis server; each tenant corresponds to only one connection between the proxy component and the Redis server.
[0075] In this embodiment, the client does not directly establish a connection with the Redis server. Instead, the tenant establishes a connection with the Redis server through a proxy component. No matter how many clients a tenant has, only one connection is established between the proxy component and the Redis server.
[0076] In the proxy component, if a tenant's client has previously sent a request to the Redis server through the proxy component, it indicates that a connection corresponding to the tenant exists between the proxy component and the Redis server. The proxy component can record the connection information corresponding to the tenant between the proxy component and the Redis server. This connection information can include application programming interface (API) information and socket information at both ends of the connection.
[0077] For example, a database can be preset. If a tenant's client has previously connected to the Redis server through the proxy component, the tenant information and connection information will be recorded in the database. If no connection has occurred, the database will not have the tenant's connection information.
[0078] S104: If there is a connection corresponding to the tenant between the proxy component and the Redis server, forward the request information to the Redis server based on the connection.
[0079] For example, if the proxy component stores the tenant's connection information, it means that the tenant's client has historically sent a request to the proxy component, that is, the tenant has established a connection between the proxy component and the Redis server.
[0080] Multiple clients of the same tenant do not always send requests at the same time, which makes connection reuse possible. When the proxy component receives a request from a tenant's client again, this embodiment does not create a new connection, but instead uses the existing connection to send the request to the Redis server. This reuse of connection resources improves the resource utilization of the Redis server.
[0081] In related technologies, each client needs to establish a connection with the Redis server, which can cause performance degradation due to the increased number of connections. However, in this embodiment, multiple clients of the same tenant can reuse the same connection, thereby reducing the number of connections to the Redis server. This eliminates the need to create additional connections to the Redis server and alleviates the performance degradation caused by the increased number of connections.
[0082] The embodiment of the present invention obtains the client's request information through the proxy component, determines the tenant corresponding to the client based on the request information, determines whether there is a connection corresponding to the tenant between the proxy component and the Redis server, and if there is a connection corresponding to the tenant between the proxy component and the Redis server, forwards the request information to the Redis server based on the connection. Among them, each tenant of the Redis server corresponds to multiple clients, and each tenant corresponds to only one connection between the proxy component and the Redis server. In this embodiment, since each tenant has only one connection established between the proxy component and the Redis server, the proxy component sends all the tenant's client requests to the Redis server through the connection corresponding to the tenant, so that multiple clients of the same tenant can reuse the same connection, thereby reducing the number of connections of the Redis server, realizing resource reuse, and improving the resource utilization of the Redis server. It also reduces the difficulty of operation and maintenance, avoids the waste of resources of the Redis server and the performance degradation caused by too many connections.
[0083] In one embodiment, the method further comprises:
[0084] If there is no connection between the proxy component and the Redis server corresponding to the tenant, the connection is created.
[0085] If a tenant's client sends a request to the Redis server for the first time, the proxy component establishes a connection between the proxy component and the Redis server for that tenant and then sends the request to the Redis server through that connection. All subsequent requests from that tenant's clients are sent to the Redis server through that connection. This allows multiple clients from the same tenant to reuse the same connection, enabling resource reuse, reducing the number of connections to the Redis server and improving resource utilization.
[0086] In one embodiment, determining whether there is a connection corresponding to the tenant between the proxy component and the Redis server includes:
[0087] querying a setting database based on the identification information of the tenant to determine whether the setting database stores a socket corresponding to the identification information of the tenant; wherein different connections between the proxy component and the Redis server correspond to different sockets;
[0088] If the setting database stores a socket corresponding to the identification information of the tenant, it is determined that a connection corresponding to the tenant exists between the proxy component and the Redis server.
[0089] The Transmission Control Protocol (TCP) is a connection-oriented, reliable, byte-stream-based communication protocol. Data transmission requires a connection to be established before transmission and to be disconnected afterward. TCP provides point-to-point communication, and each TCP connection is uniquely identified by the sockets at both ends. The two ends of a TCP connection can be thought of as connecting the sockets to form a pipeline, with the two ends of the pipeline, or ports, being called sockets.
[0090] In this embodiment, different connections between the proxy component and the Redis server correspond to different sockets. This embodiment pre-sets a settings database that stores the sockets corresponding to established connections and tenant identification information. When the proxy component receives a new request, it queries the settings database based on the tenant's identification information to see if there is a corresponding socket. If so, it determines that a connection corresponding to the tenant exists between the proxy component and the Redis server.
[0091] In one embodiment, forwarding the request information to the Redis server based on the connection includes:
[0092] determining a status of the connection;
[0093] If the connection is in an unused state, the request information is forwarded to the Redis server based on the connection, and the connection is marked as in used state.
[0094] After forwarding the request information, the connection is marked as unused.
[0095] In order to ensure that the request information can be sent to the Redis server smoothly, this embodiment sets a status for each connection between the proxy component and the Redis server. The status includes a use status and a non-use status. The use status indicates that a client is currently using this connection, and the non-use status indicates that no client is currently using this connection.
[0096] Before sending a request, the connection status is determined. If it is not in use, the request is sent to the Redis server through the connection and the connection is marked as in use.
[0097] After processing the client's request, the connection is marked as unused. This way, when a new request from the tenant needs to be forwarded, it can be sent through the same connection, achieving connection reuse without creating more connections.
[0098] If the connection status is in use, wait until the status returns to non-use before forwarding the request information.
[0099] In one embodiment, if the request information represents an authentication request, after obtaining the request information from the client, the method further includes:
[0100] Obtain the username and password in the request information;
[0101] Forwarding the username and password to the Redis server for authentication; wherein each tenant includes a unique username and password;
[0102] Obtain the authentication result sent by the Redis server; if the authentication is successful, the authentication result includes identification information of the tenant corresponding to the client.
[0103] In this embodiment, each tenant has only one unique user name and password, and all clients of the tenant can access the Redis server only by using the user name and password.
[0104] The purpose of authentication here is to prevent unauthenticated clients or clients that fail authentication from obtaining a usable connection. After receiving a request, it parses the request, obtains the tenant's username and password, and forwards the tenant's username and password to the Redis server for authentication. The Redis server stores the tenant's correct username and password and checks whether the received username and password match the locally stored ones. If they match, authentication succeeds; otherwise, authentication fails.
[0105] Get the authentication result sent by the Redis server. If the authentication is successful, it means that the client has passed the authentication of the corresponding tenant, and the proxy component can further forward the request information. Only authenticated clients can access and operate the tenant's data in the Redis server.
[0106] If the authentication fails, the corresponding error message will be returned to the client, prompting the client to request authentication using the correct username and password.
[0107] In practice, this embodiment is compatible with native Redis-cli, a command-line tool included with native Redis. Redis-cli is a simple program that allows you to send commands directly from a terminal to a Redis server and read its responses. By leveraging native Redis-cli user authentication, it provides tenant identification. For example, a Redis-cli authenticated with "auth tenant1password" can access and manipulate all data belonging to tenant1, but cannot access or manipulate data belonging to other tenants.
[0108] Figure 2 : is a schematic diagram of an implementation flow of another tenant data processing method provided by an embodiment of the present invention. The tenant data processing method is applied to the Redis server in the above embodiment, and the method includes:
[0109] S201, obtaining client request information forwarded by the proxy component of the Redis server.
[0110] Here, each tenant of the Redis server can correspond to multiple clients, and each client can use the corresponding tenant's account name and password to log in to the Redis server to perform operations.
[0111] In related technologies, the client sends a request directly to the Redis server. This embodiment adds a proxy component that forwards both the client's request and the Redis server's reply. The proxy receives the request on behalf of the Redis server, and the client is unaware of the proxy's operation.
[0112] Here, the request information includes request content, client information, and tenant information corresponding to the client.
[0113] S202: Process the request information to obtain response information.
[0114] The Redis server parses the request information, obtains the request content, and processes the tenant data according to the request content. For example, if the request content is to obtain data, the Redis server returns the corresponding data to the client.
[0115] In one embodiment, each tenant has a corresponding data space, and the client can only access and operate data in the data space.
[0116] S203: Send the response information to the proxy component based on the connection between the proxy component and the Redis server corresponding to the tenant of the client, so that the proxy component forwards the response information to the client.
[0117] In this embodiment, the client does not directly establish a connection with the Redis server. Instead, the tenant establishes a connection with the Redis server through a proxy component. No matter how many clients a tenant has, only one connection is established between the proxy component and the Redis server.
[0118] The Redis server returns the response information to the proxy component through the original connection, and the proxy component forwards it to the corresponding client.
[0119] In this embodiment, multiple clients of the same tenant can reuse the same connection, thereby reducing the number of connections to the Redis server. There is no need to create more connections to the Redis server, which can alleviate the performance degradation problem of the Redis server caused by the increase in the number of connections.
[0120] In this embodiment, since each tenant establishes only one connection between the proxy component and the Redis server, the proxy component sends all client requests from the tenant to the Redis server through the connection corresponding to the tenant. This allows multiple clients of the same tenant to reuse the same connection, achieving resource reuse, reducing the number of connections to the Redis server, and simplifying operation and maintenance. This also improves resource utilization and avoids resource waste and performance degradation caused by excessive connections.
[0121] In one embodiment, the method further comprises:
[0122] Obtain the username and password sent by the proxy component;
[0123] Authenticating the username and password; wherein each tenant includes a unique username and password pair;
[0124] If the authentication is successful, the client is marked as the tenant corresponding to the username and password;
[0125] The authentication result is sent to the proxy module.
[0126] In this embodiment, each tenant has only one unique user name and password, and all clients of the tenant can access the Redis server only by using the user name and password.
[0127] The purpose of authentication here is to prevent unauthenticated clients or clients that fail authentication from obtaining a usable connection. After receiving a request, the proxy component parses the request and obtains the tenant's username and password. The proxy component then forwards the tenant's username and password to the Redis server for authentication. The Redis server stores the tenant's correct username and password and checks whether the received username and password match the locally stored ones. If they match, authentication succeeds; otherwise, authentication fails.
[0128] Regardless of whether the authentication is successful, the authentication result will be sent to the proxy component. If the authentication is successful, the Redis server will mark the client as the tenant corresponding to the username and password. The authentication result includes the client's corresponding tenant information so that the proxy component can store the correspondence between the client and the tenant.
[0129] In one embodiment, processing the request information includes:
[0130] The request information is processed in a database of the tenant corresponding to the client; wherein each tenant of the Redis server corresponds to a unique database.
[0131] In the Redis server, each tenant has only one database, and each tenant can only access and perform read and write operations in its corresponding database, thereby achieving tenant data isolation.
[0132] In one embodiment, the method further comprises:
[0133] When a tenant is created in the Redis server, a unique database is allocated to the tenant.
[0134] When an administrator creates a new tenant in the Redis server, the Redis server automatically allocates an unused database to the new tenant. This database belongs only to the tenant and cannot be accessed by other tenants.
[0135] When the tenant is authenticated, the corresponding database will be automatically selected for the tenant, and the tenant's access and operations will be completed in this database.
[0136] In one embodiment, the method further comprises:
[0137] When creating the tenant in the Redis server, the command for the tenant to switch databases is disabled.
[0138] By disabling the command for tenants to switch databases, tenants will not be able to switch to other databases and operate data in other databases. This achieves the isolation of tenant data and improves the security of tenant data.
[0139] refer to Figure 3 , Figure 3 This is a schematic diagram of a Redis multi-tenant architecture provided by an application embodiment of the present invention.
[0140] Tenant1-redis-cli, Tenant2-redis-cli, and Tenantn-redis-cli each represent a tenant.
[0141] This example is compatible with the native redis-cli, allowing you to use Redis's multi-tenancy features without modifying the existing redis-cli. By leveraging the native redis-cli's user authentication capabilities, it provides tenant identification. For example, a redis-cli authenticated with "authtenant1password" can access and manipulate all data belonging to tenant1, but not data belonging to other tenants.
[0142] Multi-tenant redis-proxy is a proxy middleware, corresponding to the proxy component in the above embodiment. redis-proxy is a high-performance and stable proxy middleware service based on the Redis protocol. It does not invade business code, has no connection with the business, does not require any application code changes, and naturally supports distributed deployment.
[0143] Multi-tenant-redis-proxy includes three functional modules: tenant authentication module, request proxy module and connection reuse module.
[0144] The tenant authentication module is used to resolve tenant authentication issues and prevent unauthenticated tenants or tenants who have failed authentication from obtaining available connections. When the multi-tenant redis-proxy establishes a connection with a client, the connection is considered unauthenticated by default. Upon receiving further requests from this connection, the request content is parsed according to the standard Redis communication protocol. If it is an authentication request, the tenant name and password are parsed and forwarded to the Redis server for authentication. If authentication is successful, the connection is identified as having passed the authentication of the corresponding tenant, and further message forwarding can be performed. If it is not an authentication request or authentication fails, a corresponding error message is returned to the client, and the connection remains unauthenticated, awaiting a correct authentication request.
[0145] Request proxy module: The proxy is the basic functional module of redis-proxy, which is used to forward request information from the client and reply information from the Redis server.
[0146] Connection reuse module: used to manage connections between different tenants, so that multiple clients of the same tenant can reuse the same connection, thereby reducing the number of connections and alleviating the performance degradation problem of the Redis server caused by the increase in the number of connections. When a request from client A is received and needs to be forwarded, the request proxy module can obtain a connection between the tenant corresponding to client A and the Redis server from the connection reuse module. If such a connection does not exist, it is created; if it exists, it is returned to the request proxy module. The request proxy module forwards client A's request to the Redis server through the connection. After processing client A's request, it returns the connection to the connection reuse module. In this way, when requests from other clients of the tenant need to be forwarded, they can obtain the same connection from the connection reuse module to achieve connection reuse without creating more connections to the Redis server.
[0147] Multi-tenant Redis refers to the Redis server. This embodiment adds a tenant management module based on the native Redis, which is responsible for tenant creation, update, deletion, authentication and data isolation.
[0148] Tenant authentication function: Native Redis supports authentication of multiple pairs of usernames and passwords. Based on this function, the present invention has been modified so that a pair of usernames and passwords represents only one tenant. When tenant A is created, the username and password of tenant A are written into the Redis authentication module. When tenant A uses a client for authentication, the Redis authentication module can be used directly for authentication. After the authentication is passed, the client is identified as tenant A. In this way, the authentication function of the native Redis-cli can be reused to implement multi-tenant functions, which is convenient for users. When a tenant is deleted, the authentication information is deleted from the Redis authentication module.
[0149] Tenant data isolation function: Native redis supports multiple databases, and the data between these databases is isolated, and users can switch between these databases. Based on this function, this embodiment has been modified so that one tenant is bound to one database. When a tenant is created, the tenant management module will allocate an unused database for the new tenant. When the tenant authentication is passed, the corresponding database will be automatically selected for the tenant. The tenant's access and operation data are all completed in this database, and the tenant will not perceive the database switching. At the same time, the command for the tenant to switch databases is disabled, and the tenant will not be able to switch to other databases and operate the data in other databases. In this way, the isolation of tenant data is achieved and the security of tenant data is improved.
[0150] refer to Figure 4 , Figure 4 This is a network topology diagram of a proxy component and a Redis server provided by an application embodiment of the present invention.
[0151] Tenant 1 and Tenant 2 are two tenants of the Redis server. Tenant 1 includes clients 1-3, and Tenant 2 includes clients 4-6. Any request from a client is sent to the proxy component, which determines which tenant the client belongs to. If it belongs to Tenant 1, the proxy component sends the request to the Redis server through the connection corresponding to Tenant 1. If it belongs to Tenant 2, the proxy component sends the request to the Redis server through the connection corresponding to Tenant 2.
[0152] Here, each tenant has only one connection between the proxy component and the Redis server. The proxy component sends all client requests from a tenant to the Redis server through the connection corresponding to the tenant. For example, requests from clients 1-3 are sent to the Redis server through the connection corresponding to tenant 1; requests from clients 4-6 are sent to the Redis server through the connection corresponding to tenant 2.
[0153] In this embodiment, since each tenant establishes only one connection between the proxy component and the Redis server, the proxy component sends all client requests from the tenant to the Redis server through the connection corresponding to the tenant. This allows multiple clients of the same tenant to reuse the same connection, reducing the number of connections to the Redis server, enabling resource reuse and improving resource utilization. This also reduces operational and maintenance difficulties, avoiding wasted Redis server resources and performance degradation caused by excessive connections.
[0154] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0155] It will be understood that when used in this specification and the appended claims, the terms “comprises” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0156] It should be noted that the technical solutions described in the embodiments of the present invention can be arbitrarily combined without conflict.
[0157] In addition, in the embodiments of the present invention, “first”, “second”, etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0158] refer to Figure 5 , Figure 5 is a schematic diagram of an agent component provided by an embodiment of the present invention, such as Figure 5 As shown, the agent components include:
[0159] The first acquisition module is used to obtain the request information of the client;
[0160] A first determining module is configured to determine a tenant corresponding to the client based on the request information; each tenant of the Redis server corresponds to multiple clients;
[0161] A second determination module is configured to determine whether there is a connection corresponding to the tenant between the proxy component and the Redis server; each tenant corresponds to only one connection between the proxy component and the Redis server;
[0162] A forwarding module is used to forward the request information to the Redis server based on the connection if there is a connection corresponding to the tenant between the proxy component and the Redis server.
[0163] In one embodiment, the second determining module is specifically configured to:
[0164] querying a setting database based on the identification information of the tenant to determine whether the setting database stores a socket corresponding to the identification information of the tenant; wherein different connections between the proxy component and the Redis server correspond to different sockets;
[0165] If the setting database stores a socket corresponding to the identification information of the tenant, it is determined that a connection corresponding to the tenant exists between the proxy component and the Redis server.
[0166] In one embodiment, the forwarding module is specifically configured to:
[0167] determining a status of the connection;
[0168] If the connection is in an unused state, the request information is forwarded to the Redis server based on the connection, and the connection is marked as in used state.
[0169] In one embodiment, the apparatus further comprises:
[0170] The first authentication module is used to obtain the username and password in the request information; forward the username and password to the Redis server for authentication; wherein each tenant includes a unique username and password; obtain the authentication result sent by the Redis server; if the authentication is successful, the authentication result includes the identification information of the tenant corresponding to the client.
[0171] refer to Figure 6 , Figure 6 is a schematic diagram of a tenant data processing device provided by an embodiment of the present invention, such as Figure 6 As shown, the device includes:
[0172] A second acquisition module is used to obtain the client's request information forwarded by the proxy component of the Redis server;
[0173] A request processing module, configured to process the request information and obtain response information;
[0174] A sending module is used to send the response information to the proxy component based on the connection between the proxy component and the Redis server corresponding to the tenant of the client, so that the proxy component forwards the response information to the client.
[0175] In one embodiment, the apparatus further comprises:
[0176] The second authentication module is used to obtain the username and password sent by the proxy component; authenticate the username and password; wherein each tenant includes a unique username and password; if the authentication is successful, mark the client as the tenant corresponding to the username and password; and send the authentication result to the proxy module.
[0177] In one embodiment, the request processing module is specifically configured to:
[0178] The request information is processed in a database of the tenant corresponding to the client; wherein each tenant of the Redis server corresponds to a unique database.
[0179] In actual application, the first acquisition module, the first determination module, the second determination module and the forwarding module can be implemented by a processor in an electronic device, such as a central processing unit (CPU), a digital signal processor (DSP), a microcontroller unit (MCU) or a programmable gate array (FPGA).
[0180] It should be noted that the tenant data processing device provided in the above embodiments only illustrates the division of the above modules when processing tenant data. In actual applications, the above processing can be assigned to different modules as needed, that is, the internal structure of the device can be divided into different modules to complete all or part of the above-described processing. In addition, the proxy component, tenant data processing device, and tenant data processing method embodiments provided in the above embodiments are based on the same concept. The specific implementation process is detailed in the method embodiments and will not be repeated here.
[0181] The tenant data processing device described above may be in the form of an image file. After being executed, the image file may be run as a container or virtual machine to implement the tenant data processing method described herein. Of course, this is not limited to image files; any software capable of implementing the tenant data processing method described herein is within the scope of protection of this application.
[0182] Based on the hardware implementation of the above program modules, and in order to implement the method of the embodiment of the present application, the embodiment of the present application also provides an electronic device. Figure 7 This is a schematic diagram of the hardware structure of the electronic device according to the embodiment of the present application. Figure 7 As shown, the electronic equipment includes:
[0183] Communication interface, capable of exchanging information with other devices such as network equipment;
[0184] The processor is connected to the communication interface to implement information exchange with other devices and is used to execute the methods provided by one or more technical solutions on the electronic device side when running a computer program. The computer program is stored in the memory.
[0185] Of course, in actual applications, the various components in the electronic device are coupled together through a bus system. It is understood that the bus system is used to achieve connection and communication between these components. In addition to the data bus, the bus system also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, Figure 7 Various buses are labeled as bus systems.
[0186] The electronic devices described above can be clustered, such as in the form of a cloud computing platform. A cloud computing platform is a service model that uses computing virtualization, network virtualization, and storage virtualization technologies to organize the physical hardware resources of multiple independent servers into pooled resources. It is a software-defined resource architecture based on the development of virtualization technology, providing resource capabilities in the form of virtual machines and containers. By eliminating the fixed relationship between hardware and operating systems and relying on network connectivity to unify resource scheduling and then provide the required virtual resources and services, it represents a new IT and software delivery model characterized by flexibility, elasticity, distribution, multi-tenancy, and on-demand nature.
[0187] The current cloud computing platform supports several service models:
[0188] SaaS (Software as a Service): Cloud computing platform users do not need to purchase software, but instead rent software deployed on the cloud computing platform. Users do not need to maintain the software, and the software service provider will fully manage and maintain the software;
[0189] PaaS (Platform as a Service): Cloud computing platform users (usually software developers in this case) can build new applications or extend existing applications on the cloud computing platform's infrastructure without having to purchase development, quality control, or production servers.
[0190] IaaS (Infrastructure as a Service): Cloud computing platforms provide data centers, infrastructure hardware and software resources through the Internet. Cloud computing platforms under the IaaS model can provide servers, operating systems, disk storage, databases and / or information resources.
[0191] The memory in the embodiments of the present application is used to store various types of data to support the operation of the electronic device. Examples of such data include: any computer program used to operate on the electronic device.
[0192] It is understood that the memory can be volatile memory or non-volatile memory, or can include both volatile and non-volatile memory. Among them, non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic random access memory (FRAM), flash memory, magnetic surface memory, optical disk, or compact disc read-only memory (CD-ROM); magnetic surface memory can be magnetic disk memory or tape memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), direct memory bus random access memory (DRRAM). The memory described in the embodiments of the present application is intended to include, but is not limited to, these and any other suitable types of memory.
[0193] The methods disclosed in the above embodiments of the present application can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, the steps of the above methods can be completed by hardware integrated logic circuits in the processor or instructions in software form. The above processor may be a general-purpose processor, a DSP, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the methods disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in a memory. The processor reads the program in the memory and completes the steps of the above methods in combination with its hardware.
[0194] Optionally, when the processor executes the program, it implements the corresponding processes implemented by the electronic device in each method of the embodiments of the present application, which will not be described here for the sake of brevity.
[0195] In an exemplary embodiment, the present application also provides a storage medium, namely, a computer storage medium, specifically a computer-readable storage medium, including, for example, a first memory storing a computer program, wherein the computer program can be executed by a processor of an electronic device to perform the steps of the aforementioned method. The computer-readable storage medium can be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, Flash Memory, magnetic surface storage, optical disk, or CD-ROM.
[0196] In the several embodiments provided in this application, it should be understood that the disclosed devices, electronic devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0197] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0198] In addition, all functional units in the embodiments of the present application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the above-mentioned integrated units can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0199] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: mobile storage devices, ROM, RAM, disks or optical disks, etc. Various media that can store program codes.
[0200] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can be essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0201] It should be noted that the technical solutions described in the embodiments of the present application can be combined arbitrarily without conflict.
[0202] In addition, in the examples of this application, "first", "second", etc. are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0203] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A tenant data processing method, applied to a proxy component of a Redis server, characterized in that: include: Get the client's request information; Determining a tenant corresponding to the client based on the request information; Each tenant of the Redis server corresponds to multiple clients; Determine whether there is a connection corresponding to the tenant between the proxy component and the Redis server; each tenant corresponds to only one connection between the proxy component and the Redis server, and multiple clients of the same tenant use the same connection; If there is a connection corresponding to the tenant between the proxy component and the Redis server, the request information is forwarded to the Redis server based on the connection.
2. The method according to claim 1, wherein Determining whether there is a connection corresponding to the tenant between the proxy component and the Redis server includes: querying a setting database based on the identification information of the tenant to determine whether the setting database stores a socket corresponding to the identification information of the tenant; wherein different connections between the proxy component and the Redis server correspond to different sockets; If the setting database stores a socket corresponding to the identification information of the tenant, it is determined that a connection corresponding to the tenant exists between the proxy component and the Redis server.
3. The method according to claim 1, wherein The forwarding the request information to the Redis server based on the connection includes: determining a status of the connection; If the connection is in an unused state, the request information is forwarded to the Redis server based on the connection, and the connection is marked as in used state.
4. The method according to claim 1, wherein If the request information represents an authentication request, after obtaining the request information from the client, the method further includes: Obtain the username and password in the request information; Forwarding the username and password to the Redis server for authentication; wherein each tenant includes a unique username and password; Obtain the authentication result sent by the Redis server; if the authentication is successful, the authentication result includes identification information of the tenant corresponding to the client.
5. A tenant data processing method, applied to a Redis server, comprising: Obtaining client request information forwarded by the proxy component of the Redis server; Processing the request information to obtain response information; The response information is sent to the proxy component based on the connection between the proxy component and the Redis server corresponding to the tenant of the client, so that the proxy component forwards the response information to the client; each tenant corresponds to only one connection between the proxy component and the Redis server, and multiple clients of the same tenant use the same connection.
6. The method according to claim 5, wherein The method further comprises: Obtain the username and password sent by the proxy component; Authenticating the username and password; wherein each tenant includes a unique username and password pair; If the authentication is successful, the client is marked as the tenant corresponding to the username and password; The authentication result is sent to the proxy component.
7. The method according to claim 5, wherein The processing of the request information includes: The request information is processed in a database of the tenant corresponding to the client; wherein each tenant of the Redis server corresponds to a unique database.
8. An agent component, characterized in that: include: The first acquisition module is used to obtain the request information of the client; A first determining module, configured to determine a tenant corresponding to the client based on the request information; Each tenant of the Redis server corresponds to multiple clients; The second determination module is used to determine whether there is a connection corresponding to the tenant between the proxy component and the Redis server; each tenant corresponds to only one connection between the proxy component and the Redis server; multiple clients of the same tenant use the same connection; A forwarding module is used to forward the request information to the Redis server based on the connection if there is a connection corresponding to the tenant between the proxy component and the Redis server.
9. A tenant data processing device, characterized in that: include: The second acquisition module is used to obtain the client request information forwarded by the proxy component of the Redis server; A request processing module, configured to process the request information and obtain response information; A sending module is used to send the response information to the proxy component based on the connection between the proxy component and the Redis server corresponding to the tenant of the client, so that the proxy component forwards the response information to the client; each tenant corresponds to only one connection between the proxy component and the Redis server, and multiple clients of the same tenant use the same connection.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the tenant data processing method according to any one of claims 1 to 7 is implemented.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which includes program instructions. When the program instructions are executed by a processor, the processor executes the tenant data processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Middleware-based data processing method and system and storage medium
CN113377784A