jedis依赖
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
spring配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="jedis" class="redis.clients.jedis.Jedis">
<constructor-arg index="0" value="127.0.0.1"></constructor-arg>
</bean>
</beans>
jedis应用
public List<Menu> getMenusByEmpuuid(Long uuid) {
String menuListJson = jedis.get("menuList_"+uuid);
List<Menu> menuList = null;
if(null == menuListJson) {
menuList = empDao.getMenusByEmpuuid(uuid);
jedis.set("menuList_"+uuid, JSON.toJSONString(menuList));
} else {
menuList = JSON.parseArray(menuListJson, Menu.class);
}
return menuList;
}
jedis.del("menuList_"+uuid());