利用redis进行springSession的存储:
存储:
//在session中保存用户信息
HttpSessionsession=httpRequest.getSession(true);
session.setAttribute(Constants.SESSION_KEY_USER+userToken,user);
//存储sessionId
redisService.hmSet(Constants.SESSION_ID_KEY,userToken,session.getId());
获取:
StringsessionId=(String)redisService.hmGet(Constants.SESSION_ID_KEY,userToken);
Stringkey="spring:session:sessions:"+sessionId;
StringhashKey="sessionAttr:"+Constants.SESSION_KEY_USER+userToken;
T_useruser=(T_user)redisService.hmGet(key,hashKey);
redisService中的hmSet和hmGet的代码:
publicvoidhmSet(Stringkey,StringhashKey,Objectvalue){
redisTemplate.opsForHash().put(key,hashKey,value);
}
publicObjecthmGet(Stringkey,ObjecthashKey){
HashOperations
详细代码:
packagecom.handsight.platform.fras.service.impl;
importjava.util.Collection;
importjava.util.List;
importjava.util.Map;
importjava.util.Set;
importjava.util.concurrent.TimeUnit;
importjavax.annotation.Resource;
importorg.springframework.data.redis.core.HashOperations;
importorg.springframework.data.redis.core.RedisTemplate;
importorg.springframework.data.redis.core.ZSetOperations.TypedTuple;
importorg.springframework.stereotype.Service;
importcom.handsight.platform.fras.constant.Constants;
importcom.handsight.platform.fras.mgt.pojo.T_user;
importcom.handsight.platform.fras.service.RedisService;
/**
*@authorCarey2018年1月23日
*
*redis操作工具类
*/
@Service
publicclassRedisServiceImplimplementsRedisService{
@Resource(name="FrasRedisTemplate")
privateRedisTemplate
到此这篇关于springboot中的springSession的存储和获取实现的文章就介绍到这了,更多相关springSession存储获取内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!