Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Redis and Shiro clusters

Shulou Source: shulou.com Published: 2022-06-01 08:42:47 09月24日 Update

This article mainly explains "how to use Redis and Shiro clusters". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use Redis and Shiro clusters.

Specific content

If you are using a Shiro cluster now, in order to avoid access problems, you must cache all Shiro Session in the Redis database, and then the Shiro login is divided into two parts: login authentication and authorization. In order to prevent repeated login operations, two pieces of data should be cached this time: Shiro's Session processing and Shiro role information. At the same time, in order to facilitate processing, the Spring-Data framework will be used to deal with Redis.

The management of the previously used Session is done with a class configured as follows:

1. You need to define your own implementation of SessionDAO, and the implementation of this DAO is best to inherit the "EnterpriseCacheSessionDAO" parent class directly.

2. Modify the applicationContext.xml configuration file:

Then all the Session data that can be used in the distributed cluster will be saved in Redis at this time.

3. Summary

Because Shiro has its own Session implementation mechanism, such a pattern must be an inevitable choice in distributed clusters.

Course title: using Redis to serialize role and permission data

2. Specific content

Before learning Shiro, all roles and permissions were serialized to memory because it was only a single WEB, which was completed using the EHCache cache component. The specific configuration is as follows:

But now it belongs to the server cluster environment, so now if a certain role or permission is saved in the memory of a WEB server, then other servers need to make a query if they need the role or permission. Now it is also best to serialize the data of roles and permissions into Redis data, so that there is no need for repeated query processing on each WEB side. 1. First of all, if you want to serialize the data into the Redis database, you must now have a matching Cache processing class, which is CRUD. Example: define a RedisCache processing class

2. All objects of Cache interface must be processed through CacheManager. Example: define RedisCacheManager program classes

3. Modify the applicationContext.xml configuration file:

Then all the cached data of permissions and roles will be saved in the Redis database at this time.

Thank you for reading, the above is the content of "how to use Redis and Shiro clusters". After the study of this article, I believe you have a deeper understanding of how to use Redis and Shiro clusters, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data clustering processing roles permissions content sequences caching learning configuration intermediate databases servers services login memory distributed just that is files Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi Huawei Shulou Information Shulou Tech Info