java - tomcat+redis集群session共享
PHP中文网
PHP中文网 2017-04-18 09:21:54
0
6
337

简单做了一个测试,servlet中post方法存入session(存入之后立马去getAttribute是有值的),redis也存进去了,但是重新再请求get方法中request.getSession().getAttribute确是null,求解?

环境:jdk7+tomcat7+redis2.8

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(6)
巴扎黑

Redis puts the object and it is null when it is taken out. It is good to put the string. It seems that the only way is to convert the object to json

Problem solved: The bean object was not serialized, causing an exception in redis, but it was normal after serialization

迷茫

Session is only valid in the current tomcat instance, so in the case of multiple tomcat instances, you cannot use request.getSession().getAttribute to obtain the session, but obtain it from redis.

刘奇

Now that redis is used, there is no need to use the session in the container. .

迷茫

In the cluster session retention solution, you can store the sessionId as a key in redis (the value is the session information you want to save). Of course, when you retrieve it, you need to retrieve it from redis. Tomcat does not save the session information.

Peter_Zhu

There is a third-party jar package that can be integrated with tomcat to save the session in redis. The application code does not need to pay attention to this matter

巴扎黑

Try spring-session

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!