|
|
<!DOCTYPE html>
|
|
|
<html lang="zh-Hans">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
|
|
|
<meta name="theme-color" content="#222">
|
|
|
<meta name="generator" content="Hexo 4.2.0">
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
|
|
|
<link rel="mask-icon" href="/images/logo.svg" color="#222">
|
|
|
<meta name="google-site-verification" content="2X6S9P7CAjXjVvw8YyQR8pCu-B0oEu7O9quLgxXuWyA">
|
|
|
<meta name="baidu-site-verification" content="dV8JGNzi0c">
|
|
|
<meta name="chinaz-site-verification" content="500A176AA29CFB31">
|
|
|
|
|
|
<script data-ad-client="ca-pub-7480618470784058" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
|
|
|
|
|
<link rel="stylesheet" href="/css/main.css">
|
|
|
|
|
|
<link rel="stylesheet" href="//fonts.loli.net/css?family=Lato:300,300italic,400,400italic,700,700italic|M+ 2p:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
|
|
|
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
|
|
|
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
|
|
|
|
|
|
|
|
|
<script id="hexo-configurations">
|
|
|
var NexT = window.NexT || {};
|
|
|
var CONFIG = {
|
|
|
hostname: new URL('https://nicksxs.me').hostname,
|
|
|
root: '/',
|
|
|
scheme: 'Pisces',
|
|
|
version: '7.7.0',
|
|
|
exturl: false,
|
|
|
sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
|
|
|
copycode: {"enable":true,"show_result":false,"style":null},
|
|
|
back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
|
|
|
bookmark: {"enable":false,"color":"#222","save":"auto"},
|
|
|
fancybox: true,
|
|
|
mediumzoom: false,
|
|
|
lazyload: true,
|
|
|
pangu: false,
|
|
|
comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
|
|
|
algolia: {
|
|
|
appID: '',
|
|
|
apiKey: '',
|
|
|
indexName: '',
|
|
|
hits: {"per_page":10},
|
|
|
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
|
|
|
},
|
|
|
localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
|
|
|
path: '',
|
|
|
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<meta name="description" content="redis中对于 set 其实有两种处理,对于元素均为整型,并且元素数目较少时,使用 intset 作为底层数据结构,否则使用 dict 作为底层数据结构,先看一下代码先 1234567891011121314typedef struct intset &#123; // 编码方式 uint32_t encoding; // 集合包含的元素数量 uint32_t lengt">
|
|
|
<meta property="og:type" content="article">
|
|
|
<meta property="og:title" content="redis数据结构介绍三-第三部分 整数集合">
|
|
|
<meta property="og:url" content="https://nicksxs.me/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/index.html">
|
|
|
<meta property="og:site_name" content="Nicksxs's Blog">
|
|
|
<meta property="og:description" content="redis中对于 set 其实有两种处理,对于元素均为整型,并且元素数目较少时,使用 intset 作为底层数据结构,否则使用 dict 作为底层数据结构,先看一下代码先 1234567891011121314typedef struct intset &#123; // 编码方式 uint32_t encoding; // 集合包含的元素数量 uint32_t lengt">
|
|
|
<meta property="og:image" content="https://i.loli.net/2020/01/10/qIc6HgP7wfCLipN.png">
|
|
|
<meta property="article:published_time" content="2020-01-09T16:54:04.000Z">
|
|
|
<meta property="article:modified_time" content="2020-01-12T13:08:27.005Z">
|
|
|
<meta property="article:author" content="Nicksxs">
|
|
|
<meta property="article:tag" content="Redis">
|
|
|
<meta property="article:tag" content="C语言">
|
|
|
<meta property="article:tag" content="数据结构">
|
|
|
<meta property="article:tag" content="源码">
|
|
|
<meta property="article:tag" content="源码分析">
|
|
|
<meta property="article:tag" content="集合">
|
|
|
<meta property="article:tag" content="intset">
|
|
|
<meta name="twitter:card" content="summary">
|
|
|
<meta name="twitter:image" content="https://i.loli.net/2020/01/10/qIc6HgP7wfCLipN.png">
|
|
|
|
|
|
<link rel="canonical" href="https://nicksxs.me/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/">
|
|
|
|
|
|
|
|
|
<script id="page-configurations">
|
|
|
// https://hexo.io/docs/variables.html
|
|
|
CONFIG.page = {
|
|
|
sidebar: "",
|
|
|
isHome: false,
|
|
|
isPost: true
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<title>redis数据结构介绍三-第三部分 整数集合 | Nicksxs's Blog</title>
|
|
|
|
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-61358619-1"></script>
|
|
|
<script>
|
|
|
if (CONFIG.hostname === location.hostname) {
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
function gtag(){dataLayer.push(arguments);}
|
|
|
gtag('js', new Date());
|
|
|
gtag('config', 'UA-61358619-1');
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
|
|
|
<script>
|
|
|
var _hmt = _hmt || [];
|
|
|
(function() {
|
|
|
var hm = document.createElement("script");
|
|
|
hm.src = "https://hm.baidu.com/hm.js?20f33b3c0c0eff9b1522999c0015646d";
|
|
|
var s = document.getElementsByTagName("script")[0];
|
|
|
s.parentNode.insertBefore(hm, s);
|
|
|
})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<noscript>
|
|
|
<style>
|
|
|
.use-motion .brand,
|
|
|
.use-motion .menu-item,
|
|
|
.sidebar-inner,
|
|
|
.use-motion .post-block,
|
|
|
.use-motion .pagination,
|
|
|
.use-motion .comments,
|
|
|
.use-motion .post-header,
|
|
|
.use-motion .post-body,
|
|
|
.use-motion .collection-header { opacity: initial; }
|
|
|
|
|
|
.use-motion .site-title,
|
|
|
.use-motion .site-subtitle {
|
|
|
opacity: initial;
|
|
|
top: initial;
|
|
|
}
|
|
|
|
|
|
.use-motion .logo-line-before i { left: initial; }
|
|
|
.use-motion .logo-line-after i { right: initial; }
|
|
|
</style>
|
|
|
</noscript>
|
|
|
|
|
|
<link rel="alternate" href="/atom.xml" title="Nicksxs's Blog" type="application/atom+xml">
|
|
|
</head>
|
|
|
|
|
|
<body itemscope itemtype="http://schema.org/WebPage">
|
|
|
<div class="container use-motion">
|
|
|
<div class="headband"></div>
|
|
|
|
|
|
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
|
|
|
<div class="header-inner"><div class="site-brand-container">
|
|
|
<div class="site-meta">
|
|
|
|
|
|
<div>
|
|
|
<a href="/" class="brand" rel="start">
|
|
|
<span class="logo-line-before"><i></i></span>
|
|
|
<span class="site-title">Nicksxs's Blog</span>
|
|
|
<span class="logo-line-after"><i></i></span>
|
|
|
</a>
|
|
|
</div>
|
|
|
<p class="site-subtitle">What hurts more, the pain of hard work or the pain of regret?</p>
|
|
|
</div>
|
|
|
|
|
|
<div class="site-nav-toggle">
|
|
|
<div class="toggle" aria-label="Toggle navigation bar">
|
|
|
<span class="toggle-line toggle-line-first"></span>
|
|
|
<span class="toggle-line toggle-line-middle"></span>
|
|
|
<span class="toggle-line toggle-line-last"></span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<nav class="site-nav">
|
|
|
|
|
|
<ul id="menu" class="menu">
|
|
|
<li class="menu-item menu-item-home">
|
|
|
|
|
|
<a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-about">
|
|
|
|
|
|
<a href="/about/" rel="section"><i class="fa fa-fw fa-about"></i>About</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-tags">
|
|
|
|
|
|
<a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-categories">
|
|
|
|
|
|
<a href="/categories/" rel="section"><i class="fa fa-fw fa-categories"></i>Categories</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-archives">
|
|
|
|
|
|
<a href="/archives/" rel="section"><i class="fa fa-fw fa-archives"></i>Archives</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-sitemap">
|
|
|
|
|
|
<a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>Sitemap</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-commonweal">
|
|
|
|
|
|
<a href="/404/" rel="section"><i class="fa fa-fw fa-heartbeat"></i>Commonweal 404</a>
|
|
|
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
</nav>
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
<div class="back-to-top">
|
|
|
<i class="fa fa-arrow-up"></i>
|
|
|
<span>0%</span>
|
|
|
</div>
|
|
|
|
|
|
<a href="https://github.com/nicksxs" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>
|
|
|
|
|
|
|
|
|
<main class="main">
|
|
|
<div class="main-inner">
|
|
|
<div class="content-wrap">
|
|
|
|
|
|
|
|
|
<div class="content">
|
|
|
|
|
|
|
|
|
<div class="posts-expand">
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h1 class="post-title" itemprop="name headline">
|
|
|
redis数据结构介绍三-第三部分 整数集合
|
|
|
</h1>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2020-01-10 00:54:04" itemprop="dateCreated datePublished" datetime="2020-01-10T00:54:04+08:00">2020-01-10</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-calendar-check-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-folder-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/Redis/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">Redis</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
,
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/Redis/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">数据结构</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
,
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/C/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">C</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
,
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/Redis/%E6%BA%90%E7%A0%81/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">源码</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
,
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/C/Redis/" itemprop="url" rel="index">
|
|
|
<span itemprop="name">Redis</span>
|
|
|
</a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/" class="post-meta-item leancloud_visitors" data-flag-title="redis数据结构介绍三-第三部分 整数集合" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-comment-o"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/#comments" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/01/10/redis数据结构介绍三/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<p>redis中对于 set 其实有两种处理,对于元素均为整型,并且元素数目较少时,使用 intset 作为底层数据结构,否则使用 dict 作为底层数据结构,先看一下代码先</p>
|
|
|
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">intset</span> {</span></span><br><span class="line"> <span class="comment">// 编码方式</span></span><br><span class="line"> <span class="keyword">uint32_t</span> encoding;</span><br><span class="line"> <span class="comment">// 集合包含的元素数量</span></span><br><span class="line"> <span class="keyword">uint32_t</span> length;</span><br><span class="line"> <span class="comment">// 保存元素的数组</span></span><br><span class="line"> <span class="keyword">int8_t</span> contents[];</span><br><span class="line">} intset;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* Note that these encodings are ordered, so:</span></span><br><span class="line"><span class="comment"> * INTSET_ENC_INT16 < INTSET_ENC_INT32 < INTSET_ENC_INT64. */</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INTSET_ENC_INT16 (sizeof(int16_t))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INTSET_ENC_INT32 (sizeof(int32_t))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> INTSET_ENC_INT64 (sizeof(int64_t))</span></span><br></pre></td></tr></table></figure>
|
|
|
<p>一眼看,为啥整型还需要编码,然后 int8_t 怎么能存下大整形呢,带着这些疑问,我们一步步分析下去,这里的编码其实指的是这个整型集合里存的究竟是多大的整型,16 位,还是 32 位,还是 64 位,结构体下面的宏定义就是表示了 encoding 的可能取值,INTSET_ENC_INT16 表示每个元素用2个字节存储,INTSET_ENC_INT32 表示每个元素用4个字节存储,INTSET_ENC_INT64 表示每个元素用8个字节存储。因此,intset中存储的整数最多只能占用64bit。length 就是正常的表示集合中元素的数量。最奇怪的应该就是这个 contents 了,是个 int8_t 的数组,那放毛线数据啊,最小的都有 16 位,这里我在看代码和《redis 设计与实现》的时候也有点懵逼,后来查了下发现这是个比较取巧的用法,这里我用自己的理解表述一下,先看看 8,16,32,64 的关系,一眼看就知道都是 2 的 N 次,并且呈两倍关系,而且 8 位刚好一个字节,所以呢其实这里的contents 不是个常规意义上的 int8_t 类型的数组,而是个柔性数组。看下 wiki 的定义</p>
|
|
|
<blockquote>
|
|
|
<p>Flexible array members<a href="https://en.wikipedia.org/wiki/Flexible_array_member#cite_note-1" target="_blank" rel="noopener">1</a> were introduced in the <a href="https://en.wikipedia.org/wiki/C99" target="_blank" rel="noopener">C99</a> standard of the <a href="https://en.wikipedia.org/wiki/C_(programming_language)" target="_blank" rel="noopener">C programming language</a> (in particular, in section §6.7.2.1, item 16, page 103).<a href="https://en.wikipedia.org/wiki/Flexible_array_member#cite_note-2" target="_blank" rel="noopener">2</a> It is a member of a struct, which is an array without a given dimension. It must be the last member of such a struct and it must be accompanied by at least one other member, as in the following example:</p>
|
|
|
</blockquote>
|
|
|
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">vectord</span> {</span></span><br><span class="line"> <span class="keyword">size_t</span> len;</span><br><span class="line"> <span class="keyword">double</span> arr[]; <span class="comment">// the flexible array member must be last</span></span><br><span class="line">};</span><br></pre></td></tr></table></figure>
|
|
|
<p>在初始化这个 intset 的时候,这个contents数组是不占用空间的,后面的反正用到了申请,那么这里就有一个问题,给出了三种可能的 encoding 值,他们能随便换吗,显然不行,首先在 intset 中数据的存放是有序的,这个有部分原因是方便二分查找,然后存放数据其实随着数据的大小不同会有一个升级的过程,看下图<br><img data-src="https://i.loli.net/2020/01/10/qIc6HgP7wfCLipN.png" alt=""><br>新创建的intset只有一个header,总共8个字节。其中encoding = 2, length = 0, 类型都是uint32_t,各占 4 字节,添加15, 5两个元素之后,因为它们是比较小的整数,都能使用2个字节表示,所以encoding不变,值还是2,也就是默认的 <code>INTSET_ENC_INT16</code>,当添加32768的时候,它不再能用2个字节来表示了(2个字节能表达的数据范围是-215~215-1,而32768等于215,超出范围了),因此encoding必须升级到INTSET_ENC_INT32(值为4),即用4个字节表示一个元素。在添加每个元素的过程中,intset始终保持从小到大有序。与ziplist类似,intset也是按小端(little endian)模式存储的(参见维基百科词条<a href="https://en.wikipedia.org/wiki/Endianness" target="_blank" rel="noopener">Endianness</a>)。比如,在上图中intset添加完所有数据之后,表示encoding字段的4个字节应该解释成0x00000004,而第4个数据应该解释成0x00008000 = 32768</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="popular-posts-header">Related Posts</div>
|
|
|
<ul class="popular-posts">
|
|
|
<li class="popular-posts-item">
|
|
|
<div class="popular-posts-title"><a href="/2020/01/04/redis数据结构介绍二/" rel="bookmark">redis数据结构介绍二-第二部分 跳表</a></div>
|
|
|
</li>
|
|
|
<li class="popular-posts-item">
|
|
|
<div class="popular-posts-title"><a href="/2020/01/20/redis数据结构介绍五/" rel="bookmark">redis数据结构介绍五-第五部分 对象</a></div>
|
|
|
</li>
|
|
|
<li class="popular-posts-item">
|
|
|
<div class="popular-posts-title"><a href="/2020/01/19/redis数据结构介绍四/" rel="bookmark">redis数据结构介绍四-第四部分 压缩表</a></div>
|
|
|
</li>
|
|
|
<li class="popular-posts-item">
|
|
|
<div class="popular-posts-title"><a href="/2019/12/26/redis数据结构介绍/" rel="bookmark">redis数据结构介绍-第一部分 SDS,链表,字典</a></div>
|
|
|
</li>
|
|
|
<li class="popular-posts-item">
|
|
|
<div class="popular-posts-title"><a href="/2020/01/22/redis数据结构介绍六/" rel="bookmark">redis数据结构介绍六 快表</a></div>
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
<div class="reward-container">
|
|
|
<div>请我喝杯咖啡</div>
|
|
|
<button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
|
|
|
Donate
|
|
|
</button>
|
|
|
<div id="qr" style="display: none;">
|
|
|
|
|
|
<div style="display: inline-block;">
|
|
|
<img src="https://i.loli.net/2020/01/12/NUlWanT31E8LQGx.png" alt="Nicksxs WeChat Pay">
|
|
|
<p>WeChat Pay</p>
|
|
|
</div>
|
|
|
|
|
|
<div style="display: inline-block;">
|
|
|
<img src="https://ooo.0o0.ooo/2016/08/17/57b421e773057.jpg" alt="Nicksxs Alipay">
|
|
|
<p>Alipay</p>
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
<ul class="post-copyright">
|
|
|
<li class="post-copyright-author">
|
|
|
<strong>Post author: </strong>Nicksxs
|
|
|
</li>
|
|
|
<li class="post-copyright-link">
|
|
|
<strong>Post link: </strong>
|
|
|
<a href="https://nicksxs.me/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/" title="redis数据结构介绍三-第三部分 整数集合">https://nicksxs.me/2020/01/10/redis数据结构介绍三/</a>
|
|
|
</li>
|
|
|
<li class="post-copyright-license">
|
|
|
<strong>Copyright Notice: </strong>All articles in this blog are licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> unless stating additionally.
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-tags">
|
|
|
<a href="/tags/redis/" rel="tag"># redis</a>
|
|
|
<a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag"># 数据结构</a>
|
|
|
<a href="/tags/%E6%BA%90%E7%A0%81/" rel="tag"># 源码</a>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-nav">
|
|
|
<div class="post-nav-item">
|
|
|
<a href="/2020/01/04/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%BA%8C/" rel="prev" title="redis数据结构介绍二-第二部分 跳表">
|
|
|
<i class="fa fa-chevron-left"></i> redis数据结构介绍二-第二部分 跳表
|
|
|
</a></div>
|
|
|
<div class="post-nav-item">
|
|
|
<a href="/2020/01/19/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E5%9B%9B/" rel="next" title="redis数据结构介绍四-第四部分 压缩表">
|
|
|
redis数据结构介绍四-第四部分 压缩表 <i class="fa fa-chevron-right"></i>
|
|
|
</a></div>
|
|
|
</div>
|
|
|
</footer>
|
|
|
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="comments">
|
|
|
<div id="disqus_thread">
|
|
|
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<script>
|
|
|
window.addEventListener('tabs:register', () => {
|
|
|
let activeClass = CONFIG.comments.activeClass;
|
|
|
if (CONFIG.comments.storage) {
|
|
|
activeClass = localStorage.getItem('comments_active') || activeClass;
|
|
|
}
|
|
|
if (activeClass) {
|
|
|
let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
|
|
|
if (activeTab) {
|
|
|
activeTab.click();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
if (CONFIG.comments.storage) {
|
|
|
window.addEventListener('tabs:click', event => {
|
|
|
if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
|
|
|
let commentClass = event.target.classList[1];
|
|
|
localStorage.setItem('comments_active', commentClass);
|
|
|
});
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="toggle sidebar-toggle">
|
|
|
<span class="toggle-line toggle-line-first"></span>
|
|
|
<span class="toggle-line toggle-line-middle"></span>
|
|
|
<span class="toggle-line toggle-line-last"></span>
|
|
|
</div>
|
|
|
|
|
|
<aside class="sidebar">
|
|
|
<div class="sidebar-inner">
|
|
|
|
|
|
<ul class="sidebar-nav motion-element">
|
|
|
<li class="sidebar-nav-toc">
|
|
|
Table of Contents
|
|
|
</li>
|
|
|
<li class="sidebar-nav-overview">
|
|
|
Overview
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
<!--noindex-->
|
|
|
<div class="post-toc-wrap sidebar-panel">
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
<div class="site-overview-wrap sidebar-panel">
|
|
|
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<img class="site-author-image" itemprop="image" alt="Nicksxs"
|
|
|
src="/uploads/avatar.jpg">
|
|
|
<p class="site-author-name" itemprop="name">Nicksxs</p>
|
|
|
<div class="site-description" itemprop="description">learn from zero,技术博客,Nicksxs,史学森</div>
|
|
|
</div>
|
|
|
<div class="site-state-wrap motion-element">
|
|
|
<nav class="site-state">
|
|
|
<div class="site-state-item site-state-posts">
|
|
|
<a href="/archives/">
|
|
|
|
|
|
<span class="site-state-item-count">45</span>
|
|
|
<span class="site-state-item-name">posts</span>
|
|
|
</a>
|
|
|
</div>
|
|
|
<div class="site-state-item site-state-categories">
|
|
|
<a href="/categories/">
|
|
|
|
|
|
<span class="site-state-item-count">34</span>
|
|
|
<span class="site-state-item-name">categories</span></a>
|
|
|
</div>
|
|
|
<div class="site-state-item site-state-tags">
|
|
|
<a href="/tags/">
|
|
|
|
|
|
<span class="site-state-item-count">58</span>
|
|
|
<span class="site-state-item-name">tags</span></a>
|
|
|
</div>
|
|
|
</nav>
|
|
|
</div>
|
|
|
<div class="links-of-author motion-element">
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="https://github.com/nicksxs" title="GitHub → https://github.com/nicksxs" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
|
|
|
</span>
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="mailto:nicksxs1202@gmail.com" title="E-Mail → mailto:nicksxs1202@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
|
|
|
</span>
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="/atom.xml" title="RSS → /atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a>
|
|
|
</span>
|
|
|
</div>
|
|
|
<div class="cc-license motion-element" itemprop="license">
|
|
|
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
|
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
|
|
|
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
|
|
|
<div class="widget-wrap">
|
|
|
<div id="myCanvasContainer" class="widget tagcloud">
|
|
|
<canvas width="250" height="250" id="resCanvas" style="width=100%">
|
|
|
<ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/2019/" rel="tag">2019</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C++</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Comparator/" rel="tag">Comparator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Design-Patterns/" rel="tag">Design Patterns</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Distributed-Lock/" rel="tag">Distributed Lock</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Docker/" rel="tag">Docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dockerfile/" rel="tag">Dockerfile</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/G1/" rel="tag">G1</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/GC/" rel="tag">GC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Garbage-First-Collector/" rel="tag">Garbage-First Collector</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gogs/" rel="tag">Gogs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JVM/" rel="tag">JVM</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/" rel="tag">Java</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Maven/" rel="tag">Maven</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Redis/" rel="tag">Redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Singleton/" rel="tag">Singleton</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Stream/" rel="tag">Stream</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Webhook/" rel="tag">Webhook</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aqs/" rel="tag">aqs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/" rel="tag">c++</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cgroup/" rel="tag">cgroup</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cluster/" rel="tag">cluster</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/" rel="tag">docker</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/echo/" rel="tag">echo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/" rel="tag">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/im/" rel="tag">im</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/leetcode/" rel="tag">leetcode</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/" rel="tag">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mfc/" rel="tag">mfc</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/" rel="tag">mq</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/" rel="tag">mysql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/namespace/" rel="tag">namespace</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nullsfirst/" rel="tag">nullsfirst</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/openresty/" rel="tag">openresty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/" rel="tag">php</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sort/" rel="tag">sort</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spark/" rel="tag">spark</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/swoole/" rel="tag">swoole</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/uname/" rel="tag">uname</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/websocket/" rel="tag">websocket</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/" rel="tag">分布式锁</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%95%E4%BE%8B/" rel="tag">单例</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%EF%BC%8C%E6%96%87%E7%AB%A0/" rel="tag">博客,文章</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8F%91%E8%A1%8C%E7%89%88/" rel="tag">发行版</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%AF%84%E7%94%9F%E8%99%AB/" rel="tag">寄生虫</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B4%E7%BB%88%E6%80%BB%E7%BB%93/" rel="tag">年终总结</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BD%B1%E8%AF%84/" rel="tag">影评</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8E%92%E5%BA%8F/" rel="tag">排序</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag">数据结构</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">设计模式</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AF%BB%E5%90%8E%E6%84%9F/" rel="tag">读后感</a><span class="tag-list-count">1</span></li></ul>
|
|
|
</canvas>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="links-of-blogroll motion-element">
|
|
|
<div class="links-of-blogroll-title">
|
|
|
<i class="fa fa-fw fa-link"></i>
|
|
|
Links
|
|
|
</div>
|
|
|
<ul class="links-of-blogroll-list">
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://www.zipperary.com/" title="http://www.zipperary.com/" rel="noopener" target="_blank">Zippera's blog</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://x20a.xyz/" title="http://x20a.xyz/" rel="noopener" target="_blank">Freedom</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://samuel.group/" title="http://samuel.group/" rel="noopener" target="_blank">sfwtt</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://blog.leanote.com/buru" title="http://blog.leanote.com/buru" rel="noopener" target="_blank">bruce</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://m2shad0w.com/" title="http://m2shad0w.com/" rel="noopener" target="_blank">m2shad0w</a>
|
|
|
</li>
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="http://www.programcat.com/" title="http://www.programcat.com" rel="noopener" target="_blank">程序喵的厨房</a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
</aside>
|
|
|
<div id="sidebar-dimmer"></div>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</main>
|
|
|
|
|
|
<footer class="footer">
|
|
|
<div class="footer-inner">
|
|
|
|
|
|
|
|
|
<div class="copyright">
|
|
|
|
|
|
©
|
|
|
<span itemprop="copyrightYear">2020</span>
|
|
|
<span class="with-love">
|
|
|
<i class="fa fa-user"></i>
|
|
|
</span>
|
|
|
<span class="author" itemprop="copyrightHolder">Nicksxs</span>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
function leancloudSelector(url) {
|
|
|
url = encodeURI(url);
|
|
|
return document.getElementById(url).querySelector('.leancloud-visitors-count');
|
|
|
}
|
|
|
if (CONFIG.page.isPost) {
|
|
|
function addCount(Counter) {
|
|
|
var visitors = document.querySelector('.leancloud_visitors');
|
|
|
var url = decodeURI(visitors.getAttribute('id'));
|
|
|
var title = visitors.getAttribute('data-flag-title');
|
|
|
|
|
|
Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
|
|
|
.then(response => response.json())
|
|
|
.then(({ results }) => {
|
|
|
if (results.length > 0) {
|
|
|
var counter = results[0];
|
|
|
Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
|
|
|
.then(response => response.json())
|
|
|
.then(() => {
|
|
|
leancloudSelector(url).innerText = counter.time + 1;
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('Failed to save visitor count', error);
|
|
|
})
|
|
|
} else {
|
|
|
leancloudSelector(url).innerText = 'Counter not initialized! More info at console err msg.';
|
|
|
console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('LeanCloud Counter Error', error);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
function showTime(Counter) {
|
|
|
var visitors = document.querySelectorAll('.leancloud_visitors');
|
|
|
var entries = [...visitors].map(element => {
|
|
|
return decodeURI(element.getAttribute('id'));
|
|
|
});
|
|
|
|
|
|
Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
|
|
|
.then(response => response.json())
|
|
|
.then(({ results }) => {
|
|
|
if (results.length === 0) {
|
|
|
document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
|
|
|
element.innerText = 0;
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
for (let item of results) {
|
|
|
let { url, time } = item;
|
|
|
leancloudSelector(url).innerText = time;
|
|
|
}
|
|
|
for (let url of entries) {
|
|
|
var element = leancloudSelector(url);
|
|
|
if (element.innerText == '') {
|
|
|
element.innerText = 0;
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('LeanCloud Counter Error', error);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
fetch('https://app-router.leancloud.cn/2/route?appId=ysza182Vghlqjdt7QiwGLLJy-gzGzoHsz')
|
|
|
.then(response => response.json())
|
|
|
.then(({ api_server }) => {
|
|
|
var Counter = (method, url, data) => {
|
|
|
return fetch(`https://${api_server}/1.1${url}`, {
|
|
|
method: method,
|
|
|
headers: {
|
|
|
'X-LC-Id': 'ysza182Vghlqjdt7QiwGLLJy-gzGzoHsz',
|
|
|
'X-LC-Key': 's9GDqbn7gnGGkusf66YRVccw',
|
|
|
'Content-Type': 'application/json',
|
|
|
},
|
|
|
body: JSON.stringify(data)
|
|
|
});
|
|
|
};
|
|
|
if (CONFIG.page.isPost) {
|
|
|
if (CONFIG.hostname !== location.hostname) return;
|
|
|
addCount(Counter);
|
|
|
} else if (document.querySelectorAll('.post-title-link').length >= 1) {
|
|
|
showTime(Counter);
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</footer>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<script src="/lib/anime.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
|
|
|
<script src="/lib/velocity/velocity.min.js"></script>
|
|
|
<script src="/lib/velocity/velocity.ui.min.js"></script>
|
|
|
|
|
|
<script src="/js/utils.js"></script>
|
|
|
|
|
|
<script src="/js/motion.js"></script>
|
|
|
|
|
|
|
|
|
<script src="/js/schemes/pisces.js"></script>
|
|
|
|
|
|
|
|
|
<script src="/js/next-boot.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
(function(){
|
|
|
var bp = document.createElement('script');
|
|
|
var curProtocol = window.location.protocol.split(':')[0];
|
|
|
bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
|
|
|
var s = document.getElementsByTagName("script")[0];
|
|
|
s.parentNode.insertBefore(bp, s);
|
|
|
})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script src="//cdn.jsdelivr.net/npm/quicklink@1/dist/quicklink.umd.js"></script>
|
|
|
<script>
|
|
|
window.addEventListener('load', () => {
|
|
|
quicklink({
|
|
|
timeout: 3000,
|
|
|
priority: true,
|
|
|
ignores: [uri => uri.includes('#'),uri => uri == 'https://nicksxs.me/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/',]
|
|
|
});
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
|
function loadCount() {
|
|
|
var d = document, s = d.createElement('script');
|
|
|
s.src = 'https://nicksxs.disqus.com/count.js';
|
|
|
s.id = 'dsq-count-scr';
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
}
|
|
|
// defer loading until the whole page loading is completed
|
|
|
window.addEventListener('load', loadCount, false);
|
|
|
</script>
|
|
|
<script>
|
|
|
NexT.utils.loadComments(document.querySelector('#disqus_thread'), () => {
|
|
|
if (window.DISQUS) {
|
|
|
DISQUS.reset({
|
|
|
reload: true,
|
|
|
config: {page: {
|
|
|
url: "https://nicksxs.me/2020/01/10/redis%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BB%8B%E7%BB%8D%E4%B8%89/",
|
|
|
identifier: "2020/01/10/redis数据结构介绍三/",
|
|
|
title: "redis数据结构介绍三-第三部分 整数集合"
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
var d = document, s = d.createElement('script');
|
|
|
s.src = 'https://nicksxs.disqus.com/embed.js';
|
|
|
s.setAttribute('data-timestamp', '' + +new Date());
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
</html>
|