Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xiaoheiAh/hugo-theme-pure.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '2019/11/db/index.html')
-rw-r--r--2019/11/db/index.html165
1 files changed, 81 insertions, 84 deletions
diff --git a/2019/11/db/index.html b/2019/11/db/index.html
index ef650c0..ff6a97b 100644
--- a/2019/11/db/index.html
+++ b/2019/11/db/index.html
@@ -31,6 +31,7 @@
<link rel="stylesheet" href="https://xiaohei.im/hugo-theme-pure/css/style.css">
<link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/9.15.10/styles/github.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css">
<meta property="og:title" content="Redis-数据库长什么样?" />
<meta property="og:description" content="" />
<meta property="og:type" content="article" />
@@ -43,7 +44,7 @@
<meta itemprop="datePublished" content="2019-11-06T11:00:32&#43;08:00" />
<meta itemprop="dateModified" content="2019-11-06T11:00:32&#43;08:00" />
-<meta itemprop="wordCount" content="1860">
+<meta itemprop="wordCount" content="2156">
@@ -163,7 +164,8 @@
<li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/corejava/" class="category-list-link">corejava</a><span class="category-list-count">7</span></li>
<li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/hystrix/" class="category-list-link">hystrix</a><span class="category-list-count">2</span></li>
<li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/leetcode/" class="category-list-link">leetcode</a><span class="category-list-count">3</span></li>
- <li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/redis/" class="category-list-link">redis</a><span class="category-list-count">8</span></li>
+ <li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/redis/" class="category-list-link">redis</a><span class="category-list-count">10</span></li>
+ <li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="category-list-link">学习笔记</a><span class="category-list-count">1</span></li>
<li class="category-list-item"><a href="https://xiaohei.im/hugo-theme-pure/categories/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/" class="category-list-link">消息队列</a><span class="category-list-count">4</span></li>
</ul>
</div>
@@ -190,12 +192,16 @@
class="tag-list-count">3</span></li>
+ <li class="tag-list-item"><a href="https://xiaohei.im/hugo-theme-pure/tags/netty/" class="tag-list-link">netty</a><span
+ class="tag-list-count">1</span></li>
+
+
<li class="tag-list-item"><a href="https://xiaohei.im/hugo-theme-pure/tags/rabbitmq/" class="tag-list-link">rabbitmq</a><span
class="tag-list-count">4</span></li>
<li class="tag-list-item"><a href="https://xiaohei.im/hugo-theme-pure/tags/redis/" class="tag-list-link">redis</a><span
- class="tag-list-count">8</span></li>
+ class="tag-list-count">10</span></li>
<li class="tag-list-item"><a href="https://xiaohei.im/hugo-theme-pure/tags/rust/" class="tag-list-link">rust</a><span
@@ -229,50 +235,50 @@
<li>
<div class="item-inner">
<p class="item-title">
- <a href="https://xiaohei.im/hugo-theme-pure/2019/11/replication/" class="title">Redis-复制功能探索</a>
+ <a href="https://xiaohei.im/hugo-theme-pure/2019/11/netty/" class="title">[学习笔记] Netty</a>
</p>
<p class="item-date">
- <time datetime="2019-11-16 14:24:40 &#43;0800 CST" itemprop="datePublished">2019-11-16</time>
+ <time datetime="2019-11-29 18:40:27 &#43;0800 CST" itemprop="datePublished">2019-11-29</time>
</p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-title">
- <a href="https://xiaohei.im/hugo-theme-pure/2019/11/event/" class="title">Redis-事件</a>
+ <a href="https://xiaohei.im/hugo-theme-pure/2019/11/cluster/" class="title">Redis HA - Cluster</a>
</p>
<p class="item-date">
- <time datetime="2019-11-14 15:01:45 &#43;0800 CST" itemprop="datePublished">2019-11-14</time>
+ <time datetime="2019-11-24 11:48:17 &#43;0800 CST" itemprop="datePublished">2019-11-24</time>
</p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-title">
- <a href="https://xiaohei.im/hugo-theme-pure/2019/11/aof/" class="title">Redis-AOF持久化</a>
+ <a href="https://xiaohei.im/hugo-theme-pure/2019/11/sentinel/" class="title">Redis HA - 哨兵模式</a>
</p>
<p class="item-date">
- <time datetime="2019-11-08 15:18:05 &#43;0800 CST" itemprop="datePublished">2019-11-08</time>
+ <time datetime="2019-11-23 17:56:15 &#43;0800 CST" itemprop="datePublished">2019-11-23</time>
</p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-title">
- <a href="https://xiaohei.im/hugo-theme-pure/2019/11/rdb/" class="title">Redis-RDB持久化</a>
+ <a href="https://xiaohei.im/hugo-theme-pure/2019/11/replication/" class="title">Redis-复制功能探索</a>
</p>
<p class="item-date">
- <time datetime="2019-11-06 19:08:56 &#43;0800 CST" itemprop="datePublished">2019-11-06</time>
+ <time datetime="2019-11-16 14:24:40 &#43;0800 CST" itemprop="datePublished">2019-11-16</time>
</p>
</div>
</li>
<li>
<div class="item-inner">
<p class="item-title">
- <a href="https://xiaohei.im/hugo-theme-pure/2019/11/db/" class="title">Redis-数据库长什么样?</a>
+ <a href="https://xiaohei.im/hugo-theme-pure/2019/11/event/" class="title">Redis-事件</a>
</p>
<p class="item-date">
- <time datetime="2019-11-06 11:00:32 &#43;0800 CST" itemprop="datePublished">2019-11-06</time>
+ <time datetime="2019-11-14 15:01:45 &#43;0800 CST" itemprop="datePublished">2019-11-14</time>
</p>
</div>
</li>
@@ -284,49 +290,14 @@
- <aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
- <div class="slimContent">
- <nav id="toc" class="article-toc">
- <h3 class="toc-title">文章目录</h3>
- <div class="toc-content always-active"><nav id="TableOfContents">
-<ul>
-<li>
-<ul>
-<li><a href="#服务器中的数据库">服务器中的数据库</a></li>
-<li><a href="#切换数据库">切换数据库</a></li>
-<li><a href="#键空间">键空间</a>
-<ul>
-<li><a href="#读写键空间后的操作">读写键空间后的操作</a></li>
-<li><a href="#过期时间保存">过期时间保存</a></li>
-</ul></li>
-<li><a href="#redis的过期键删除策略">Redis的过期键删除策略</a>
-<ul>
-<li><a href="#定时删除">定时删除</a>
-<ul>
-<li><a href="#优点">优点</a></li>
-<li><a href="#缺点">缺点</a></li>
-</ul></li>
-<li><a href="#惰性删除">惰性删除</a>
-<ul>
-<li><a href="#优点-1">优点</a></li>
-<li><a href="#缺点-1">缺点</a></li>
-</ul></li>
-<li><a href="#定期删除">定期删除</a>
-<ul>
-<li><a href="#优点-2">优点</a></li>
-<li><a href="#难点">难点</a></li>
-</ul></li>
-<li><a href="#redis采用方案">redis采用方案</a></li>
-</ul></li>
-<li><a href="#aof-rdb-复制功能对过期键的处理">AOF,RDB &amp; 复制功能对过期键的处理</a></li>
-<li><a href="#数据库通知">数据库通知</a></li>
-</ul></li>
-</ul>
-</nav>
- </div>
- </nav>
- </div>
- </aside>
+<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
+ <div class="slimContent">
+ <h4 class="toc-title">文章目录</h4>
+ <nav id="toc" class="js-toc toc">
+
+ </nav>
+ </div>
+</aside>
<main class="main" role="main"><div class="content">
<article id="-" class="article article-type-" itemscope
itemtype="http://schema.org/BlogPosting">
@@ -363,11 +334,11 @@
</span>
<span class="post-comment"><i class="icon icon-comment"></i> <a href="/hugo-theme-pure/2019/11/db/#comments"
class="article-comment-link">评论</a></span>
- <span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计:1860字</span>
- <span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长:4分 </span>
+ <span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计:2156字</span>
+ <span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长:5分 </span>
</div>
</div>
- <div class="article-entry marked-body" itemprop="articleBody">
+ <div class="article-entry marked-body js-toc-content" itemprop="articleBody">
<h2 id="服务器中的数据库">服务器中的数据库</h2>
<p>redis的数据库是保存在一个db数组中的,默认会新建16个数组.</p>
@@ -393,7 +364,7 @@ typedef struct client {
}
</code></pre>
-<p><img src="https://raw.githubusercontent.com/xiaoheiAh/imgs/master/20191106112623.png" alt="redis设计与实现-指向当前选中db图例" /></p>
+<p><img src="https://cdn.jsdelivr.net/gh/xiaoheiAh/imgs@master/20191106112623.png" alt="redis设计与实现-指向当前选中db图例" /></p>
<h2 id="键空间">键空间</h2>
@@ -488,6 +459,20 @@ typedef struct redisDb {
<p>定期删除是通过 <code>redis</code> 的定时任务执行.在规定的时间内,多次遍历服务器的各个数据库,从 <code>expires</code> 字典中 <strong>随机抽查</strong> 一部分键的过期时间.<code>current_db</code> 会记录当前函数检查的进度,并在下一次函数执行时,接着上次的执行.循环往复地执行.</p>
+<h2 id="内存淘汰策略">内存淘汰策略</h2>
+
+<p>默认策略是 <code>volatile-lru</code>,即超过最大内存后,在过期键中使用 lru 算法进行 key 的剔除,保证不过期数据不被删除,但是可能会出现 OOM 问题。</p>
+
+<h5 id="其他策略如下">其他策略如下:</h5>
+
+<ul>
+<li>allkeys-lru:根据 LRU 算法删除键,不管数据有没有设置超时属性,直到腾出足够空间为止。</li>
+<li>allkeys-random:随机删除所有键,直到腾出足够空间为止。</li>
+<li>volatile-random: 随机删除过期键,直到腾出足够空间为止。</li>
+<li>volatile-ttl:根据键值对象的 ttl 属性,删除最近将要过期数据。如果没有,回退到 noeviction 策略。</li>
+<li>noeviction:不会剔除任何数据,拒绝所有写入操作并返回客户端错误信息 &ldquo;(error) OOM command not allowed when used memory&rdquo;,此时 Redis 只响应读操作。</li>
+</ul>
+
<h2 id="aof-rdb-复制功能对过期键的处理">AOF,RDB &amp; 复制功能对过期键的处理</h2>
<ol>
@@ -702,39 +687,52 @@ void notifyKeyspaceEvent(int type, char *event, robj *key, int dbid) {
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
<script>
- window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
+ window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/rust.min.js"></script>
<script type="text/javascript"
- src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
+ src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
<script>
-hljs.configure({
- tabReplace: ' ',
- classPrefix: ''
-
-})
-hljs.initHighlightingOnLoad();
+ hljs.configure({
+ tabReplace: ' ',
+ classPrefix: ''
+
+ })
+ hljs.initHighlightingOnLoad();
</script>
<script type="text/javascript" src="https://xiaohei.im/hugo-theme-pure/js/application.js"></script>
<script type="text/javascript" src="https://xiaohei.im/hugo-theme-pure/js/plugin.js"></script>
<script>
- (function (window) {
- var INSIGHT_CONFIG = {
- TRANSLATION: {
- POSTS: '文章',
- PAGES: '页面',
- CATEGORIES: '分类',
- TAGS: '标签',
- UNTITLED: '(未命名)',
- },
- ROOT_URL: 'https:\/\/xiaohei.im\/hugo-theme-pure',
- CONTENT_URL: 'https:\/\/xiaohei.im\/hugo-theme-pure\/searchindex.json ',
- };
- window.INSIGHT_CONFIG = INSIGHT_CONFIG;
- })(window);
- </script>
+ (function (window) {
+ var INSIGHT_CONFIG = {
+ TRANSLATION: {
+ POSTS: '文章',
+ PAGES: '页面',
+ CATEGORIES: '分类',
+ TAGS: '标签',
+ UNTITLED: '(未命名)',
+ },
+ ROOT_URL: 'https:\/\/xiaohei.im\/hugo-theme-pure',
+ CONTENT_URL: 'https:\/\/xiaohei.im\/hugo-theme-pure\/searchindex.json ',
+ };
+ window.INSIGHT_CONFIG = INSIGHT_CONFIG;
+ })(window);
+</script>
<script type="text/javascript" src="https://xiaohei.im/hugo-theme-pure/js/insight.js"></script>
+<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script>
+<script>
+ tocbot.init({
+
+ tocSelector: '.js-toc',
+
+ contentSelector: '.js-toc-content',
+
+ headingSelector: 'h1, h2, h3',
+
+ hasInnerContainers: true,
+ });
+</script>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
@@ -763,6 +761,5 @@ if (!doNotTrack) {
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
-
</body>
</html>