码迷,mamicode.com
首页 > 其他好文 > 详细

集群下使用redis统一session处理

时间:2017-04-18 15:33:43      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:single   framework   5.0   new   param   统一   version   bean   共享   

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>

  RedisSession.java

@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));
	}

  

集群下使用redis统一session处理

标签:single   framework   5.0   new   param   统一   version   bean   共享   

原文地址:http://www.cnblogs.com/tietazhan/p/6728070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!