Dynamic system authority management method and device based on Redis, equipment and medium
By designing the permission data model in Redis and utilizing its publish/subscribe function and distributed locking mechanism, the problems of traditional permission management efficiency and response speed are solved, and efficient, flexible and real-time permission management is achieved.
Patent Information
- Application Number
- CN202411398371.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2025-02-25
AI Technical Summary
When traditional system permission management handles a large number of concurrent requests and updates permission data in real time, its efficiency and response speed are limited, making it difficult to meet the flexibility and real-time requirements of modern complex systems for permission management.
The dynamic system permission management method based on Redis is adopted, and the role, permissions and user association relationships are stored in Redis by designing a permission data model, Redis's publish/subscribe function is used to achieve real-time permission updates, and efficient and consistency is ensured through cache optimization and distributed locking mechanisms.
It improves the efficiency and response speed of permission management, enhances flexibility and real-time, is suitable for large systems and high-concurrency scenarios, provides high-speed data storage and processing capabilities, and supports key functions such as real-time data updates and distributed locks.
Smart Images

Figure CN119513849A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of authority management, and in particular to a Redis-based dynamic system authority management method, device, equipment and medium. Background Art
[0002] In traditional system permission management, permission data is usually stored in relational databases. Although relational databases perform well in terms of data consistency, their efficiency and response speed are often limited when processing a large number of concurrent requests and updating permission data in real time. In addition, with the expansion of system scale and the complexity of business, higher requirements are placed on the flexibility and real-time performance of permission management, which are difficult to meet with traditional methods.
[0003] Therefore, how to improve the efficiency and response speed of permission management while enhancing the flexibility and real-time performance of permission management is a technical problem that needs to be solved urgently. Summary of the invention
[0004] The technical task of the present invention is to provide a Redis-based dynamic system authority management method, device, equipment and medium to solve the problem of how to improve the efficiency and response speed of authority management while enhancing the flexibility and real-time performance of authority management.
[0005] The technical task of the present invention is achieved in the following way: a dynamic system rights management method based on Redis, the method is as follows:
[0006] Design permission data model: The permission data model includes roles, permissions, and the relationship between users and roles. The data of roles, permissions, and the relationship between users and roles are stored in Redis in a structured form. The hash data type of Redis is used to store the mapping relationship between roles and permissions, and set or sorted set is used to store the relationship between users and roles to achieve efficient permission query and management.
[0007] Update permissions: Develop a management interface that allows administrators to modify permission configurations in real time through the management interface. The modified permission information is immediately written to Redis. Use Redis's publish / subscribe function to notify each component in the dynamic system of changes in real time to ensure the real-time nature of permission updates.
[0008] Optimize permission cache: cache common permission information in the dynamic system memory. When there is a permission query request, query from the memory first. If it does not hit, query Redis again, reducing the access frequency to Redis and improving the response speed of the dynamic system.
[0009] When the business system performs single sign-on, obtain the latest and complete user permission data;
[0010] The business system loads the business system functions within the scope of authority based on the obtained authority data.
[0011] Preferably, when updating permission data, use Redis's distributed lock mechanism to ensure the consistency and integrity of permission data when multiple threads or multiple service instances operate concurrently.
[0012] As a preferred method, when optimizing the permission cache, the user's permission information is cached in Redis. When performing user authentication, Redis's high-speed data storage, real-time data update, data structure support, publish / subscribe and distributed lock mechanism, scalability, high availability and low latency characteristics are used to complete dynamic system user permission management.
[0013] Preferably, the method also includes permission auditing, during which permission change logs are recorded for auditing and tracking permission management.
[0014] Preferably, the content of the permission change log includes the change time, the person who made the change, and the permission information before and after the change.
[0015] A dynamic system rights management device based on Redis, the device comprising:
[0016] The permission data model design module is used to design the roles, permissions, and the relationship between users and roles in the permission data model. The data of roles, permissions, and the relationship between users and roles are stored in Redis in a structured form. The Redis hash data type is used to store the mapping relationship between roles and permissions, and set or sorted set is used to store the relationship between users and roles, so as to achieve efficient permission query and management.
[0017] The permission update module is used to develop a management interface that allows administrators to modify permission configurations in real time through the management interface. The modified permission information is immediately written to Redis, and the publish / subscribe function of Redis is used to notify the changes of various components in the dynamic system in real time to ensure the real-time nature of permission updates.
[0018] The permission cache optimization module is used to cache commonly used permission information in the dynamic system memory. When there is a permission query request, it will first query from the memory. If it does not hit, it will query Redis, reducing the access frequency to Redis and improving the response speed of the dynamic system;
[0019] The permission data acquisition module is used to obtain the latest and complete user permission data when performing single sign-on through the business system;
[0020] The loading module is used by the business system to load the business system functions within the scope of authority based on the obtained authority data.
[0021] Preferably, when the permission update module updates the permission data, it uses the distributed lock mechanism of Redis to ensure the consistency and integrity of the permission data when multiple threads or multiple service instances operate concurrently;
[0022] When the permission cache optimization module optimizes the permission cache, the user's permission information is cached in Redis. When performing user authentication, Redis's high-speed data storage, real-time data update, data structure support, publish / subscribe and distributed lock mechanism, scalability, high availability and low latency characteristics are used to complete dynamic system user permission management.
[0023] Preferably, the system also includes a permission audit module for recording permission change logs for auditing and tracking permission management; wherein the content of the permission change log includes the change time, the changer, and permission information before and after the change.
[0024] An electronic device comprising: a memory and at least one processor;
[0025] Wherein, the memory stores a computer program;
[0026] The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the above-mentioned Redis-based dynamic system permission management method.
[0027] A computer-readable storage medium stores a computer program, and the computer program can be executed by a processor to implement the above-mentioned Redis-based dynamic system permission management method.
[0028] The Redis-based dynamic system rights management method, device, equipment and medium of the present invention have the following advantages:
[0029] (i) The present invention proposes an efficient, flexible and scalable rights management solution to meet the high requirements for real-time and flexibility of rights management in modern complex systems. By storing the rights information in Redis, a high-performance key-value storage system, the rights can be quickly read and dynamically updated, thereby improving the response speed and management efficiency of the system.
[0030] (ii) The present invention not only improves the efficiency and response speed of permission management, but also enhances the flexibility and real-time performance of permission management. It is applicable to various large-scale systems and high-concurrency scenarios, and provides high-speed data storage and processing capabilities. It also supports key functions such as real-time data update, data structure storage, message notification, and distributed locks. It is a core component for achieving efficient, real-time, and consistent permission management. Through the implementation of the present invention, the efficiency and flexibility of system permission management are significantly improved, providing an efficient, flexible, and scalable solution for permission management of modern complex systems.
[0031] (III) The present invention stores permission information in the form of key-value pairs in Redis, and uses the high performance and low latency characteristics of Redis to achieve fast reading and updating of permission data;
[0032] (iv) The present invention designs a permission update mechanism that allows administrators to modify permission configurations in real time through a Web interface. The modified permission information takes effect immediately without restarting the system or service, thus achieving dynamic adjustment of permissions;
[0033] (V) The present invention introduces a permission cache mechanism to cache commonly used permission information in memory, reduce frequent access to Redis, and further improve system response speed;
[0034] (VI) The present invention adopts a distributed lock mechanism to ensure the consistency and integrity of permission data in high-concurrency scenarios and prevent data conflicts;
[0035] (VII) The present invention implements the permission audit function, records the permission change log, facilitates the tracking of permission modification history, and ensures the transparency and auditability of permission management;
[0036] (VIII) In the present invention, Redis plays the role of core data storage and processing, which is specifically reflected in the following aspects:
[0037] ① High-speed data storage: Redis is an in-memory data structure storage system that can provide extremely fast read and write speeds. In system permission management, Redis is used to store permission information, including roles, permissions, and the association between users and roles. Since the data is stored in memory, the speed of reading and updating permission information is very fast, which greatly improves the system's response speed and overall performance.
[0038] ② Real-time data update: Redis supports real-time data update, which means that when the administrator modifies the permission configuration through the management interface, the updated permission information can be immediately written to Redis and notified to various components of the system in real time. Real-time performance is crucial for dynamic system permission management because it ensures that permission updates take effect immediately without waiting for system restart or cache refresh;
[0039] ③Data structure support: Redis provides a variety of data structures, such as hash, set, sorted set, etc. These data structures are very suitable for storing and managing permission information; for example, hash can be used to store the mapping relationship between roles and permissions, and set or sorted set can be used to store the association relationship between users and roles. Through these data structures, efficient permission query and management can be achieved;
[0040] ④ Publish / Subscribe Mechanism: Redis's Publish / Subscribe (Pub / Sub) mechanism is used to notify permission changes in real time. When permission data is updated in Redis, each subscriber in the system (i.e., each system component) can be notified by publishing a message, and the latest permission information can be obtained in real time to ensure the consistency of permission data.
[0041] ⑤ Distributed lock support: Redis also provides distributed lock function, which is very critical in high concurrency scenarios; when multiple service instances try to update permission data at the same time, Redis's distributed lock can ensure that only the instance that obtains the lock can perform the update operation, preventing data conflicts and ensuring data consistency and integrity. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The present invention is further described below in conjunction with the accompanying drawings.
[0043] Attached Figure 1 This is a flowchart of a dynamic system permission management method based on Redis. DETAILED DESCRIPTION
[0044] The Redis-based dynamic system authority management method, device, equipment and medium of the present invention are described in detail below with reference to the accompanying drawings and specific embodiments of the specification.
[0045] Embodiment 1:
[0046] As attached Figure 1 As shown, this embodiment provides a dynamic system permission management method based on Redis, and the method is specifically as follows:
[0047] S1. Design the permission data model: The permission data model includes roles, permissions, and the relationship between users and roles. The data of roles, permissions, and the relationship between users and roles are stored in Redis in a structured form. The hash data type of Redis is used to store the mapping relationship between roles and permissions, and set or sorted set is used to store the relationship between users and roles to achieve efficient permission query and management.
[0048] S2. Update permissions: Develop a management interface that allows administrators to modify permission configurations in real time through the management interface. The modified permission information is immediately written to Redis. Use Redis's publish / subscribe function to notify each component in the dynamic system of changes in real time to ensure the real-time nature of permission updates.
[0049] S3. Optimize permission cache: cache common permission information in the dynamic system memory. When there is a permission query request, query from the memory first. If it does not hit, query Redis again, reducing the access frequency to Redis and improving the response speed of the dynamic system.
[0050] S4. When the business system performs single sign-on, obtain the latest and complete user authority data;
[0051] S5. The business system loads business system functions within the scope of authority based on the obtained authority data.
[0052] When updating the permission data in step S2 of this embodiment, the distributed lock mechanism of Redis is used to ensure the consistency and integrity of the permission data when multiple threads or multiple service instances operate concurrently.
[0053] When optimizing the permission cache in step S3 of this embodiment, the user's permission information is cached in Redis. When performing user authentication, the dynamic system user permission management is completed by utilizing Redis's high-speed data storage, real-time data update, data structure support, publish / subscribe and distributed lock mechanism, scalability, high availability, and low latency characteristics.
[0054] In this embodiment, the method also includes permission auditing. During the permission auditing process, a permission change log is recorded for auditing and tracking permission management.
[0055] The content of the permission change log in this embodiment includes the change time, the changer, and the permission information before and after the change.
[0056] Embodiment 2:
[0057] This embodiment provides a dynamic system rights management device based on Redis, which includes:
[0058] The permission data model design module is used to design the roles, permissions, and the relationship between users and roles in the permission data model. The data of roles, permissions, and the relationship between users and roles are stored in Redis in a structured form. The Redis hash data type is used to store the mapping relationship between roles and permissions, and set or sorted set is used to store the relationship between users and roles, so as to achieve efficient permission query and management.
[0059] The permission update module is used to develop a management interface that allows administrators to modify permission configurations in real time through the management interface. The modified permission information is immediately written to Redis, and the publish / subscribe function of Redis is used to notify the changes of various components in the dynamic system in real time to ensure the real-time nature of permission updates.
[0060] The permission cache optimization module is used to cache commonly used permission information in the dynamic system memory. When there is a permission query request, it will first query from the memory. If it does not hit, it will query Redis, reducing the access frequency to Redis and improving the response speed of the dynamic system;
[0061] The permission data acquisition module is used to obtain the latest and complete user permission data when performing single sign-on through the business system;
[0062] The loading module is used by the business system to load the business system functions within the scope of authority based on the obtained authority data.
[0063] When the permission update module in this embodiment updates the permission data, it uses the distributed lock mechanism of Redis to ensure the consistency and integrity of the permission data when multiple threads or multiple service instances operate concurrently.
[0064] When the permission cache optimization module in this embodiment optimizes the permission cache, the user's permission information is cached in Redis. When performing user authentication, Redis's high-speed data storage, real-time data update, data structure support, publish / subscribe and distributed lock mechanism, scalability, high availability and low latency are used to complete dynamic system user permission management.
[0065] In this embodiment, the system also includes a permission audit module for recording permission change logs for auditing and tracking permission management; wherein the content of the permission change log includes the change time, the changer, and permission information before and after the change.
[0066] Embodiment 3:
[0067] This embodiment also provides an electronic device, including: a memory and a processor;
[0068] Wherein, the memory stores computer-executable instructions;
[0069] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the Redis-based dynamic system authority management method in any embodiment of the present invention.
[0070] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or any conventional processor, etc.
[0071] The memory can be used to store computer programs and / or modules. The processor realizes various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory can also include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SMC), a secure digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid-state storage devices.
[0072] Embodiment 4:
[0073] This embodiment also provides a computer-readable storage medium, which stores a plurality of instructions, which are loaded by a processor, so that the processor executes the dynamic system permission management method based on Redis in any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code that implements the functions of any of the above embodiments is stored, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.
[0074] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
[0075] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RYM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer via a communication network.
[0076] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.
[0077] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.
[0078] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A dynamic system rights management method based on Redis, characterized in that: The method is as follows: Design the permission data model: The permission data model includes roles, permissions, and the relationship between users and roles. The data of roles, permissions, and the relationship between users and roles are stored in Redis in a structured form. The Redis hash data type is used to store the mapping relationship between roles and permissions, and set or sorted set is used to store the relationship between users and roles. Update permissions: Develop a management interface that allows administrators to modify permission configurations in real time through the management interface. The modified permission information is immediately written to Redis. Use Redis's publish / subscribe function to notify each component in the dynamic system of changes in real time to ensure the real-time nature of permission updates. Optimize permission cache: cache common permission information in the dynamic system memory. When there is a permission query request, query from the memory first. If it does not hit, query Redis again. When the business system performs single sign-on, obtain the latest and complete user permission data; The business system loads the business system functions within the scope of authority based on the obtained authority data.
2. According to the Redis-based dynamic system rights management method of claim 1, it is characterized in that: When updating permission data, use Redis's distributed lock mechanism to ensure the consistency and integrity of permission data when multiple threads or multiple service instances operate concurrently.
3. According to the Redis-based dynamic system rights management method of claim 1, it is characterized in that: When optimizing the permission cache, the user's permission information is cached in Redis. When performing user authentication, Redis's high-speed data storage, real-time data update, data structure support, publish / subscribe and distributed lock mechanism, scalability, high availability, and low latency are used to complete dynamic system user permission management.
4. The Redis-based dynamic system rights management method according to any one of claims 1 to 3, characterized in that: The method also includes permission auditing. During the permission auditing process, permission change logs are recorded for auditing and tracking permission management.
5. The Redis-based dynamic system rights management method according to claim 4, characterized in that: The content of the permission change log includes the change time, changer, and permission information before and after the change.
6. A dynamic system rights management device based on Redis, characterized in that: The device includes: The permission data model design module is used to design the roles, permissions, and the relationship between users and roles in the permission data model. The data of roles, permissions, and the relationship between users and roles are stored in Redis in a structured form. The Redis hash data type is used to store the mapping relationship between roles and permissions, and set or sorted set is used to store the relationship between users and roles. The permission update module is used to develop a management interface that allows administrators to modify permission configurations in real time through the management interface. The modified permission information is immediately written to Redis, and the publish / subscribe function of Redis is used to notify the changes of various components in the dynamic system in real time to ensure the real-time nature of permission updates. The permission cache optimization module is used to cache common permission information in the dynamic system memory. When there is a permission query request, it will first query from the memory, and then query Redis if it does not hit the target. The permission data acquisition module is used to obtain the latest and complete user permission data when performing single sign-on through the business system; The loading module is used by the business system to load the business system functions within the scope of authority based on the obtained authority data.
7. The Redis-based dynamic system rights management device according to claim 6, characterized in that: When the permission update module updates the permission data, it uses the distributed lock mechanism of Redis to ensure the consistency and integrity of the permission data when multiple threads or multiple service instances operate concurrently; When the permission cache optimization module optimizes the permission cache, the user's permission information is cached in Redis. When performing user authentication, Redis's high-speed data storage, real-time data update, data structure support, publish / subscribe and distributed lock mechanism, scalability, high availability and low latency characteristics are used to complete dynamic system user permission management.
8. The Redis-based dynamic system rights management device according to claim 6 or 7, characterized in that: The system also includes a permission audit module for recording permission change logs for auditing and tracking permission management; wherein the content of the permission change log includes the change time, the changer, and permission information before and after the change.
9. An electronic device, characterized in that: include: memory and at least one processor; Wherein, the memory stores a computer program; The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the Redis-based dynamic system permission management method as described in any one of claims 1 to 5.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which can be executed by a processor to implement the Redis-based dynamic system authority management method as described in any one of claims 1 to 5.