集群下使用redis统一session处理
2024-10-21 05:48:16
pom依赖(快照版):
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>5.0.0.Beta1</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
pom.xml正式版:
<dependency>
<groupId>biz.paluch.redis</groupId>
<artifactId>lettuce</artifactId>
<version>4.2.2.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
RedisSession.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;
//依赖包不要导入错。
@EnableRedisHttpSession
@EnableConfigurationProperties(RedisProperties.class)
public class RedisConfiguration { @Resource
private RedisProperties redisProperties; @Bean
public LettuceConnectionFactory connectionFactory() {
LettuceConnectionFactory factory = new LettuceConnectionFactory();
factory.setHostName("localhost");
factory.setPassword("redispassword");
factory.setDatabase(0);
factory.setTimeout(5000);
factory.setPort(6379);
return factory;
} }
然后在把值放入到HttpSession里面就会被自动放入到redis里面了。在集群下自动达到共享session的功能。
如:
public ResponseEntity<Object> browseCunAction(@RequestParam("key")String key,@RequestParam("value")String value,HttpSession session) throws Exception {
session.setAttribute(key, value);
return ResponseEntity.ok(Collections.singletonMap(key, value));
}
最新文章
- CSS兼容各浏览器的hack
- swift 判断字符串长度
- [XAF] How to improve the application&#39;s performance
- 【转】 linux下的g++编译器安装
- mysql 字符串处理优化
- [转]Responsive Tables Demo
- [SAP ABAP开发技术总结]BAPI调用
- C/C++ 框架,类库,资源集合
- 微信web开发者工具调试
- nginx——rewrite模块
- Windows命令行(DOS命令)教程-8 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_7.html
- ubuntu14.04 64位 安装eclipse出错
- 201621123060《JAVA程序设计》第八周学习总结
- numpy.squeeze()是干啥的
- maven将依赖的jar包复制到指定位置
- 解决ASP.NET中ServiceStack.Redis每小时6000次访问请求的问题
- struts2_E_commerce_maven
- PyQt5 各种菜单实现
- Oracle 11g 分区拆分与合并
- Java导包后在测试类中执行正确但在Servlet中执行错误报ClassNotFoundException或者ClassDefNotFoundException解决办法
热门文章
- spring java 方式配置JedisPool Bean
- Mapper not initialized. Call Initialize with appropriate configuration.
- [Functional Programming ADT] Initialize Redux Application State Using The State ADT
- 云计算之路-试用Azure:竟然无法重置虚拟机的管理员密码
- Adobe Acrobat Pro 11安装激活
- iOS程序发布测试-生成ad hoc证书
- SuperMap iClient如何使用WMS地图服务
- json servlet通信 显示数据
- Name与x:Name的关系
- 在windows 2012中安装sharepoint 2013时遇到问题的处理办法