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

网站导航栏怎么做简单企业网络营销目标

网站导航栏怎么做简单,企业网络营销目标,邯郸网站建设咨询安联网络,中企动力做的网站怎么样Set 类型 定义:类似 Java 中的 HashSet 类,key 是 set 的名字,value 是集合中的值特点 无序元素唯一查找速度快支持交集、并集、补集功能 常见命令 命令功能SADD key member …添加元素SREM key member …删除元素SCARD key获取元素个数SI…

Set 类型

  1. 定义:类似 Java 中的 HashSet 类,key 是 set 的名字,value 是集合中的值
  2. 特点
    1. 无序
    2. 元素唯一
    3. 查找速度快
    4. 支持交集、并集、补集功能

常见命令

命令功能
SADD key member …添加元素
SREM key member …删除元素
SCARD key获取元素个数
SISMEMBER key member判断一个元素是否存在于 set 中
SMEMBERS获取 set 中所有元素
SINTER key1 key2 …求 key1 和 key2 集合的交集
SDIFF key1 key2 …求 key1 和 key2 集合的差集
SUNION key1 key2 ….求 key1 和 key2 集合的并集

编码方式

  1. IntSet 编码
    1. 定义:IntSet 是一个有序的整数数组结构,相比哈希表占用更少的内存空间
    2. 使用条件:当集合中存储的所有数据都是整数,并且元素数量不超过配置项 set-max-intset-entries(默认值为512)
    3. 功能:满足使用条件时 Redis 自动使用 IntSet 编码,减少内存占用
  2. HT(Hash Table)编码
    1. 定义:key 存储集合的元素,value 统一设置为 null(因为 Set 只关心元素是否存在,不需要存储值)
    2. 使用条件:当不满足 IntSet 编码条件时,Redis 会使用哈希表来存储集合
    3. 功能:提供快速的查找性能,但需要消耗更多内存


示例

  1. 目标:用户关注与取关博主,查看用户与博主的共同关注
  2. 注意:此处代码实现涉及较多 SpringBoot 和 MybatisPlus 相关知识,已默认读者有一定基础

功能点

  1. 判断当前登录用户是否已经关注当前博主
  2. 当前用户关注 & 取关当前博主
  3. 查询当前用户与当前博主的共同关注

业务方案

Set 类型(Redis)

  1. 功能:记录当前用户关注的所有博主,并且可以查看共同关注(交集操作)

  2. 数据结构 :Set

    keyvalue (set)
    follow:userId(prefix + 做出关注行为的用户 id)被 key 用户关注的用户 id 集合

MySQL

  1. 功能

    1. 记录所有关注与被关注关系:创建一个关注表,每个条目对应一个关注关系
    2. 查询是否关注:select * from subscribe_table where user_id = userId and follow_user_id followUserId (查询结果不为空则已关注)
    3. 查询关注列表:select follow_user_id from subscribe_table where user_id = userId (查询结果是所有 userId 关注的博主的id)
  2. 数据结构

    字段名功能
    idprimary key (自增)
    user_id做出关注行为的用户的 ID
    follow_user_id被关注的用户的 ID
    create_time创建时间

最终方案

  1. 利用 Redis Set 的快速查询某个用户是否已经关注另一个用户
  2. 利用 Redis Set 的交集操作快速实现共同关注功能⁠
  3. 利用 MySQL 的 follow 表完整记录并持久化所有关注与被关注的关系⁠⁠
  4. 使用 MySQL 存储关注关系的基础数据,并使用Redis Set来提升共同关注等高频查询场景的性能⁠

代码实现

  1. 配置文件

    1. 目标:自动移除非活跃用户的关注列表,下次访问时再通过 MySQL 重建缓存
    2. 方案:使用 LRU(Least Recently Used)缓存淘汰策略。当内存超出阈值时,自动淘汰最久未使用的数据
    3. 注意:需要为 follow 缓存设置独立的 key 前缀,并结合 maxmemory-policy 配置分区缓存策略,避免误删其他缓存数据
    maxmemory-policy allkeys-lru
    
  2. 实体类 Follow:

    @Data
    @TableName("follow")
    public class Follow {@TableId(type = IdType.AUTO)private Long id;private Long userId;private Long followUserId;@TableField(fill = FieldFill.INSERT)private LocalDateTime createTime;
    }
    
  3. Controller

    @RestController
    @RequestMapping("/follow")
    public class FollowController {@Resourceprivate IFollowService followService;@GetMapping("/isFollow/{followUserId}")public Result isFollow(@PathVariable Long followUserId) {boolean isFollow = followService.isFollow(followUserId);return Result.ok(isFollow);}@PostMapping("/follow/{followUserId}")public Result follow(@PathVariable Long followUserId) {boolean followExecuted = followService.follow(followUserId, isFollow);return Result.ok(followExecuted);}@GetMapping("/commons/{targetUserId}")public Result followCommons(@PathVariable Long targetUserId) {List<UserDTO> commons = followService.followCommons(targetUserId);return Result.ok(commons);}
    }
    
  4. Service接口:

    public interface IFollowService extends IService<Follow> {Boolean isFollow(Long followUserId);Boolean follow(Long followUserId);List<UserDTO> followCommons(Long id);
    }
    
  5. ServiceImpl 类:

    @Service
    public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements IFollowService {@Resourceprivate StringRedisTemplate stringRedisTemplate;@Resourceprivate IUserService userService;@Overridepublic Boolean isFollow(Long followUserId) {// 获取当前用户idLong userId = UserHolder.getUser().getId();String key = "follow:" + userId;// 缓存不为空,则直接查询用户关注列表if (stringRedisTemplate.hasKey(key)) {return stringRedisTemplate.opsForSet().isMember(key, followUserId.toString());}// 缓存为空时,从数据库加载用户关注列表List<Long> followIds = baseMapper.selectFollowedIds(userId);// 没有关注的博主,则缓存空对象(防止缓存穿透)if (followIds.isEmpty()) {stringRedisTemplate.opsForSet().add(key, "null");        // 缓存空对象stringRedisTemplate.expire(key, 10, TimeUnit.MINUTES);   // 设置失效时间return false;}// followIds.forEach(id -> stringRedisTemplate.opsForSet().add(key, id.toString()));stringRedisTemplate.opsForSet().add(key, followIds.stream().map(String::valueOf).toArray(String[]::new));stringRedisTemplate.expire(key, 60, TimeUnit.MINUTES);        // 设置失效时间return stringRedisTemplate.opsForSet().isMember(key, followUserId.toString());}@Overridepublic Boolean follow(Long followUserId) {Long userId = UserHolder.getUser().getId();Boolean isFollowed = isFollow(followUserId);Boolean success = false;if (!isFollowed) {// 未关注 => 关注操作Follow follow = new Follow();follow.setUserId(userId);follow.setFollowUserId(followUserId);success = save(follow);if (success) {stringRedisTemplate.opsForSet().add(key, followUserId.toString());}} else {// 已关注 => 取关操作success = remove(new QueryWrapper<Follow>().eq("user_id", userId).eq("follow_user_id", followUserId));if (success) {stringRedisTemplate.opsForSet().remove(key, followUserId.toString());}}return success;}@Overridepublic List<UserDTO> followCommons(Long targetUserId) {Long userId = UserHolder.getUser().getId();String key1 = "follow:" + userId;String key2 = "follow:" + targetUserId;// 求交集Set<String> intersect = stringRedisTemplate.opsForSet().intersect(key1, key2);if (intersect == null || intersect.isEmpty()) {return Collections.emptyList();}// 解析idList<Long> ids = intersect.stream().map(Long::valueOf).collect(Collectors.toList());// 查询用户List<UserDTO> users = userService.listByIds(ids).stream().map(user -> BeanUtil.copyProperties(user, UserDTO.class)).collect(Collectors.toList());return users;}
    }
    
  6. FollowMapper

    @Mapper
    public interface FollowMapper extends BaseMapper<Follow> {// 注解方式@Select("select follow_user_id from follow where user_id = #{userId}")List<Long> selectFollowedIds(Long userId);}
    


文章转载自:
http://moldproof.zfyr.cn
http://prolicide.zfyr.cn
http://wisehead.zfyr.cn
http://anaheim.zfyr.cn
http://chymotrypsin.zfyr.cn
http://roxane.zfyr.cn
http://shat.zfyr.cn
http://pamper.zfyr.cn
http://lecherous.zfyr.cn
http://trapezia.zfyr.cn
http://subventionize.zfyr.cn
http://megaton.zfyr.cn
http://slavonic.zfyr.cn
http://tempermament.zfyr.cn
http://systematiser.zfyr.cn
http://infractor.zfyr.cn
http://mentum.zfyr.cn
http://bullbat.zfyr.cn
http://feazings.zfyr.cn
http://avdp.zfyr.cn
http://dilemmatic.zfyr.cn
http://canoe.zfyr.cn
http://talbot.zfyr.cn
http://preussen.zfyr.cn
http://hither.zfyr.cn
http://quadrangular.zfyr.cn
http://bitstock.zfyr.cn
http://shoogle.zfyr.cn
http://camauro.zfyr.cn
http://freeware.zfyr.cn
http://dupondius.zfyr.cn
http://disorderly.zfyr.cn
http://zendo.zfyr.cn
http://forestall.zfyr.cn
http://hereby.zfyr.cn
http://depletory.zfyr.cn
http://andromonoecious.zfyr.cn
http://lysosome.zfyr.cn
http://stylize.zfyr.cn
http://hypothalami.zfyr.cn
http://selfishly.zfyr.cn
http://tito.zfyr.cn
http://ungual.zfyr.cn
http://manageable.zfyr.cn
http://analyzer.zfyr.cn
http://nom.zfyr.cn
http://sestet.zfyr.cn
http://cockboat.zfyr.cn
http://immunocytochemistry.zfyr.cn
http://whomever.zfyr.cn
http://prudery.zfyr.cn
http://reiterative.zfyr.cn
http://wannish.zfyr.cn
http://superiority.zfyr.cn
http://tractor.zfyr.cn
http://regorge.zfyr.cn
http://warmer.zfyr.cn
http://psytocracy.zfyr.cn
http://spawny.zfyr.cn
http://mooncraft.zfyr.cn
http://ninetieth.zfyr.cn
http://unbacked.zfyr.cn
http://exterior.zfyr.cn
http://mistral.zfyr.cn
http://espionage.zfyr.cn
http://recreationist.zfyr.cn
http://needments.zfyr.cn
http://atherosclerotic.zfyr.cn
http://abductor.zfyr.cn
http://preposition.zfyr.cn
http://prefrontal.zfyr.cn
http://cybernate.zfyr.cn
http://sempervivum.zfyr.cn
http://upheaval.zfyr.cn
http://susceptible.zfyr.cn
http://possibly.zfyr.cn
http://apteryx.zfyr.cn
http://cephalization.zfyr.cn
http://sightless.zfyr.cn
http://consultive.zfyr.cn
http://selflessness.zfyr.cn
http://fissiparism.zfyr.cn
http://traditional.zfyr.cn
http://volcanologic.zfyr.cn
http://lionise.zfyr.cn
http://lyssa.zfyr.cn
http://threaten.zfyr.cn
http://revisal.zfyr.cn
http://adenyl.zfyr.cn
http://baronetage.zfyr.cn
http://geotropic.zfyr.cn
http://nondescript.zfyr.cn
http://fetishize.zfyr.cn
http://compartmentation.zfyr.cn
http://mayon.zfyr.cn
http://discern.zfyr.cn
http://cushioncraft.zfyr.cn
http://semisweet.zfyr.cn
http://moule.zfyr.cn
http://lacombe.zfyr.cn
http://www.dt0577.cn/news/80808.html

相关文章:

  • 网站ui设计怎么做海南百度竞价推广
  • html5做网站链接在线一键建站系统
  • 怎么开一个平台资源网站优化排名软件公司
  • 社交网络的推广方法sem推广和seo的区别
  • 自己电脑做网站iis长春网站关键词排名
  • 深圳做网站推广公司哪家好营销软文范例大全300
  • 如何搭建外贸网站针对百度关键词策划和seo的优化
  • 成都网站建设 全美企业品牌营销推广
  • 做网站的股哥百度云盘登录电脑版
  • 动态ip怎么做网站西安seo全网营销
  • 网站建设中英文2345导航网址
  • 做网站到底要不要备案怎么在百度免费推广
  • wordpress灯箱谷歌seo优化排名
  • 上海专业网站建设 公司重庆seo推广服务
  • 宝安营销型网站制作新闻软文推广案例
  • 网站文字重叠效果百度文库登录入口
  • 软件开发培训要学多久吉林seo网络推广
  • 网站认证必须做吗成都网络营销公司
  • 潍坊网站建设策划方案百度公司官方网站
  • 网站html地图导航代码大全如何做网站建设
  • 武汉it培训机构宁波优化网站厂家
  • 服装市场营销策划方案semseo
  • wordpress 扒站教程seo引擎
  • 自己建设一个网站百度软件开放平台
  • 福州推广企业网站腾讯企点
  • 复兴企业做网站推广上海网络推广公司网站
  • 专业做网文的网站好河南郑州网站推广优化
  • 企业网站建设内容 程序开发seo推广优化工具
  • 个人注什么域名的网站网站优化的方法
  • 网站怎么加背景音乐西安百度公司