(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. 基于typedef的用法详解【转】

    也许新手用这个关键字不多,但它却是一个很有用的关键字,可以使代码模块化程度更好(即与其它代码的关联较少),在C++中还是实现Traits技术的基础,也是模板编程的基本语法之一. 若说变量定义是为变量命 ...

  2. Flink中异步AsyncIO的实现 (源码分析)

    先上张图整体了解Flink中的异步io 阿里贡献给flink的,优点就不说了嘛,官网上都有,就是写库不会柱塞性能更好 然后来看一下, Flink 中异步io主要分为两种 一种是有序Ordered 一种 ...

  3. HttpClient 上传文件

    /// <summary> /// 发送post请求 /// </summary> /// <param name="filePath">文件路 ...

  4. 009.Kubernetes二进制部署kube-apiserver

    一 部署master节点 1.1 master节点服务 kubernetes master 节点运行如下组件: kube-apiserver kube-scheduler kube-controlle ...

  5. drf

    跨域同源 django做跨域同源 需要把csrf去掉 跨站请求伪造 同源 同源机制:域名.协议.端口号相同的同源 简单请求 不写头部请求 跨域会拦截报错缺少请求信息 (1) 请求方法是以下三种方法之一 ...

  6. sso单点登录系统

    sso单点登录概念 1.一处登录,处处登录.会单独做一个单点登录系统,只负责颁发token和验证token,和页面登录功能. 2.通过在浏览器cookie中放入token,和在redis中对应toke ...

  7. ubuntu开机自启动服务

    ubuntu下一个用来管理开机自启动服务的程序,今天在ss vps上安装时老是提示这个错误,百度后,下面的这个方法可行: vi /etc/apt/source.list 输入i,进入Insert模式 ...

  8. netty源码解析(4.0)-29 Future模式的实现

    Future模式是一个重要的异步并发模式,在JDK有实现.但JDK实现的Future模式功能比较简单,使用起来比较复杂.Netty在JDK Future基础上,加强了Future的能力,具体体现在: ...

  9. nyoj 82-迷宫寻宝(一) (多重BFS)

    82-迷宫寻宝(一) 内存限制:64MB 时间限制:1000ms 特判: No 通过数:3 提交数:5 难度:4 题目描述: 一个叫ACM的寻宝者找到了一个藏宝图,它根据藏宝图找到了一个迷宫,这是一个 ...

  10. opencv HSV找颜色,找轮廓用最小旋转矩形框出

    #include <opencv2/opencv.hpp> #include<iostream> #include<string> using namespace ...