forked from huangzworks/redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpush.html
176 lines (146 loc) · 7.31 KB
/
lpush.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LPUSH — Redis 命令参考</title>
<link rel="stylesheet" href="../_static/pyramid.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.8',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Redis 命令参考" href="../index.html" />
<link rel="up" title="List(列表)" href="index.html" />
<link rel="next" title="LPUSHX" href="lpushx.html" />
<link rel="prev" title="LPOP" href="lpop.html" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="../_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="lpushx.html" title="LPUSHX"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="lpop.html" title="LPOP"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">Redis 命令参考</a> »</li>
<li><a href="index.html" accesskey="U">List(列表)</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="lpush">
<span id="id1"></span><h1>LPUSH<a class="headerlink" href="#lpush" title="Permalink to this headline">¶</a></h1>
<p><strong>LPUSH key value [value ...]</strong></p>
<p>将一个或多个值 <code class="docutils literal"><span class="pre">value</span></code> 插入到列表 <code class="docutils literal"><span class="pre">key</span></code> 的表头</p>
<p>如果有多个 <code class="docutils literal"><span class="pre">value</span></code> 值,那么各个 <code class="docutils literal"><span class="pre">value</span></code> 值按从左到右的顺序依次插入到表头:
比如说,对空列表 <code class="docutils literal"><span class="pre">mylist</span></code> 执行命令 <code class="docutils literal"><span class="pre">LPUSH</span> <span class="pre">mylist</span> <span class="pre">a</span> <span class="pre">b</span> <span class="pre">c</span></code> ,列表的值将是 <code class="docutils literal"><span class="pre">c</span> <span class="pre">b</span> <span class="pre">a</span></code> ,这等同于原子性地执行 <code class="docutils literal"><span class="pre">LPUSH</span> <span class="pre">mylist</span> <span class="pre">a</span></code> 、 <code class="docutils literal"><span class="pre">LPUSH</span> <span class="pre">mylist</span> <span class="pre">b</span></code> 和 <code class="docutils literal"><span class="pre">LPUSH</span> <span class="pre">mylist</span> <span class="pre">c</span></code> 三个命令。</p>
<p>如果 <code class="docutils literal"><span class="pre">key</span></code> 不存在,一个空列表会被创建并执行 <a class="reference internal" href="#lpush">LPUSH</a> 操作。</p>
<p>当 <code class="docutils literal"><span class="pre">key</span></code> 存在但不是列表类型时,返回一个错误。</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">在Redis 2.4版本以前的 <a class="reference internal" href="#lpush">LPUSH</a> 命令,都只接受单个 <code class="docutils literal"><span class="pre">value</span></code> 值。</p>
</div>
<dl class="docutils">
<dt><strong>可用版本:</strong></dt>
<dd>>= 1.0.0</dd>
<dt><strong>时间复杂度:</strong></dt>
<dd>O(1)</dd>
<dt><strong>返回值:</strong></dt>
<dd>执行 <a class="reference internal" href="#lpush">LPUSH</a> 命令后,列表的长度。</dd>
</dl>
<div class="highlight-python"><div class="highlight"><pre># 加入单个元素
redis> LPUSH languages python
(integer) 1
# 加入重复元素
redis> LPUSH languages python
(integer) 2
redis> LRANGE languages 0 -1 # 列表允许重复元素
1) "python"
2) "python"
# 加入多个元素
redis> LPUSH mylist a b c
(integer) 3
redis> LRANGE mylist 0 -1
1) "c"
2) "b"
3) "a"
</pre></div>
</div>
</div>
<div class="section" id="discuss">
<h2>
讨论
<a class="headerlink" href="#discuss" title="永久链接至标题">¶</a>
</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'redis-command-cn'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<div id="sponser">
<h2>赞助商</h2>
<p>我们正在寻找赞助商,有意对这个网站进行赞助的朋友请联系 [email protected] 。</p>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="lpushx.html" title="LPUSHX"
>next</a> |</li>
<li class="right" >
<a href="lpop.html" title="LPOP"
>previous</a> |</li>
<li><a href="../index.html">Redis 命令参考</a> »</li>
<li><a href="index.html" >List(列表)</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2015, Redis.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-53959484-7', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>