商品类目和商品大广告的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的产品经理,细节上还是要多注意),每次添加都需要在几百个类目里面找到要添加的父类目也是一个麻烦事,比如 ...
随机推荐
- java数组、字符串拼接
1. 数组实现拼接 int[] arr ={11,22,33,44,55,66}; System.out.print("["); for (int i = 0; i <arr ...
- HttpClient 上传文件
/// <summary> /// 发送post请求 /// </summary> /// <param name="filePath">文件路 ...
- js数组方法大全(下)
# js数组方法大全(下) 记录一下整理的js数组方法,免得每次要找方法都找不到.图片有点多,注意流量,嘻嘻! 本期分享 forEach() map() filer() every() some() ...
- QKD 一些术语的含义
密钥率:每个信道使用的比特数. 系统开销:不能用来提取最终密钥的信号百分比. SNU:散粒噪声单元 RNG:随机数发生器 QRNG:量子随机数发生器 TRNG:真正的随机数生成器 PRNG:伪随机数发 ...
- (C#)WPF:关于INotifyPropertyChanged接口的介绍
注意:INotifyPropertyChanged接口位于System.CompenentModel名称空间中,想使用INotifyPropertyChanged接口时,头文件需添加“using Sy ...
- codeblocks在Ubuntu 18 下的安装
codeblocks在Ubuntu 18 下的安装: 1. 现在应用中心直接下载CodeBlocks IDE: 2. Ctrl + Alt + T 打开终端 Terminal 3. 输入: sudo ...
- nyoj 76-超级台阶 (递推)
76-超级台阶 内存限制:64MB 时间限制:1000ms 特判: No 通过数:8 提交数:12 难度:3 题目描述: 有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第m级,共 ...
- nyoj 70-阶乘因式分解(二)(数学)
70-阶乘因式分解(二) 内存限制:64MB 时间限制:3000ms 特判: No 通过数:7 提交数:7 难度:3 题目描述: 给定两个数n,m,其中m是一个素数. 将n(0<=n<=2 ...
- hdu 1233 还是畅通工程 (prim, kruskal)
还是畅通工程Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- BIM到底是啥?
近年来随着BIM的大火以及一些政策的支持,BIM逐渐走入建筑行业的视野,但其实大部分人都不知道或者说不了解BIM到底是啥.去百度上进行搜索,你会知道BIM就是Building Infor ...