In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to achieve session sharing in nginx+redis". In daily operation, I believe many people have doubts about how to achieve session sharing in nginx+redis. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to achieve session sharing in nginx+redis". Next, please follow the editor to study!
1. The first step is to install redis, my server is windows, download is the installation-free version, decompress it, its directory is as follows. At first, redis does not need a password by default. If you want to set a password, you can go to the redis.windows.conf file to find requirepass, delete the previous #, and then set the password after it.
two。 From cmd, enter the root directory of redis and type the following directive: redis-server.exeredis.windows.conf. In this way, you can start redis, and if it starts successfully, the following screen will appear. Of course, you can also modify the conf file, plus the password. Requirepass xxxxx
3. Then we can do some configuration work to implement the global caching of session data.
1) the first step is to add jar package. If you are a maven project, you need to add the following code to pom.xml
Org.springframework.session spring-session-data-redis 1.3.1.release pom
If it is not a maven project, you need to add the following jar packages.
2) write redis.properties with the following code
Redis_isopen:yes# host address redis_hostname=xxx.xxx.xxx.xxx# port redis_port=6379# password redis_password=xxxxxxxx# connection timeout redis_timeout=200000redis_maxidle:300redis_maxactive:600redis_maxwait:100000redis_testonborrow:true
It is basically similar to the connection statement that we configure the database.
3) write a spring-redis.xml configuration file that configures some basic information about redis.
4) in application.xml (the main configuration file of spring), you need to join the scan of redis.properties configuration file, as follows.
/ web-inf/classes/redis.properties
5) introduce spring-redis.xml into the main configuration file, as follows.
6) in web.xml, add a filter about session so that session can be manipulated by redis.
Springsessionrepositoryfilter org.springframework.web.filter.delegatingfilterproxy springsessionrepositoryfilter / *
After this, we have realized the management of session by redis.
7) We can install a redis client to view the data in it, which is called redis desktop manager. As shown in the following figure, it is easy to see the data in the redis database.
Ps. When you quit again, you need to write this way so that you won't make a mistake. (ssh Project)
Public string yipinexit () {iteratorkeys=session.keyset (). Iterator (); while (keys.hasnext ()) {string key=keys.next (); session.remove (key);} return "yipinexit";} at this point, the study on "how nginx+redis implements session sharing" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.