分布式系统概论
session
服务端保存客户端的相关信息,比如登录信息
Key-value
水平分布式: 多个集群(多个服务)
垂直分布式: 一个Tomcat完成一个功能模块
这个时候我们需要Redis 保证session 一致
分布式例子:用户扫码登录
- 用户信息表
create table `seller_info`(
`seller_id` varchar(32) not null,
`username` varchar(32) not null,
`password` varchar(32) not null,
`openid` varchar(64) not null comment '微信openid',
`create_time` timestamp not null default current_timestamp comment '创建时间',
`update_time` timestamp not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (`seller_id`),
) comment '卖家信息'
- 新建对应的实体类
- 新建持久层
- 新建逻辑层
- 单元测试
- 从微信开放平台获取二维码接口
- 获取openid后与数据库做对比
- 将登录信息存入Redis
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
8.1.Redis的使用
配置
spring.datasource.redis.host=120.0.0.1
spring.datasource.redis.port=6379
@Autowired
private SpringRedisTemplate redisTemplate;
//设置值
redisTemplate.opsForValue().set(“openId”,“xxxxxxxxx”,过期时间,时间单位 );