提交 07358f28 编写于 作者: 爱吃血肠's avatar 爱吃血肠

项目集成Redis....

上级 f4b4297d
package com.yingjun.ssm.task; package com.yingjun.ssm.task;
import com.yingjun.ssm.cache.RedisCache;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -36,13 +37,15 @@ public class BizQuartz { ...@@ -36,13 +37,15 @@ public class BizQuartz {
private final Logger LOG = LoggerFactory.getLogger(this.getClass()); private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@Autowired @Autowired
private UserDao userDao; private RedisCache redisCache;
/** /**
* 间隔5秒执行 * 间隔5秒执行
*/ */
@Scheduled(cron = "0/5 * * * * ? ") @Scheduled(cron = "0/5 * * * * ? ")
public void cacheClear() { public void cacheClear() {
LOG.info("@Scheduled-------cacheClear()"); LOG.info("@Scheduled-------cacheClear()");
String userName = redisCache.getCache("name",String.class);
LOG.info("登录的用户名称是 :" + userName);
} }
} }
...@@ -2,6 +2,7 @@ package com.yingjun.ssm.web; ...@@ -2,6 +2,7 @@ package com.yingjun.ssm.web;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yingjun.ssm.cache.RedisCache;
import com.yingjun.ssm.dto.BaseResult; import com.yingjun.ssm.dto.BaseResult;
import com.yingjun.ssm.entity.User; import com.yingjun.ssm.entity.User;
import com.yingjun.ssm.enums.ResultEnum; import com.yingjun.ssm.enums.ResultEnum;
...@@ -31,6 +32,8 @@ public class UserController { ...@@ -31,6 +32,8 @@ public class UserController {
private final Logger LOG = LoggerFactory.getLogger(this.getClass()); private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private RedisCache redisCache;
/** /**
* 到达用户登录页面 * 到达用户登录页面
* @return * @return
...@@ -52,6 +55,7 @@ public class UserController { ...@@ -52,6 +55,7 @@ public class UserController {
userService.checkUserLogin(user); userService.checkUserLogin(user);
//页面是以name="email" 接受用户名称的 //页面是以name="email" 接受用户名称的
session.setAttribute("email",user.getEmail()); session.setAttribute("email",user.getEmail());
redisCache.putCache("name",user.getEmail());
} catch (BizException e) { } catch (BizException e) {
return new BaseResult<>(false, e.getMessage()); return new BaseResult<>(false, e.getMessage());
} catch (Exception e) { } catch (Exception e) {
......
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.ip}" /> <property name="hostName" value="${redis.ip}" />
<property name="port" value="${redis.port}" /> <property name="port" value="${redis.port}" />
<property name="password" value="${redis.pass}" /> <!--<property name="password" value="${redis.pass}" />-->
<property name="poolConfig" ref="jedisPoolConfig" /> <property name="poolConfig" ref="jedisPoolConfig" />
</bean> </bean>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册