(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缓存的更多相关文章

  1. Java生鲜电商平台-生鲜电商中商品类目、属性、品牌、单位架构设计与实战

    Java生鲜电商平台-生鲜电商中商品类目.属性.品牌.单位架构设计与实战 说明:Java生鲜电商平台-生鲜电商中商品类目.属性.品牌.单位架构设计与实战经验分享 凡是涉及到购物,必然是建立在商品的基础 ...

  2. JAVAEE——宜立方商城03:商品类目选择、Nginx端口或域名区分虚拟机、Nginx反向代理、负载均衡、keepalived实现高可用

    1. 学习计划 第三天: 1.商品类目选择(EasyUI的tree实现) 2.图片上传 a) 图片服务器FastDFS(Nainx部分) 2. 商品类目选择 2.1. 原型 2.2. 功能分析 展示商 ...

  3. 干货 | 揭秘如何增加listing多个类目节点

    流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...

  4. 如何增加亚马逊listing多个类目节点

    流量是电商销售的必要因素,可以说,任何成功的电商平台都离不开流量.亚马逊listing优化做得好,不仅能提高产品的曝光率,还能提升转换率,而好的类目可以吸引大的流量.帮你快速爬升. 首先我们来了解一下 ...

  5. 010商城项目:商品类目的选择——Dao,Service.Action层的分析

    我们现在开始写商品类选择这个功能: 先看效果: 当我们点击"新增商品"---->"选择目录"然后从数据库中查出来数据并显示了. 我们分析数据库的那张表: ...

  6. 【SSH网上商城项目实战10】商品类基本模块的搭建

    转自:https://blog.csdn.net/eson_15/article/details/51354932 前面我们完成了与商品类别相关的业务逻辑,接下来我们开始做具体商品部分. 1. 数据库 ...

  7. 属性 每秒10万吞吐 并发 架构 设计 58最核心的帖子中心服务IMC 类目服务 入口层是Java研发的,聚合层与检索层都是C语言研发的 电商系统里的SKU扩展服务

    小结: 1. 海量异构数据的存储问题 如何将不同品类,异构的数据统一存储起来呢? (1)全品类通用属性统一存储: (2)单品类特有属性,品类类型与通用属性json来进行存储: 2. 入口层是Java研 ...

  8. UML类图的6大关系

    <小酌重构系列>已经完成了大约1/3了,在这些文章中,我使用了一些简单的类图来描述重构策略.在之后的文章中,我可能会借助稍微复杂一些的UML类图来介绍.但是在此之前,我觉得有必要先介绍一下 ...

  9. ECshop网点程序优化-后台添加类目自动选择上次父类目并计算Sort Order

    如果在ECshop后台批量添加过大量类目的人都能体会到是多么的不方便(这点还是要说一下ECshop的产品经理,细节上还是要多注意),每次添加都需要在几百个类目里面找到要添加的父类目也是一个麻烦事,比如 ...

随机推荐

  1. awk 实用案例介绍

    awk 简介 • awk是 3 个姓氏的首字母,代表该语言的 3 个作者 • awk的版本有很多,包括: 旧版 awk,新版 awk(nawk), GNUawk(gawk)等 • awk程序有 awk ...

  2. 实现两个数字的交换(C语言)

    int num1=10; int num2=20; //1.简单的数学方法实现数字交换 num1=num1+num2;//num1=30 num2=num1-num2;//num2=10 num1=n ...

  3. nyoj 524-A-B Problem (java stripTrailingZeros, toPlainString)

    524-A-B Problem 内存限制:64MB 时间限制:1000ms 特判: No 通过数:2 提交数:4 难度:3 题目描述: A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下 ...

  4. 力扣(LeetCode)Excel表列名称 个人题解

    给定一个正整数,返回它在 Excel 表中相对应的列名称. 例如, 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> ...

  5. MySQL数据库的主从同步

    什么要进行数据库的主从同步? 防止单点故障造成的数据丢失 主从复制的原理 MySQL从数据库开启I/O线程,向主服务器发送请求数据同步(获取二进制日志) MySQL数据库开启I/O线程回应从数据库 从 ...

  6. .Net Core 使用NPOI导入数据

    一.搭建环境 1.新建ASP.NET Core Web 应用程序 2.选择API 3.引用Swashbuckle.AspNetCore NuGet 包进行安装. Swashbuckle.AspNetC ...

  7. Linux系统中文件行末尾出现^M的原因及解决办法

    不同系统,有不同的换行符号: 在windows下的文本文件的每一行结尾,都有一个回车('\n')和换行('\r') 在linux下的文本文件的每一行结尾,只有一个回车('\n'); 在Mac下的文本文 ...

  8. Java基础知识总结之类的集合

    Java集合概述 1.集合类也叫作容器类.它的功能相当于一个容器.可以存储数量不确定的数据,以及保存具有映射关系的数据(也被称为关联数组). 2.Java的集合(容器),它是用来”装对象的“(实际上是 ...

  9. Java关于Resource leak: 's' is never closed的问题

    Resource leak: 's' is never closed的问题 问题:在编写Java时出现了Resource leak: 's' is never closed的问题,也就是对象s下面的波 ...

  10. Java异常处理只有Try-Catch吗?

    今天,我们将讨论一个非常重要的主题-Java 中的异常处理.尽管有时可能会对此主题进行过多的讨论,但并非每篇文章都包含有用且相关的信息. Java 中最常见的异常处理机制通常与 try-catch 块 ...