商品类目和商品大广告的Redis缓存
(dubbo)主要的实现类:
商品类目的Redis缓存
com.bjsxt.ego.portal.service.impl.PortalItemCatServiceImpl
package com.bjsxt.ego.portal.service.impl;
import com.bjsxt.ego.beans.CatNode;
import com.bjsxt.ego.beans.CatResult;
import com.bjsxt.ego.beans.JsonUtils;
import com.bjsxt.ego.portal.service.PortalItemCatService;
import com.bjsxt.ego.rpc.pojo.TbItemCat;
import com.bjsxt.ego.rpc.service.ItemCatService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisCluster;
import java.util.ArrayList;
import java.util.List;
@Service
public class PortalItemCatServiceImpl implements PortalItemCatService {
@Autowired
private ItemCatService itemCatServiceProxy;
@Value("${ITEM_CAT}")
private String itemCatkey;
@Autowired
private JedisCluster cluster;
@Override
public String loadItemCatService() {
String jsonstr = cluster.get(itemCatkey);
if (!StringUtils.isEmpty(jsonstr)){
return jsonstr;
}
List<TbItemCat> list = itemCatServiceProxy.loadItemCatListService();
//创建CatResult对象
CatResult result=new CatResult();
//将List转化为符合前端规范数据格式,递归遍历list
List<?> date=getChildren(0L,list);
result.setData(date);
//将result对象序列化json字符串
String str = JsonUtils.objectToJson(result);
//将str缓存到Redis集群中
cluster.set(itemCatkey,str);
return str;
}
private List<?> getChildren(long parentId, List<TbItemCat> itemCats) {
// 盛放指定分类下的所有子分类信息
List resultList = new ArrayList<>();
for (TbItemCat itemCat:itemCats){
if (itemCat.getParentId().equals(parentId)){
if (itemCat.getIsParent()){
//如果itemCat代表一级分类或者二级分类
CatNode catNode=new CatNode();
if (itemCat.getParentId().longValue()==0){
// 如果是一级分类 "<a href='/products/1.html'>图书、音像、电子书刊</a>",
catNode.setName(
"<a href='/products/" + itemCat.getId() + ".html'>" + itemCat.getName() + "</a>");
}else {
// 如果是二级分类 "电子书刊",
catNode.setName(itemCat.getName());
}
// "/products/2.html",
catNode.setUrl("/products/" + itemCat.getId() + ".html");
catNode.setList(getChildren(itemCat.getId(),itemCats));
// 将节点添加到list集合中
resultList.add(catNode);
}else {
// 如果itemCat表示三级分类 "/products/3.html|电子书",
resultList.add("/products/" + itemCat.getId() + ".html|" + itemCat.getName());
}
}
}
return resultList;
}
}
大广告的Redis缓存:
com.bjsxt.ego.portal.service.impl.PortalContentServiceImpl
package com.bjsxt.ego.portal.service.impl;
import com.bjsxt.ego.beans.BigPicture;
import com.bjsxt.ego.beans.JsonUtils;
import com.bjsxt.ego.portal.service.PortalContentService;
import com.bjsxt.ego.rpc.pojo.TbContent;
import com.bjsxt.ego.rpc.service.TbContentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisCluster;
import java.util.ArrayList;
import java.util.List;
@Service
public class PortalContentServiceImpl implements PortalContentService {
@Autowired
private TbContentService tbContentServiceProxy;
@Value("${CONTENT_PICTURE}")
private String contentPicturekey;
//注入JedisCluster
@Autowired
private JedisCluster cluster;
@Override
public String loadContentListByCidService(Long cid) {
//查询Redis数据库
String jesonStr = cluster.get(contentPicturekey);
if (!StringUtils.isEmpty(jesonStr)){
return jesonStr;
}
List<TbContent> list = tbContentServiceProxy.loadTbContentListByCidService(cid);
//封装前台数据格式的广告数据
List<BigPicture> bigList=new ArrayList<>();
for (TbContent content:list){
BigPicture picture=new BigPicture();
picture.setSrcb(content.getPic());
picture.setHeight(240);
picture.setAlt(content.getTitle());
picture.setWidth(670);
picture.setSrc(content.getPic2());
picture.setWidthb(550);
picture.setHref(content.getUrl());
picture.setHeightb(240);
bigList.add(picture);
}
String s = JsonUtils.objectToJson(bigList);
//将str保存到redis缓存
cluster.set(contentPicturekey,s);
cluster.expire(contentPicturekey,86400);
return s;
}
}
接口:
com.bjsxt.ego.portal.service.PortalContentService
package com.bjsxt.ego.portal.service;
public interface PortalContentService {
/**
* 返回某个内容类目,对应的内容数据
* @param cid
* @return
*/
public String loadContentListByCidService(Long cid);
}
com.bjsxt.ego.rpc.service.TbContentService
/**
* 加载某个类目对应的内容列表
* @param cid
* @return
*/
public List<TbContent> loadTbContentListByCidService(Long cid);
(实现类)com.bjsxt.ego.rpc.service.impl.TbContentServiceImpl
@Override
public List<TbContent> loadTbContentListByCidService(Long cid) {
try {
TbContentExample example=new TbContentExample();
TbContentExample.Criteria c = example.createCriteria();
c.andCategoryIdEqualTo(cid);
List<TbContent> tbContents = tbContentMapper.selectByExampleWithBLOBs(example);
return tbContents;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
com.bjsxt.ego.portal.service.PortalItemCatService
package com.bjsxt.ego.portal.service;
public interface PortalItemCatService {
/**
* 加载前台首页的商品类目
* @return
*/
public String loadItemCatService();
}
com.bjsxt.ego.rpc.service.ItemCatService
/**
* 加载门户首页的商品类目
* @return
*/
public List<TbItemCat> loadItemCatListService();
(实现类)com.bjsxt.ego.rpc.service.impl.ItemCatServiceImpl
@Override
public List<TbItemCat> loadItemCatListService() {
TbItemCatExample example=new TbItemCatExample();
return itemCatMapper.selectByExample(example);
}
配置文件(Redis集群)
spring/applicationContext-redis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--加载cache.properties-->
<context:property-placeholder location="classpath:cache.properties"/>
<!--实例化JedisCluster-->
<bean id="cluster" class="redis.clients.jedis.JedisCluster">
<constructor-arg name="nodes">
<set>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.181.130"/>
<constructor-arg name="port" value="6380"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.181.130"/>
<constructor-arg name="port" value="6381"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.181.130"/>
<constructor-arg name="port" value="6382"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.181.130"/>
<constructor-arg name="port" value="6383"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.181.130"/>
<constructor-arg name="port" value="6384"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg name="host" value="192.168.181.130"/>
<constructor-arg name="port" value="6385"/>
</bean>
</set>
</constructor-arg>
</bean>
</beans>
控制台没有SQL语句输出,说明是从集群中取出的数据
商品类目和商品大广告的Redis缓存的更多相关文章
- Java生鲜电商平台-生鲜电商中商品类目、属性、品牌、单位架构设计与实战
Java生鲜电商平台-生鲜电商中商品类目.属性.品牌.单位架构设计与实战 说明:Java生鲜电商平台-生鲜电商中商品类目.属性.品牌.单位架构设计与实战经验分享 凡是涉及到购物,必然是建立在商品的基础 ...
- JAVAEE——宜立方商城03:商品类目选择、Nginx端口或域名区分虚拟机、Nginx反向代理、负载均衡、keepalived实现高可用
1. 学习计划 第三天: 1.商品类目选择(EasyUI的tree实现) 2.图片上传 a) 图片服务器FastDFS(Nainx部分) 2. 商品类目选择 2.1. 原型 2.2. 功能分析 展示商 ...
- 干货 | 揭秘如何增加listing多个类目节点
流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...
- 如何增加亚马逊listing多个类目节点
流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...
- 010商城项目:商品类目的选择——Dao,Service.Action层的分析
我们现在开始写商品类选择这个功能: 先看效果: 当我们点击"新增商品"---->"选择目录"然后从数据库中查出来数据并显示了. 我们分析数据库的那张表: ...
- 【SSH网上商城项目实战10】商品类基本模块的搭建
转自:https://blog.csdn.net/eson_15/article/details/51354932 前面我们完成了与商品类别相关的业务逻辑,接下来我们开始做具体商品部分. 1. 数据库 ...
- 属性 每秒10万吞吐 并发 架构 设计 58最核心的帖子中心服务IMC 类目服务 入口层是Java研发的,聚合层与检索层都是C语言研发的 电商系统里的SKU扩展服务
小结: 1. 海量异构数据的存储问题 如何将不同品类,异构的数据统一存储起来呢? (1)全品类通用属性统一存储: (2)单品类特有属性,品类类型与通用属性json来进行存储: 2. 入口层是Java研 ...
- UML类图的6大关系
<小酌重构系列>已经完成了大约1/3了,在这些文章中,我使用了一些简单的类图来描述重构策略.在之后的文章中,我可能会借助稍微复杂一些的UML类图来介绍.但是在此之前,我觉得有必要先介绍一下 ...
- ECshop网点程序优化-后台添加类目自动选择上次父类目并计算Sort Order
如果在ECshop后台批量添加过大量类目的人都能体会到是多么的不方便(这点还是要说一下ECshop的产品经理,细节上还是要多注意),每次添加都需要在几百个类目里面找到要添加的父类目也是一个麻烦事,比如 ...
随机推荐
- MBR分区表的备份与还原
MBR分区表的备份与还原 MBR分区的存储 从下图可以看出,MBR分区前446字节是boot loader:接下来64字节是分区表:再然后就是三个主分区加一个拓展分区. 一.备份分区表,要跳过前446 ...
- java多线程与线程并发四:线程范围内的共享数据
当多个线程操作同一个共有数据时,一个线程对共有数据的改变会影响到另一个线程.比如下面这个例子:两个线程调用同一个对象的的方法,一个线程的执行结果会影响另一个线程. package com.sky.th ...
- T-SQL Part X: UNION, EXCEPT and INTERSECT
MSDN上关于EXCEPT和INTERSECT的文档.MSDN上关于UNION的文档. 值得注意的是,UNION其实有两种,一种是普通的UNION,另外一种是UNION ALL.加上EXCEPT和IN ...
- tomcat 部署springboot 项目
Springboot项目默认jar包,且内置Tomcat.现需要将项目打成war包,并部署到服务器tomcat中. 1.修改pom.xml文件.将jar修改为war. <packaging> ...
- LyX Error convert to loadable format - error handling
This question used to spend my half a day, and this time again, half a day. Here I write it down in ...
- jenkins手把手教你从入门到放弃03-安装Jenkins时web界面出现该jenkins实例似乎已离线
简介 很久没有安装jenkins了,因为之前用的的服务器一直正常使用,令人郁闷的是,之前用jenkins一直没出过这个问题. 令人更郁闷的是,我尝试了好多个历史版本和最新版本,甚至从之前的服务器把je ...
- nyoj 114-某种序列 (python EOFError, List, append)
114-某种序列 内存限制:64MB 时间限制:3000ms 特判: No 通过数:6 提交数:13 难度:4 题目描述: 数列A满足An = An-1 + An-2 + An-3, n >= ...
- CSS:CSS弹性盒子布局 Flexible Box
一.简介 flexbox:全称Flexible Box, 弹性盒子布局.可以简单实现各种伸缩性的设计,它是由伸缩容器和伸缩项目组成.任何一个元素都可以指定为flexbox布局.这种新的布局方案在200 ...
- 使用Amazon EMR和Apache Hudi在S3上插入,更新,删除数据
将数据存储在Amazon S3中可带来很多好处,包括规模.可靠性.成本效率等方面.最重要的是,你可以利用Amazon EMR中的Apache Spark,Hive和Presto之类的开源工具来处理和分 ...
- web服务,ftp服务以及共享实现
在开始服务前一定要确保可以ping通外网,在虚拟机联网但ping 不通外网下 确认vim /etc/sysconfig/network-scripts/ifcfg-ens33 (nmcli conne ...