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

服装 网站规划方案室内设计者联盟网站

服装 网站规划方案,室内设计者联盟网站,建立网站时什么可以使用中文,关键词优化公司如何选择Set 类型 定义#xff1a;类似 Java 中的 HashSet 类#xff0c;key 是 set 的名字#xff0c;value 是集合中的值特点 无序元素唯一查找速度快支持交集、并集、补集功能 常见命令 命令功能SADD key member …添加元素SREM key member …删除元素SCARD key获取元素个数SI…Set 类型 定义类似 Java 中的 HashSet 类key 是 set 的名字value 是集合中的值特点 无序元素唯一查找速度快支持交集、并集、补集功能 常见命令 命令功能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 集合的并集 编码方式 IntSet 编码 定义IntSet 是一个有序的整数数组结构相比哈希表占用更少的内存空间使用条件当集合中存储的所有数据都是整数并且元素数量不超过配置项 set-max-intset-entries默认值为512功能满足使用条件时 Redis 自动使用 IntSet 编码减少内存占用HTHash Table编码 定义key 存储集合的元素value 统一设置为 null因为 Set 只关心元素是否存在不需要存储值使用条件当不满足 IntSet 编码条件时Redis 会使用哈希表来存储集合功能提供快速的查找性能但需要消耗更多内存 示例 目标用户关注与取关博主查看用户与博主的共同关注注意此处代码实现涉及较多 SpringBoot 和 MybatisPlus 相关知识已默认读者有一定基础 功能点 判断当前登录用户是否已经关注当前博主当前用户关注 取关当前博主查询当前用户与当前博主的共同关注 业务方案 Set 类型Redis 功能记录当前用户关注的所有博主并且可以查看共同关注交集操作 数据结构 Set keyvalue (set)follow:userIdprefix 做出关注行为的用户 id被 key 用户关注的用户 id 集合 MySQL 功能 记录所有关注与被关注关系创建一个关注表每个条目对应一个关注关系查询是否关注select * from subscribe_table where user_id userId and follow_user_id followUserId 查询结果不为空则已关注查询关注列表select follow_user_id from subscribe_table where user_id userId 查询结果是所有 userId 关注的博主的id 数据结构 字段名功能idprimary key 自增user_id做出关注行为的用户的 IDfollow_user_id被关注的用户的 IDcreate_time创建时间 最终方案 利用 Redis Set 的快速查询某个用户是否已经关注另一个用户利用 Redis Set 的交集操作快速实现共同关注功能⁠利用 MySQL 的 follow 表完整记录并持久化所有关注与被关注的关系⁠⁠使用 MySQL 存储关注关系的基础数据并使用Redis Set来提升共同关注等高频查询场景的性能⁠ 代码实现 配置文件 目标自动移除非活跃用户的关注列表下次访问时再通过 MySQL 重建缓存方案使用 LRULeast Recently Used缓存淘汰策略。当内存超出阈值时自动淘汰最久未使用的数据注意需要为 follow 缓存设置独立的 key 前缀并结合 maxmemory-policy 配置分区缓存策略避免误删其他缓存数据maxmemory-policy allkeys-lru实体类 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; }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) {ListUserDTO commons followService.followCommons(targetUserId);return Result.ok(commons);} }Service接口 public interface IFollowService extends IServiceFollow {Boolean isFollow(Long followUserId);Boolean follow(Long followUserId);ListUserDTO followCommons(Long id); }ServiceImpl 类 Service public class FollowServiceImpl extends ServiceImplFollowMapper, 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());}// 缓存为空时从数据库加载用户关注列表ListLong 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 QueryWrapperFollow().eq(user_id, userId).eq(follow_user_id, followUserId));if (success) {stringRedisTemplate.opsForSet().remove(key, followUserId.toString());}}return success;}Overridepublic ListUserDTO followCommons(Long targetUserId) {Long userId UserHolder.getUser().getId();String key1 follow: userId;String key2 follow: targetUserId;// 求交集SetString intersect stringRedisTemplate.opsForSet().intersect(key1, key2);if (intersect null || intersect.isEmpty()) {return Collections.emptyList();}// 解析idListLong ids intersect.stream().map(Long::valueOf).collect(Collectors.toList());// 查询用户ListUserDTO users userService.listByIds(ids).stream().map(user - BeanUtil.copyProperties(user, UserDTO.class)).collect(Collectors.toList());return users;} }FollowMapper Mapper public interface FollowMapper extends BaseMapperFollow {// 注解方式Select(select follow_user_id from follow where user_id #{userId})ListLong selectFollowedIds(Long userId);}
http://www.yayakq.cn/news/3510/

相关文章:

  • 用xml可不可以做网站代码网站推荐
  • 网上工伤做实网站vi设计公司有哪些
  • 有没有可以做app的网站设计软件名称
  • 搭建网站上传文件营销型网站建设合同范本
  • 芜湖营销型网站建设巴中网站建设公司
  • 公司网站如何做的美丽资讯网站排版
  • 做网站网站牟利200万判刑烟台网站建设哪家好呢
  • 如何选择丹徒网站建设软件开发入门
  • 网站开通会员怎么开发自动化系统网站建设首选公司
  • 苗木公司网站模板天眼查公司查询官网
  • 三五互联做网站吗帝国生成网站地图
  • 专业商城网站设计杭州seo优化公司
  • 老板合作网站开发加盟店
  • 成品模板网站做app网站的公司
  • 可视化设计最重要的是确定网站的深圳市龙华区地图全图
  • 泉州做网站seo的高端网站开发秦帝
  • 制作网站商城宁波网站设计方案
  • 网站空间到期怎么续费网站运营 宣传团队建设
  • 河南网站建设哪里有安徽建站优化哪里有
  • 国内比较好用的建筑案例网站婚庆网页设计
  • 好用的ppt模板网站电子商务网站建设的步骤
  • 南通模板建站多少钱wordpress去除category
  • 公司备案的网站被别的公司盗用旅游网站的后台管理系统怎么做
  • 做网站卖电脑网站运营一个月多少钱
  • 建设部执业考试网站主域名进入网站
  • 免费域名注册网站有哪些杭州微信网站开发
  • ps里怎么做微网站模板帝国cms 网站描述的全局变量
  • 建设网站 怀疑对方传销 网站制作 缓刑游戏网站建设表格
  • 手机与pc网站同步模板电脑上做简单的网站
  • 电商网站开发app意义一级做a视频在线观看网站