[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"site-config":3,"primary-menu":6,"cat-redis":85,"catposts-redis":98,"post-detail-post-redis-single-thread-d67c91bd":207},{"config":4,"socialLinks":5},null,[],{"metadata":7,"spec":10,"menuItems":20},{"name":8,"creationTimestamp":9},"primary","2026-09-12T06:13:55.024154Z",{"displayName":11,"menuItems":12},"主菜单",[13,14,15,16,17,18,19],"88c3f10b-321c-4092-86a8-70db00251b74","menu-item-izrtmxer","c4c814d1-0c2c-456b-8c96-4864965fee94","menu-item-column","menu-item-tools","menu-item-zsxq","menu-item-ocrxlczu",[21,30,40,49,58,67,76],{"displayName":22,"metadata":23,"spec":25,"status":28,"children":29},"首页",{"name":13,"creationTimestamp":24},"2026-09-12T06:13:54.422830Z",{"displayName":22,"href":26,"priority":27,"menuName":8},"\u002F",0,{"displayName":22,"href":26},[],{"displayName":31,"metadata":32,"spec":34,"status":38,"children":39},"Java面试八股",{"name":14,"creationTimestamp":33},"2026-09-13T09:42:02.854891Z",{"displayName":31,"href":35,"target":36,"priority":37,"menuName":8},"\u002Fjava-interview","_self",1,{"displayName":31,"href":35},[],{"displayName":41,"metadata":42,"spec":44,"status":47,"children":48},"文章",{"name":15,"creationTimestamp":43},"2026-09-12T06:13:54.457307Z",{"displayName":41,"href":45,"priority":46,"menuName":8},"\u002Farchives",2,{"displayName":41,"href":45},[],{"displayName":50,"metadata":51,"spec":53,"status":56,"children":57},"项目实战",{"name":16,"creationTimestamp":52},"2026-09-14T00:35:08.138170Z",{"displayName":50,"href":54,"target":36,"priority":55,"menuName":8},"\u002Fcolumn",3,{"displayName":50,"href":54},[],{"displayName":59,"metadata":60,"spec":62,"status":65,"children":66},"在线工具",{"name":17,"creationTimestamp":61},"2026-09-14T00:35:08.171474Z",{"displayName":59,"href":63,"target":36,"priority":64,"menuName":8},"\u002Ftools",4,{"displayName":59,"href":63},[],{"displayName":68,"metadata":69,"spec":71,"status":74,"children":75},"知识星球",{"name":18,"creationTimestamp":70},"2026-09-14T00:35:08.199145Z",{"displayName":68,"href":72,"target":36,"priority":73,"menuName":8},"\u002Fzsxq",5,{"displayName":68,"href":72},[],{"displayName":77,"metadata":78,"spec":80,"status":83,"children":84},"特价云服务器",{"name":19,"creationTimestamp":79},"2026-09-25T15:30:59.201614Z",{"displayName":77,"href":81,"target":36,"priority":82,"menuName":8},"\u002Fserver",6,{"displayName":77,"href":81},[],{"metadata":86,"spec":91,"status":96,"postCount":73},{"name":87,"creationTimestamp":88,"labels":89},"redis","2026-09-13T09:13:25.567674Z",{"haloweb.section":90},"interview",{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},"Redis 面试题","","Redis 面试题：数据结构与底层实现、持久化、主从集群、缓存设计与分布式锁。",false,{"permalink":97,"postCount":73,"visiblePostCount":73},"\u002Fcategories\u002Fredis",[99,123,144,165,186],{"metadata":100,"spec":103,"status":112,"categories":117},{"name":101,"creationTimestamp":102},"post-redis-single-thread-d67c91bd","2026-09-13T10:00:57.608185Z",{"title":104,"slug":105,"cover":93,"excerpt":106,"publishTime":108,"categories":109,"tags":110,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"Redis 为什么单线程还这么快？","redis-single-thread",{"raw":93,"autoGenerate":107},true,"2026-09-13T10:00:57.655030Z",[87],[],"PUBLIC",{"permalink":113,"excerpt":114,"lastModifyTime":115,"phase":116},"\u002Farchives\u002Fredis-single-thread","一、核心原因 纯内存操作：数据在内存中，访问速度极快。 I\u002FO 多路复用：用 epoll 处理大量并发连接，单线程也能处理高并发。 避免上下文切换：单线程没有线程切换开销，也没有锁竞争。 二、Redis 6.0 多线程 Redis 6.0 引入多线程，但只用于网络 I\u002FO 的读写，命令执行仍是单线程","2026-09-16T09:13:51.386377Z","PUBLISHED",[118],{"metadata":119,"spec":121,"status":122,"postCount":73},{"name":87,"creationTimestamp":88,"labels":120},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":124,"spec":127,"status":134,"categories":138},{"name":125,"creationTimestamp":126},"post-redis-distributed-lock-b83520e6","2026-09-13T10:00:57.413537Z",{"title":128,"slug":129,"cover":93,"excerpt":130,"publishTime":131,"categories":132,"tags":133,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"Redis 如何实现分布式锁？","redis-distributed-lock",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:57.460603Z",[87],[],{"permalink":135,"excerpt":136,"lastModifyTime":137,"phase":116},"\u002Farchives\u002Fredis-distributed-lock","一、基本实现 SET lock_key unique_value NX EX 30\n NX：key 不存在才设置。 EX：过期时间，防止死锁。 unique_value：释放锁时校验，防止误删别人的锁。 二、释放锁（Lua 脚本保证原子） if redis.call(\"get\", KEYS[1]) ","2026-09-16T09:13:40.536096Z",[139],{"metadata":140,"spec":142,"status":143,"postCount":73},{"name":87,"creationTimestamp":88,"labels":141},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":145,"spec":148,"status":155,"categories":159},{"name":146,"creationTimestamp":147},"post-redis-cache-penetration-83ba9eca","2026-09-13T10:00:57.240970Z",{"title":149,"slug":150,"cover":93,"excerpt":151,"publishTime":152,"categories":153,"tags":154,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"缓存穿透、击穿、雪崩及解决方案？","redis-cache-penetration",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:57.284484Z",[87],[],{"permalink":156,"excerpt":157,"lastModifyTime":158,"phase":116},"\u002Farchives\u002Fredis-cache-penetration","一、缓存穿透 查询不存在的数据，缓存和数据库都没有，请求全打到数据库。 解决方案： - 缓存空值（设置较短过期时间）。 - 布隆过滤器，不存在的 key 直接拦截。 二、缓存击穿 热点 key 过期瞬间，大量并发请求打到数据库。 解决方案： - 互斥锁（setnx），只有一个请求查库并回填缓存。 -","2026-09-16T09:13:38.128100Z",[160],{"metadata":161,"spec":163,"status":164,"postCount":73},{"name":87,"creationTimestamp":88,"labels":162},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":166,"spec":169,"status":176,"categories":180},{"name":167,"creationTimestamp":168},"post-redis-persistence-c40c1a6e","2026-09-13T10:00:57.060111Z",{"title":170,"slug":171,"cover":93,"excerpt":172,"publishTime":173,"categories":174,"tags":175,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"Redis 的持久化方式有哪些？","redis-persistence",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:57.107399Z",[87],[],{"permalink":177,"excerpt":178,"lastModifyTime":179,"phase":116},"\u002Farchives\u002Fredis-persistence","一、RDB（快照） 原理：在某个时间点把内存数据序列化写入 dump.rdb。 触发：save（阻塞）、bgsave（fork 子进程）、自动配置（save 900 1）。 优点：文件紧凑、恢复快。 缺点：可能丢失最后一次快照后的数据。 二、AOF（追加日志） 原理：把写命令追加到 appendon","2026-09-16T09:12:30.734646Z",[181],{"metadata":182,"spec":184,"status":185,"postCount":73},{"name":87,"creationTimestamp":88,"labels":183},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":187,"spec":190,"status":197,"categories":201},{"name":188,"creationTimestamp":189},"post-redis-data-structures-ce205a8f","2026-09-13T10:00:56.752073Z",{"title":191,"slug":192,"cover":93,"excerpt":193,"publishTime":194,"categories":195,"tags":196,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},"Redis 常见数据结构及使用场景？","redis-data-structures",{"raw":93,"autoGenerate":107},"2026-09-13T10:00:56.927778Z",[87],[],{"permalink":198,"excerpt":199,"lastModifyTime":200,"phase":116},"\u002Farchives\u002Fredis-data-structures","一、String 最基础，存字符串\u002F整数\u002F二进制。场景：缓存、计数器（incr）、分布式锁（setnx）、限流。 二、List 双向链表。场景：消息队列（lpush\u002Fbrpop）、最新列表。 三、Hash 键值对集合。场景：对象存储（用户信息）、购物车。 四、Set 无序去重集合。场景：标签、共同好","2026-09-16T09:13:50.934425Z",[202],{"metadata":203,"spec":205,"status":206,"postCount":73},{"name":87,"creationTimestamp":88,"labels":204},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"metadata":208,"spec":209,"status":213,"categories":214,"content":220},{"name":101,"creationTimestamp":102},{"title":104,"slug":105,"cover":93,"excerpt":210,"publishTime":108,"categories":211,"tags":212,"priority":27,"pinned":95,"deleted":95,"visible":111,"allowComment":107},{"raw":93,"autoGenerate":107},[87],[],{"permalink":113,"excerpt":114,"lastModifyTime":115,"phase":116},[215],{"metadata":216,"spec":218,"status":219,"postCount":73},{"name":87,"creationTimestamp":88,"labels":217},{"haloweb.section":90},{"displayName":92,"slug":87,"cover":93,"description":94,"priority":55,"hideFromList":95,"preventParentPostCascadeQuery":95},{"permalink":97,"postCount":73,"visiblePostCount":73},{"content":221,"raw":221},"\u003Ch2>一、核心原因\u003C\u002Fh2>\n\u003Col>\n\u003Cli>\u003Cstrong>纯内存操作\u003C\u002Fstrong>：数据在内存中，访问速度极快。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>I\u002FO 多路复用\u003C\u002Fstrong>：用 epoll 处理大量并发连接，单线程也能处理高并发。\u003C\u002Fli>\n\u003Cli>\u003Cstrong>避免上下文切换\u003C\u002Fstrong>：单线程没有线程切换开销，也没有锁竞争。\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Ch2>二、Redis 6.0 多线程\u003C\u002Fh2>\n\u003Cp>Redis 6.0 引入多线程，但只用于\u003Cstrong>网络 I\u002FO 的读写\u003C\u002Fstrong>，命令执行仍是单线程。原因是瓶颈在网络 I\u002FO 而非 CPU。\u003C\u002Fp>\n\u003Ch2>三、适用场景\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>适合高并发、数据量适中、延迟敏感的场景。\u003C\u002Fli>\n\u003Cli>不适合大 key 操作（如 hgetall 百万级 hash），会阻塞主线程。\u003C\u002Fli>\n\u003C\u002Ful>"]