(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. Redis必备面试题《基础篇》

    Date:2019-11-12 读前思考: 面试官会问什么样的问题? 所问的问题背后真实的套路是什么? 喜欢问Redis哪些问题? 如何顺畅回答面试问的问题?吊打面试官. 1.什么是Redis? Re ...

  2. (C#)WPF:Margin属性和Padding属性的介绍

    1.在进行界面设计时,Margin 和Padding都是对边距进行限制的,其区别在于“一个主外,一个主内”. Margin (边缘)是约束控件与容器控件的边距,设置值分别代表左上右下,使用 Margi ...

  3. java编程思想第四版第十八章总结

    一.概述 如何学习java I/O 学习I/O类库 学习I/O发展史,为什么要学习发展史呢? 因为,如果缺乏发展史,我们就会对什么时候使用哪个类,以及什么时候不该使用它们而感到迷惑. 了解nio 二. ...

  4. Zabbix-(六) JMX监控

    Zabbix-(六) JMX监控 一.前言 Zabbix提供了JMX监控,它通过JMX API获取JVM信息,从而提供监控数据.本文讲述使用JMX监控Tomcat的JVM信息. 准备 Zabbix S ...

  5. ArcGIS API For Javascript:新增热力图层的方法

    当我们要制作一个热力图层,可以通过以下 3 步来实现: 引入类 在 require 中需引入 "esri/layers/FeatureLayer", "esri/rend ...

  6. 50.Qt-QJsonDocument读写json

    QJsonDocument: 提供一种读取和写入JSON文档的方法,可以通过它的的成员函数array()或object()检索文档中包含的数组或对象,然后读取JSON数据,或者修改数据. QJsonO ...

  7. 微信小程序 子组件给父组件传参

    子组件给父组件传参只需这4步: 子组件的两步: 1.子组件绑定函数 addInfo <button type="primary" bindtap="addInfo& ...

  8. Alibaba Nacos 学习(四):Nacos Docker

    Alibaba Nacos 学习(一):Nacos介绍与安装 Alibaba Nacos 学习(二):Spring Cloud Nacos Config Alibaba Nacos 学习(三):Spr ...

  9. python3快速入门教程错误和异常

    Python 中(至少)有两种错误:语法错误(syntax errors)和异常(exceptions). 语法错误 语法错误又称作解析错误: >>> while True prin ...

  10. 【2018寒假集训Day 1】【位运算】生成字符串

    生成字符串(strs) [问题描述] 假设字符串只由字符“0”,“1”,“”组成,其中字符“”表示该字符可由 字符“0”或“1”替代. 现有一些字符串,根据这些字符串生成所有可生成的字符串.如: {1 ...