<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Redis on 潘忠显的技术博客</title>
    <link>https://panzhongxian.cn/tags/redis/</link>
    <description>Recent content in Redis on 潘忠显的技术博客</description>
    <generator>Hugo</generator>
    <language>zh-CN</language>
    <lastBuildDate>Wed, 01 Apr 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://panzhongxian.cn/tags/redis/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Redis Key 中可以有空格吗</title>
      <link>https://panzhongxian.cn/cn/2026/04/redis-key-with-space/</link>
      <pubDate>Wed, 01 Apr 2026 00:00:00 +0000</pubDate>
      <guid>https://panzhongxian.cn/cn/2026/04/redis-key-with-space/</guid>
      <description>&lt;p&gt;Redis Key 中可以有空格吗&lt;/p&gt;&#xA;&lt;p&gt;考虑一个特别简单的逻辑，需要根据用户输入，拼装 Redis Key 来获得对应的列表。&lt;/p&gt;&#xA;&lt;p&gt;因为是&lt;strong&gt;用户输入&lt;/strong&gt;，可能有各种个样的字符，比如空格、汉字、emoji，直接拼装 key 丢给 Redis 是否会引起异常呢？换句话说，Redis key 是否可以有空格等特殊字符呢？&lt;/p&gt;</description>
    </item>
    <item>
      <title>LRU缓存、 ZSET、有序集合</title>
      <link>https://panzhongxian.cn/cn/2025/03/lru-zset-ordered-set.md/</link>
      <pubDate>Wed, 26 Mar 2025 00:00:00 +0000</pubDate>
      <guid>https://panzhongxian.cn/cn/2025/03/lru-zset-ordered-set.md/</guid>
      <description>&lt;h3 id=&#34;lru-缓存题目&#34;&gt;LRU 缓存题目&lt;/h3&gt;&#xA;&lt;p&gt;程序员面试有一个比较经典的题目：leetcode-144-LRU缓存（Least Recently Used）。&lt;/p&gt;&#xA;&lt;p&gt;简单描述一下题目，有几个要点：&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;缓存初始化时设置一个容量 capacity。当缓存容量达到上限时，移除最久未使用的键值对。&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;get(key)&lt;/code&gt;：如果缓存中存在键 &lt;code&gt;key&lt;/code&gt;，则返回其对应的值，否则返回 -1。&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;put(key, value)&lt;/code&gt;：如果键 &lt;code&gt;key&lt;/code&gt; 已存在，则更新其值；如果键 &lt;code&gt;key&lt;/code&gt; 不存在，则插入该键值对。&lt;/li&gt;&#xA;&lt;li&gt;函数 &lt;code&gt;get&lt;/code&gt; 和 &lt;code&gt;put&lt;/code&gt; 必须以 &lt;code&gt;O(1)&lt;/code&gt; 的平均时间复杂度运行。&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;处理这种场景的思路比较简单：要将&lt;strong&gt;最新使用/插入的缓存&lt;/strong&gt;放到最前——最晚被淘汰，这种就是要&lt;strong&gt;调整节点顺序&lt;/strong&gt;，所以是要使用链表的，使用数组的复杂度会变成 &lt;code&gt;O(N^2)&lt;/code&gt;。另外，&lt;code&gt;get&lt;/code&gt; 的复杂度要是 &lt;code&gt;O(1)&lt;/code&gt; 就需要使用到哈希表。&lt;/p&gt;</description>
    </item>
    <item>
      <title>Redis 的 CLIENT SETINFO 指令</title>
      <link>https://panzhongxian.cn/cn/2024/10/redis-client-setinfo/</link>
      <pubDate>Thu, 10 Oct 2024 00:00:00 +0000</pubDate>
      <guid>https://panzhongxian.cn/cn/2024/10/redis-client-setinfo/</guid>
      <description>&lt;p&gt;今天来介绍一下 &lt;strong&gt;Redis 7.2 版本中引入的&lt;/strong&gt; &lt;code&gt;CLIENT SETINFO/SETNAME&lt;/code&gt; 指令，其加入目的、作用以及对你开发的影响。&lt;/p&gt;&#xA;&lt;h3 id=&#34;背景&#34;&gt;背景&lt;/h3&gt;&#xA;&lt;p&gt;最近用 Python 实现的一个简单的服务，用到 Redis，本地测试 OK，但是发布到线上会&lt;strong&gt;建立连接失败&lt;/strong&gt;。&lt;/p&gt;</description>
    </item>
    <item>
      <title>透彻解析Redis中HyperLogLog的实现</title>
      <link>https://panzhongxian.cn/cn/2024/04/thorough-analysis-redis-hll-implementation/</link>
      <pubDate>Tue, 09 Apr 2024 00:00:00 +0000</pubDate>
      <guid>https://panzhongxian.cn/cn/2024/04/thorough-analysis-redis-hll-implementation/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://panzhongxian.cn/cn/2024/04/hll-simple-introduce/&#34;&gt;前文&lt;/a&gt; 中介绍了一下 HyperLogLog 的简单原理，并且强调了这种算法的&lt;strong&gt;神奇之处&lt;/strong&gt;：内存使用量极低，计算复杂度低，而且可以支持多个数据集的并集操作，估算误差低。&lt;/p&gt;&#xA;&lt;p&gt;本文带你透彻的看完 Redis 中的实现——redis 仓库中 hyperloglog.c，之后你就更会觉着神奇了。&lt;/p&gt;</description>
    </item>
    <item>
      <title>HyperLogLog 简单介绍</title>
      <link>https://panzhongxian.cn/cn/2024/04/hll-simple-introduce/</link>
      <pubDate>Mon, 08 Apr 2024 00:00:00 +0000</pubDate>
      <guid>https://panzhongxian.cn/cn/2024/04/hll-simple-introduce/</guid>
      <description>&lt;p&gt;在前段时间的工作中，我这边有用到 Redis 的 HyperLogLog 来统计一些 UGC 内容的曝光 UV。&lt;/p&gt;&#xA;&lt;p&gt;HyperLogLog 是一种用于估计大规模数据集基数（即集合中不同元素的数量）的概率性算法。使用的过程中，我发现它非常非常神奇：&lt;/p&gt;</description>
    </item>
    <item>
      <title>Redis Lua脚本 遇到问题和解决</title>
      <link>https://panzhongxian.cn/cn/2020/11/redis-lua-script-problems/</link>
      <pubDate>Fri, 20 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://panzhongxian.cn/cn/2020/11/redis-lua-script-problems/</guid>
      <description>&lt;h2 id=&#34;集群上脚本执行luaexists和直接执行的结果不一致&#34;&gt;集群上脚本执行Lua&lt;code&gt;exists&lt;/code&gt;和直接执行的结果“不一致”&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;redis&amp;gt; EVAL &lt;span class=&#34;s2&#34;&gt;&amp;#34;local key = &amp;#39;prefix::&amp;#39; .. KEYS[1]; return {key, redis.call(&amp;#39;exists&amp;#39;, key)};&amp;#34;&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;panzhongxian&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;1&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;prefix::panzhongxian&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;2&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;integer&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;redis&amp;gt; EXISTS prefix::panzhongxian&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;integer&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;这里说的“不一致”是发送Redis集群上的情况。这里“不一致”是加引号，因为这现象并非有什么BUG，而是使用脚本的方法不对。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
