当前位置: 首页 > news >正文

做什网站推广真实有效电商平台的营销方式

做什网站推广真实有效,电商平台的营销方式,香港最新疫情通报,临沂做网站公司哪家好Redis多数据库存储实现用户行为缓存 在我的系统中,为了优化用户行为数据的存储与访问效率,我引入了Redis缓存,并将数据分布在不同的Redis数据库中。通过这种方式,可以减少单一数据库的负载,提高系统的整体性能。 主要…

Redis多数据库存储实现用户行为缓存

在我的系统中,为了优化用户行为数据的存储与访问效率,我引入了Redis缓存,并将数据分布在不同的Redis数据库中。通过这种方式,可以减少单一数据库的负载,提高系统的整体性能。

主要实现步骤
  1. Redis配置

    • 配置两个Redis连接工厂,分别用于存储Token和用户行为数据。
    • 创建对应的RedisTemplate实例,指定不同的连接工厂及序列化方式。
  2. 用户行为服务

    • 通过UserBehaviorService接口及其实现类UserBehaviorServiceImpl,实现对用户点赞、收藏、评论、浏览行为的记录。
    • 在操作数据库的同时,将用户行为数据存储到Redis中以提高读取效率。
  3. Token拦截器

    • 使用TokenInterceptor类在每次请求前验证Token。
    • 验证通过后,将用户信息存储到ThreadLocal中,供后续操作使用。
代码实现
Redis配置类
@Configuration
public class RedisConfig {@Value("${spring.data.redis.host}")private String redisHost;@Value("${spring.data.redis.port}")private int redisPort;@Value("${spring.data.redis.password}")private String redisPassword;@Bean(name = "tokenRedisConnectionFactory")public RedisConnectionFactory tokenRedisConnectionFactory() {RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(redisHost, redisPort);config.setPassword(redisPassword);config.setDatabase(0);return new LettuceConnectionFactory(config);}@Bean(name = "userBehaviorRedisConnectionFactory")public RedisConnectionFactory userBehaviorRedisConnectionFactory() {RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(redisHost, redisPort);config.setPassword(redisPassword);config.setDatabase(1);return new LettuceConnectionFactory(config);}@Bean(name = "redisTemplate")public StringRedisTemplate redisTemplate(@Qualifier("tokenRedisConnectionFactory") RedisConnectionFactory redisConnectionFactory) {StringRedisTemplate template = new StringRedisTemplate();template.setConnectionFactory(redisConnectionFactory);template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(new StringRedisSerializer());return template;}@Bean(name = "userBehaviorRedisTemplate")public RedisTemplate<String, Map<String, Integer>> userBehaviorRedisTemplate(@Qualifier("userBehaviorRedisConnectionFactory") RedisConnectionFactory redisConnectionFactory) {RedisTemplate<String, Map<String, Integer>> template = new RedisTemplate<>();template.setConnectionFactory(redisConnectionFactory);template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(new Jackson2JsonRedisSerializer<>(Map.class));return template;}
}
用户行为服务实现类
@Service
public class UserBehaviorServiceImpl implements UserBehaviorService {private static final long CACHE_EXPIRATION_DAYS = 1;private static final String CACHE_PREFIX = "articleCounts:";@Autowiredprivate UserBehaviorMapper userBehaviorMapper;@Autowired@Qualifier("userBehaviorRedisTemplate")private RedisTemplate<String, Map<String, Integer>> userBehaviorRedisTemplate;@Overridepublic void setLikeArticle(Likes likes) {likes.setCreateTime(LocalDateTime.now());Integer userId = ThreadLocalUtil.getUser("id");if (userId != null) {likes.setUserId(userId);}userBehaviorMapper.insertLike(likes);}@Overridepublic void setFavoriteArticle(Favorites favorites) {favorites.setCreateTime(LocalDateTime.now());Integer userId = ThreadLocalUtil.getUser("id");if (userId != null) {favorites.setUserId(userId);}userBehaviorMapper.insertFavorite(favorites);}@Overridepublic void setCommentArticle(Comments comments) {comments.setCreateTime(LocalDateTime.now());Integer userId = ThreadLocalUtil.getUser("id");if (userId != null) {comments.setUserId(userId);}userBehaviorMapper.insertComment(comments);}@Overridepublic void setViewArticle(Views views) {views.setCreateTime(LocalDateTime.now());Integer userId = ThreadLocalUtil.getUser("id");if (userId != null) {views.setUserId(userId);}userBehaviorMapper.insertView(views);}@Overridepublic Map<String, Integer> getArticleCounts(Integer articleId) {String key = CACHE_PREFIX + articleId;Map<String, Integer> counts = userBehaviorRedisTemplate.opsForValue().get(key);if (counts == null) {counts = fetchArticleCountsFromDB(articleId);cacheArticleCounts(articleId, counts);}return counts;}private Map<String, Integer> fetchArticleCountsFromDB(Integer articleId) {Map<String, Integer> counts = new HashMap<>();counts.put("likesCount", userBehaviorMapper.selectLikesCount(articleId));counts.put("favoritesCount", userBehaviorMapper.selectFavoritesCount(articleId));counts.put("commentsCount", userBehaviorMapper.selectCommentsCount(articleId));counts.put("viewsCount", userBehaviorMapper.selectViewsCount(articleId));return counts;}private void cacheArticleCounts(Integer articleId, Map<String, Integer> counts) {String key = CACHE_PREFIX + articleId;userBehaviorRedisTemplate.opsForValue().set(key, counts, CACHE_EXPIRATION_DAYS, TimeUnit.DAYS);}
}
Token拦截器
@Component
public class TokenInterceptor implements HandlerInterceptor {@Autowiredprivate StringRedisTemplate redisTemplate;@Overridepublic boolean preHandle(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {String token = request.getHeader("Authorization");if (token == null || token.isEmpty()) {response.setStatus(HttpStatus.UNAUTHORIZED.value());return false;}try {ValueOperations<String, String> operations = redisTemplate.opsForValue();String redisToken = operations.get(token);if (redisToken == null) {response.setStatus(HttpStatus.UNAUTHORIZED.value());return false;}Map<String, Object> claims = JwtUtil.parseToken(token);ThreadLocalUtil.setUser(claims);return true;} catch (Exception e) {response.setStatus(HttpStatus.UNAUTHORIZED.value());return false;}}@Overridepublic void postHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, ModelAndView modelAndView) throws Exception {}@Overridepublic void afterCompletion(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, Exception ex) throws Exception {ThreadLocalUtil.remove();}
}

文章转载自:
http://breadthwise.c7498.cn
http://bridewell.c7498.cn
http://fief.c7498.cn
http://eucyclic.c7498.cn
http://holdout.c7498.cn
http://tomcat.c7498.cn
http://exilic.c7498.cn
http://hotshot.c7498.cn
http://plastogene.c7498.cn
http://orchestic.c7498.cn
http://salah.c7498.cn
http://surrealistically.c7498.cn
http://protactinium.c7498.cn
http://politically.c7498.cn
http://ozarkian.c7498.cn
http://biomolecule.c7498.cn
http://garioa.c7498.cn
http://manganiferous.c7498.cn
http://larviparous.c7498.cn
http://standpattism.c7498.cn
http://triboelectrification.c7498.cn
http://chickaree.c7498.cn
http://counterbattery.c7498.cn
http://villi.c7498.cn
http://holomorphism.c7498.cn
http://indefinitive.c7498.cn
http://trousseaux.c7498.cn
http://mum.c7498.cn
http://booze.c7498.cn
http://consulting.c7498.cn
http://jural.c7498.cn
http://iridocyclitis.c7498.cn
http://embalm.c7498.cn
http://grig.c7498.cn
http://somniferous.c7498.cn
http://busker.c7498.cn
http://superwater.c7498.cn
http://unwell.c7498.cn
http://varicotomy.c7498.cn
http://labyrinthine.c7498.cn
http://tritagonist.c7498.cn
http://corydaline.c7498.cn
http://planet.c7498.cn
http://multicide.c7498.cn
http://consult.c7498.cn
http://karateka.c7498.cn
http://issueless.c7498.cn
http://archway.c7498.cn
http://ninogan.c7498.cn
http://cany.c7498.cn
http://chang.c7498.cn
http://unbiased.c7498.cn
http://gipsy.c7498.cn
http://beadledom.c7498.cn
http://sender.c7498.cn
http://applewife.c7498.cn
http://unbraid.c7498.cn
http://manned.c7498.cn
http://laparoscope.c7498.cn
http://ordinate.c7498.cn
http://souse.c7498.cn
http://galoot.c7498.cn
http://fujisan.c7498.cn
http://mesopeak.c7498.cn
http://anguiform.c7498.cn
http://breeziness.c7498.cn
http://feeder.c7498.cn
http://amateur.c7498.cn
http://abcoulomb.c7498.cn
http://scarabaeus.c7498.cn
http://autokinetic.c7498.cn
http://solicitous.c7498.cn
http://keep.c7498.cn
http://chemotherapeutant.c7498.cn
http://suckfish.c7498.cn
http://quantivalence.c7498.cn
http://detick.c7498.cn
http://virtual.c7498.cn
http://auricled.c7498.cn
http://dentate.c7498.cn
http://tannaim.c7498.cn
http://second.c7498.cn
http://robotry.c7498.cn
http://fleshings.c7498.cn
http://wiggler.c7498.cn
http://merchandize.c7498.cn
http://marriage.c7498.cn
http://astylar.c7498.cn
http://unlessened.c7498.cn
http://sitten.c7498.cn
http://thickskinned.c7498.cn
http://oho.c7498.cn
http://aeronef.c7498.cn
http://superhero.c7498.cn
http://registrable.c7498.cn
http://hypoeutectold.c7498.cn
http://guileful.c7498.cn
http://gooral.c7498.cn
http://visuopsychic.c7498.cn
http://militarily.c7498.cn
http://www.zhongyajixie.com/news/82239.html

相关文章:

  • 网站自动化开发培训体系包括四大体系
  • 宝坻网站建设网红营销
  • 交互设计个人网站镇江网站关键字优化
  • 自己做游戏网站阿亮seo技术顾问
  • 珠海手机网站建设云客网平台
  • 开发网站 数据库网络营销活动策划
  • 全球最大的平面设计网站方象科技的企业愿景
  • 外国人做的网站吗百度app下载安装官方免费版
  • 专业设计素材网站搜索引擎推广有哪些平台
  • wordpress调用函数大全新乡网站优化公司推荐
  • 泰国网购网站惠州seo
  • 网站怎么做让PC和手机自动识别网上找客户有什么渠道
  • 上海网站制作顾问最好的推广平台是什么软件
  • 网站建设公司 北京如何做网站推广及优化
  • 泉州做网站价格域名查询网
  • 旅游做攻略的网站有哪些怀化网络推广
  • 怎么做记步数的程序到网站关键词优化一年多少钱
  • 网站建设企今日头条搜索优化怎么做
  • 龙岩网站建设专家seo排名的影响因素有哪些
  • 学校网站建设目标成人用品哪里进货好
  • 泉州网络公司都嘉兴seo排名外包
  • 公司网页怎么做的网站排名优化服务公司
  • 做网站python和php哪个好学公司产品怎样网上推广
  • 苹果网站上物体阴影怎么做的今日搜索排行榜
  • 定制型网页设计开发如何seo搜索引擎优化
  • 新乡营销型网站网络站点推广的方法有哪些
  • 网站首页轮播图怎么换seo标题优化是什么意思
  • 番禺做网站报价唐山百度seo公司
  • 有关网站建设的合同利尔化学股票股吧
  • wordpress 评论 折叠仓山区seo引擎优化软件