吐槽,为啥redis要放弃windows这么一块大蛋糕。老外整了一个5的出来,需要的可以去下载
正文
-
在idea中下载redis simple插件。其他的redis插件是收费的,不过可体验30天
-
配置redis
点击右侧+,新建
-
配置完后,测试联通(初始下载redis,redis是没有密码的,所以不填即可)
-
测试数据
-
实例—redis缓存数据
基于内存亦可持久化的特点,redis非常适合做缓存。该案例就是实现将数据库数据拿出来放在redis中
需要jedis、commmons-pool这两个jar包。
//1.先从缓存中查询category,如果没有,从数据库中查询,查询后把数据发在缓存中
Jedis jedis = JedisPoolUtils.getJedis();
String categoryListJson = jedis.get("categoryListJson");
//2.判断categoryListJson是否为空
if(categoryListJson==null){
System.out.println("缓存中没有数据");
//准备分类数据
List<Category> categoryList = C_service.findAllCategory();
Gson gson = new Gson();
categoryListJson = gson.toJson(categoryList);
//把数据放在缓存中
jedis.set("categoryListJson",categoryListJson);
}