Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 3313 lines (2624 sloc) 94.252 kB
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
1 # PhpRedis
2569a02 @titpetric more testing, trying to set id on heading
titpetric authored
2
120ffee @nicolasff Making sure licensing is clear.
nicolasff authored
3 The phpredis extension provides an API for communicating with the [Redis](http://redis.io/) key-value store. It is released under the [PHP License, version 3.01](http://www.php.net/license/3_01.txt).
9c8e501 @nicolasff Reverted changes due to merge.
nicolasff authored
4 This code has been developed and maintained by Owlient from November 2009 to March 2011.
5
77afbe3 @michael-grunder Implement WAIT command
michael-grunder authored
6 You can send comments, patches, questions [here on github](https://github.com/nicolasff/phpredis/issues), to n.favrefelix@gmail.com ([@yowgi](http://twitter.com/yowgi)), or to michael.grunder@gmail.com ([@grumi78](http://twitter.com/grumi78)).
9c8e501 @nicolasff Reverted changes due to merge.
nicolasff authored
7
6f9533f Changed the README.
Nicolas Favre-Felix authored
8
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
9 # Table of contents
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
10 -----
2569a02 @titpetric more testing, trying to set id on heading
titpetric authored
11 1. [Installing/Configuring](#installingconfiguring)
12 * [Installation](#installation)
13 * [Installation on OSX](#installation-on-osx)
df060ca @nicolasff Link to instructions on how to build on Windows
nicolasff authored
14 * [Building on Windows](#building-on-windows)
2569a02 @titpetric more testing, trying to set id on heading
titpetric authored
15 * [PHP Session handler](#php-session-handler)
16 * [Distributed Redis Array](#distributed-redis-array)
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
17 1. [Classes and methods](#classes-and-methods)
18 * [Usage](#usage)
75434ae @titpetric bold/italics, whitespace
titpetric authored
19 * [Connection](#connection)
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
20 * [Server](#server)
968d3fd @titpetric link keys and strings
titpetric authored
21 * [Keys and strings](#keys-and-strings)
328f599 @titpetric moved hash methods under heading, created toc
titpetric authored
22 * [Hashes](#hashes)
23 * [Lists](#lists)
24 * [Sets](#sets)
3d055f8 @titpetric alphabetized sorted set methods, created toc
titpetric authored
25 * [Sorted sets](#sorted-sets)
0cf7c88 @titpetric transactions, pub/sub sections, toc
titpetric authored
26 * [Pub/sub](#pubsub)
27 * [Transactions](#transactions)
328f599 @titpetric moved hash methods under heading, created toc
titpetric authored
28 * [Scripting](#scripting)
ef79232 @michael-grunder Introspection methods
michael-grunder authored
29 * [Introspection](#introspection)
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
30
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
31 -----
fc22409 @titpetric Renamed session handler title, added a template TOC to test
titpetric authored
32
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
33 # Installing/Configuring
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
34 -----
6f9533f Changed the README.
Nicolas Favre-Felix authored
35
3d055f8 @titpetric alphabetized sorted set methods, created toc
titpetric authored
36 Everything you should need to install PhpRedis on your system.
1dbf003 @titpetric more TOC indent tests, renamed some headings
titpetric authored
37
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
38 ## Installation
39
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
40 ~~~
6f9533f Changed the README.
Nicolas Favre-Felix authored
41 phpize
3e9f43b @nicolasff Document --enable-redis-igbinary configure flag
nicolasff authored
42 ./configure [--enable-redis-igbinary]
6f9533f Changed the README.
Nicolas Favre-Felix authored
43 make && make install
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
44 ~~~
8c8ad76 markdown
Nicolas Favre-Felix authored
45
3e9f43b @nicolasff Document --enable-redis-igbinary configure flag
nicolasff authored
46 If you would like phpredis to serialize your data using the igbinary library, run configure with `--enable-redis-igbinary`.
cf534ab @nicolasff Updated doc with ini setup.
nicolasff authored
47 `make install` copies `redis.so` to an appropriate location, but you still need to enable the module in the PHP config file. To do so, either edit your php.ini or add a redis.ini file in `/etc/php5/conf.d` with the following contents: `extension=redis.so`.
48
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
49 You can generate a debian package for PHP5, accessible from Apache 2 by running `./mkdeb-apache2.sh` or with `dpkg-buildpackage` or `svn-buildpackage`.
6f9533f Changed the README.
Nicolas Favre-Felix authored
50
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
51 This extension exports a single class, [Redis](#class-redis) (and [RedisException](#class-redisexception) used in case of errors). Check out https://github.com/ukko/phpredis-phpdoc for a PHP stub that you can use in your IDE for code completion.
6f9533f Changed the README.
Nicolas Favre-Felix authored
52
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
53
54 ## Installation on OSX
ead9e60 @nicolasff Added OSX fix by @jiminoc
nicolasff authored
55
56 If the install fails on OSX, type the following commands in your shell before trying again:
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
57 ~~~
ead9e60 @nicolasff Added OSX fix by @jiminoc
nicolasff authored
58 MACOSX_DEPLOYMENT_TARGET=10.6
59 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
60 CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
61 CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
62 LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
63 export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
64 ~~~
ead9e60 @nicolasff Added OSX fix by @jiminoc
nicolasff authored
65
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
66 If that still fails and you are running Zend Server CE, try this right before "make": `./configure CFLAGS="-arch i386"`.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
67
e514147 @joedevon Added instruction in case of fail on Zend Server CE
joedevon authored
68 Taken from [Compiling phpredis on Zend Server CE/OSX ](http://www.tumblr.com/tagged/phpredis).
69
b0d65a4 @nicolasff Added link to Macports article.
nicolasff authored
70 See also: [Install Redis & PHP Extension PHPRedis with Macports](http://www.lecloud.net/post/3378834922/install-redis-php-extension-phpredis-with-macports).
71
8732d89 @mathiasverraes added homebrew installation instructions
mathiasverraes authored
72 You can install install it using Homebrew:
73
74 - [Get homebrew-php](https://github.com/josegonzalez/homebrew-php)
75 - `brew install php55-redis` (or php53-redis, php54-redis)
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
76
77 ## PHP Session handler
4963a9a @nicolasff New feature: PHP session handler.
nicolasff authored
78
79 phpredis can be used to store PHP sessions. To do this, configure `session.save_handler` and `session.save_path` in your php.ini to tell phpredis where to store the sessions:
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
80 ~~~
4963a9a @nicolasff New feature: PHP session handler.
nicolasff authored
81 session.save_handler = redis
a91e9db @nicolasff Added more session documentation.
nicolasff authored
82 session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
83 ~~~
4963a9a @nicolasff New feature: PHP session handler.
nicolasff authored
84
a91e9db @nicolasff Added more session documentation.
nicolasff authored
85 `session.save_path` can have a simple `host:port` format too, but you need to provide the `tcp://` scheme if you want to use the parameters. The following parameters are available:
86
87 * weight (integer): the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, *host1* stores 20% of all the sessions (1/(1+2+2)) while *host2* and *host3* each store 40% (2/1+2+2). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1.
88 * timeout (float): the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high (86400 seconds).
75775bf @nicolasff Add persistence in session handler.
nicolasff authored
89 * persistent (integer, should be 1 or 0): defines if a persistent connection should be used. **(experimental setting)**
5a07edc @nicolasff Custom session prefix.
nicolasff authored
90 * prefix (string, defaults to "PHPREDIS_SESSION:"): used as a prefix to the Redis key in which the session is stored. The key is composed of the prefix followed by the session ID.
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
91 * auth (string, empty by default): used to authenticate with the server prior to sending commands.
e8c3b13 @nicolasff Add 'database' parameter to Redis sessions
nicolasff authored
92 * database (integer): selects a different database.
a91e9db @nicolasff Added more session documentation.
nicolasff authored
93
94 Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with [`ini_set()`](http://php.net/ini_set).
84a33ef @nicolasff Added Redis requirements for session handler.
nicolasff authored
95 The session handler requires a version of Redis with the `SETEX` command (at least 2.0).
507ba7c Document unix sockets with the session handler
Nicolas authored
96 phpredis can also connect to a unix domain socket: `session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0`.
4963a9a @nicolasff New feature: PHP session handler.
nicolasff authored
97
5a6a1d3 @nicolasff Small documentation changes
nicolasff authored
98
df060ca @nicolasff Link to instructions on how to build on Windows
nicolasff authored
99 ## Building on Windows
100
101 See [instructions from @char101](https://github.com/nicolasff/phpredis/issues/213#issuecomment-11361242) on how to build phpredis on Windows.
102
103
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
104 ## Distributed Redis Array
5a6a1d3 @nicolasff Small documentation changes
nicolasff authored
105
106 See [dedicated page](https://github.com/nicolasff/phpredis/blob/master/arrays.markdown#readme).
107
108
ead9e60 @nicolasff Added OSX fix by @jiminoc
nicolasff authored
109
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
110 # Classes and methods
111 -----
b44fa17 @titpetric consistent heading markdown, test description header
titpetric authored
112
63cad63 @titpetric Started expanding general docs
titpetric authored
113 ## Usage
3219d30 documentation initialization
Nasreddine Bouafif authored
114
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
115 1. [Class Redis](#class-redis)
116 1. [Class RedisException](#class-redisexception)
117 1. [Predefined constants](#predefined-constants)
118
119 ### Class Redis
faeacde @titpetric test hr insert
titpetric authored
120 -----
b3b55e0 @titpetric removed duplicate description marker
titpetric authored
121 _**Description**_: Creates a Redis client
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
122
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
123 ##### *Example*
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
124
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
125 ~~~
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
126 $redis = new Redis();
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
127 ~~~
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
128
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
129 ### Class RedisException
c73c2ee @titpetric usage lists classes, subtoc for section connection
titpetric authored
130 -----
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
131 phpredis throws a [RedisException](#class-redisexception) object if it can't reach the Redis server. That can happen in case of connectivity issues,
63cad63 @titpetric Started expanding general docs
titpetric authored
132 if the Redis service is down, or if the redis host is overloaded. In any other problematic case that does not involve an
133 unreachable server (such as a key not existing, an invalid command, etc), phpredis will return `FALSE`.
134
135 ### Predefined constants
c73c2ee @titpetric usage lists classes, subtoc for section connection
titpetric authored
136 -----
63cad63 @titpetric Started expanding general docs
titpetric authored
137 _**Description**_: Available Redis Constants
138
139 Redis data types, as returned by [type](#type)
140 ~~~
141 Redis::REDIS_STRING - String
142 Redis::REDIS_SET - Set
143 Redis::REDIS_LIST - List
144 Redis::REDIS_ZSET - Sorted set
145 Redis::REDIS_HASH - Hash
146 Redis::REDIS_NOT_FOUND - Not found / other
147 ~~~
148
149 @TODO: OPT_SERIALIZER, AFTER, BEFORE,...
150
75434ae @titpetric bold/italics, whitespace
titpetric authored
151 ## Connection
152
42c3a57 @titpetric moved auth and select methods under connection heading, updated TOC w…
titpetric authored
153 1. [connect, open](#connect-open) - Connect to a server
154 1. [pconnect, popen](#pconnect-popen) - Connect to a server (persistent)
155 1. [auth](#auth) - Authenticate to the server
156 1. [select](#select) - Change the selected database for the current connection
157 1. [close](#close) - Close the connection
158 1. [setOption](#setoption) - Set client option
159 1. [getOption](#getoption) - Get client option
160 1. [ping](#ping) - Ping the server
161 1. [echo](#echo) - Echo the given string
c73c2ee @titpetric usage lists classes, subtoc for section connection
titpetric authored
162
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
163 ### connect, open
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
164 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
165 _**Description**_: Connects to a Redis instance.
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
166
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
167 ##### *Parameters*
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
168
44f048c @nicolasff Added support for UNIX Domain Sockets.
nicolasff authored
169 *host*: string. can be a host, or the path to a unix domain socket
170 *port*: int, optional
25eb12f @nicolasff Added floating-point timeout for better precision.
nicolasff authored
171 *timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
acd3245 @mobli Added lazy_connect option to RedisArray
mobli authored
172 *reserved*: should be NULL if retry_interval is specified
173 *retry_interval*: int, value in milliseconds (optional)
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
174
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
175 ##### *Return value*
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
176
177 *BOOL*: `TRUE` on success, `FALSE` on error.
178
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
179 ##### *Example*
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
180
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
181 ~~~
03979e2 Documentation fixes thanks to github user "Klinky":
Nicolas Favre-Felix authored
182 $redis->connect('127.0.0.1', 6379);
44f048c @nicolasff Added support for UNIX Domain Sockets.
nicolasff authored
183 $redis->connect('127.0.0.1'); // port 6379 by default
25eb12f @nicolasff Added floating-point timeout for better precision.
nicolasff authored
184 $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout.
44f048c @nicolasff Added support for UNIX Domain Sockets.
nicolasff authored
185 $redis->connect('/tmp/redis.sock'); // unix domain socket.
acd3245 @mobli Added lazy_connect option to RedisArray
mobli authored
186 $redis->connect('127.0.0.1', 6379, 1, NULL, 100); // 1 sec timeout, 100ms delay between reconnection attempts.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
187 ~~~
90effcb Documentation format
Nasreddine Bouafif authored
188
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
189 ### pconnect, popen
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
190 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
191 _**Description**_: Connects to a Redis instance or reuse a connection already established with `pconnect`/`popen`.
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
192
193 The connection will not be closed on `close` or end of request until the php process ends.
194 So be patient on to many open FD's (specially on redis server side) when using persistent
8d9cf21 @Savar fix markup text
Savar authored
195 connections on many servers connecting to one redis server.
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
196
197 Also more than one persistent connection can be made identified by either host + port + timeout
0aa69e7 @Zakay Updated readme with new persistent_id information on pconnect
Zakay authored
198 or host + persistent_id or unix socket + timeout.
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
199
200 This feature is not available in threaded versions. `pconnect` and `popen` then working like their non
201 persistent equivalents.
202
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
203 ##### *Parameters*
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
204
205 *host*: string. can be a host, or the path to a unix domain socket
206 *port*: int, optional
207 *timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
0aa69e7 @Zakay Updated readme with new persistent_id information on pconnect
Zakay authored
208 *persistent_id*: string. identity for the requested persistent connection
acd3245 @mobli Added lazy_connect option to RedisArray
mobli authored
209 *retry_interval*: int, value in milliseconds (optional)
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
210
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
211 ##### *Return value*
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
212
213 *BOOL*: `TRUE` on success, `FALSE` on error.
214
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
215 ##### *Example*
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
216
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
217 ~~~
bb1bfd2 @Savar fix some missing threaded parameters and added README info
Savar authored
218 $redis->pconnect('127.0.0.1', 6379);
8d9cf21 @Savar fix markup text
Savar authored
219 $redis->pconnect('127.0.0.1'); // port 6379 by default - same connection like before.
0aa69e7 @Zakay Updated readme with new persistent_id information on pconnect
Zakay authored
220 $redis->pconnect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout and would be another connection than the two before.
221 $redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection the the three before.
222 $redis->pconnect('/tmp/redis.sock'); // unix domain socket - would be another connection than the four before.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
223 ~~~
90effcb Documentation format
Nasreddine Bouafif authored
224
42c3a57 @titpetric moved auth and select methods under connection heading, updated TOC w…
titpetric authored
225 ### auth
226 -----
227 _**Description**_: Authenticate the connection using a password.
228 *Warning*: The password is sent in plain-text over the network.
229
230 ##### *Parameters*
231 *STRING*: password
232
233 ##### *Return value*
234 *BOOL*: `TRUE` if the connection is authenticated, `FALSE` otherwise.
235
236 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
237 ~~~
42c3a57 @titpetric moved auth and select methods under connection heading, updated TOC w…
titpetric authored
238 $redis->auth('foobared');
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
239 ~~~
42c3a57 @titpetric moved auth and select methods under connection heading, updated TOC w…
titpetric authored
240
241 ### select
242 -----
243 _**Description**_: Change the selected database for the current connection.
244
245 ##### *Parameters*
246 *INTEGER*: dbindex, the database number to switch to.
247
248 ##### *Return value*
249 `TRUE` in case of success, `FALSE` in case of failure.
250 ##### *Example*
251 See method for example: [move](#move)
252
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
253 ### close
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
254 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
255 _**Description**_: Disconnects from the Redis instance, except when `pconnect` is used.
6013b13 @nicolasff Added serialization doc.
nicolasff authored
256
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
257 ### setOption
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
258 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
259 _**Description**_: Set client option.
6013b13 @nicolasff Added serialization doc.
nicolasff authored
260
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
261 ##### *Parameters*
6013b13 @nicolasff Added serialization doc.
nicolasff authored
262 *parameter name*
263 *parameter value*
264
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
265 ##### *Return value*
6013b13 @nicolasff Added serialization doc.
nicolasff authored
266 *BOOL*: `TRUE` on success, `FALSE` on error.
267
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
268 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
269 ~~~
6013b13 @nicolasff Added serialization doc.
nicolasff authored
270 $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data
271 $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize
272 $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize
de57b9c @nicolasff Prefix fixes.
nicolasff authored
273
274 $redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys
ab55389 @michael-grunder SCAN and variants
michael-grunder authored
275
276 /* Options for the SCAN family of commands, indicating whether to abstract
277 empty results from the user. If set to SCAN_NORETRY (the default), phpredis
278 will just issue one SCAN command at a time, sometimes returning an empty
279 array of results. If set to SCAN_RETRY, phpredis will retry the scan command
280 until keys come back OR Redis returns an iterator of zero
281 */
282 $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
283 $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
284 ~~~
6013b13 @nicolasff Added serialization doc.
nicolasff authored
285
286
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
287 ### getOption
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
288 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
289 _**Description**_: Get client option.
6013b13 @nicolasff Added serialization doc.
nicolasff authored
290
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
291 ##### *Parameters*
6013b13 @nicolasff Added serialization doc.
nicolasff authored
292 *parameter name*
293
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
294 ##### *Return value*
6013b13 @nicolasff Added serialization doc.
nicolasff authored
295 Parameter value.
296
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
297 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
298 ~~~
6013b13 @nicolasff Added serialization doc.
nicolasff authored
299 $redis->getOption(Redis::OPT_SERIALIZER); // return Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP, or Redis::SERIALIZER_IGBINARY.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
300 ~~~
6013b13 @nicolasff Added serialization doc.
nicolasff authored
301
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
302 ### ping
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
303 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
304 _**Description**_: Check the current connection status
71f4de5 @nicolasff Added missing description of PING command.
nicolasff authored
305
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
306 ##### *Parameters*
71f4de5 @nicolasff Added missing description of PING command.
nicolasff authored
307
308 (none)
309
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
310 ##### *Return value*
71f4de5 @nicolasff Added missing description of PING command.
nicolasff authored
311
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
312 *STRING*: `+PONG` on success. Throws a [RedisException](#class-redisexception) object on connectivity error, as described above.
71f4de5 @nicolasff Added missing description of PING command.
nicolasff authored
313
314
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
315 ### echo
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
316 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
317 _**Description**_: Sends a string to Redis, which replies with the same string
c265627 @nicolasff Add missing documentation for ECHO.
nicolasff authored
318
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
319 ##### *Parameters*
c265627 @nicolasff Add missing documentation for ECHO.
nicolasff authored
320
321 *STRING*: The message to send.
322
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
323 ##### *Return value*
c265627 @nicolasff Add missing documentation for ECHO.
nicolasff authored
324
325 *STRING*: the same message.
326
327
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
328 ## Server
329
3372eb9 @titpetric server TOC and methods related to that
titpetric authored
330 1. [bgrewriteaof](#bgrewriteaof) - Asynchronously rewrite the append-only file
331 1. [bgsave](#bgsave) - Asynchronously save the dataset to disk (in background)
332 1. [config](#config) - Get or Set the Redis server configuration parameters
333 1. [dbSize](#dbsize) - Return the number of keys in selected database
334 1. [flushAll](#flushall) - Remove all keys from all databases
335 1. [flushDB](#flushdb) - Remove all keys from the current database
336 1. [info](#info) - Get information and statistics about the server
337 1. [lastSave](#lastsave) - Get the timestamp of the last disk save
338 1. [resetStat](#resetstat) - Reset the stats returned by [info](#info) method.
339 1. [save](#save) - Synchronously save the dataset to disk (wait to complete)
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
340 1. [slaveof](#slaveof) - Make the server a slave of another instance, or promote it to master
341 1. [time](#time) - Return the current server time
7207aae @michael-grunder Add SLOWLOG command
michael-grunder authored
342 1. [slowlog](#slowlog) - Access the Redis slowlog entries
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
343
3372eb9 @titpetric server TOC and methods related to that
titpetric authored
344 ### bgrewriteaof
345 -----
346 _**Description**_: Start the background rewrite of AOF (Append-Only File)
347
348 ##### *Parameters*
349 None.
350
351 ##### *Return value*
352 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
353
354 ##### *Example*
355 ~~~
356 $redis->bgrewriteaof();
357 ~~~
358
359 ### bgsave
360 -----
361 _**Description**_: Asynchronously save the dataset to disk (in background)
362
363 ##### *Parameters*
364 None.
365
366 ##### *Return value*
367 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure. If a save is already running, this command will fail and return `FALSE`.
368
369 ##### *Example*
370 ~~~
371 $redis->bgSave();
372 ~~~
373
374 ### config
375 -----
376 _**Description**_: Get or Set the Redis server configuration parameters.
377
378 ##### *Parameters*
379 *operation* (string) either `GET` or `SET`
380 *key* string for `SET`, glob-pattern for `GET`. See http://redis.io/commands/config-get for examples.
381 *value* optional string (only for `SET`)
382
383 ##### *Return value*
384 *Associative array* for `GET`, key -> value
385 *bool* for `SET`
386
387 ##### *Examples*
388 ~~~
389 $redis->config("GET", "*max-*-entries*");
390 $redis->config("SET", "dir", "/var/run/redis/dumps/");
391 ~~~
392
393 ### dbSize
394 -----
395 _**Description**_: Return the number of keys in selected database.
396
397 ##### *Parameters*
398 None.
399
400 ##### *Return value*
401 *INTEGER*: DB size, in number of keys.
402
403 ##### *Example*
404 ~~~
405 $count = $redis->dbSize();
406 echo "Redis has $count keys\n";
407 ~~~
408
409 ### flushAll
410 -----
411 _**Description**_: Remove all keys from all databases.
412
413 ##### *Parameters*
414 None.
415
416 ##### *Return value*
417 *BOOL*: Always `TRUE`.
418
419 ##### *Example*
420 ~~~
421 $redis->flushAll();
422 ~~~
423
424 ### flushDB
425 -----
426 _**Description**_: Remove all keys from the current database.
427
428 ##### *Parameters*
429 None.
430
431 ##### *Return value*
432 *BOOL*: Always `TRUE`.
433
434 ##### *Example*
435 ~~~
436 $redis->flushDB();
437 ~~~
438
439 ### info
440 -----
441 _**Description**_: Get information and statistics about the server
442
443 Returns an associative array that provides information about the server. Passing no arguments to
444 INFO will call the standard REDIS INFO command, which returns information such as the following:
445
446 * redis_version
447 * arch_bits
448 * uptime_in_seconds
449 * uptime_in_days
450 * connected_clients
451 * connected_slaves
452 * used_memory
453 * changes_since_last_save
454 * bgsave_in_progress
455 * last_save_time
456 * total_connections_received
457 * total_commands_processed
458 * role
459
460 You can pass a variety of options to INFO ([per the Redis documentation](http://redis.io/commands/info)),
461 which will modify what is returned.
462
463 ##### *Parameters*
464 *option*: The option to provide redis (e.g. "COMMANDSTATS", "CPU")
465
466 ##### *Example*
467 ~~~
468 $redis->info(); /* standard redis INFO command */
469 $redis->info("COMMANDSTATS"); /* Information on the commands that have been run (>=2.6 only)
470 $redis->info("CPU"); /* just CPU information from Redis INFO */
471 ~~~
472
473 ### lastSave
474 -----
475 _**Description**_: Returns the timestamp of the last disk save.
476
477 ##### *Parameters*
478 None.
479
480 ##### *Return value*
481 *INT*: timestamp.
482
483 ##### *Example*
484 ~~~
485 $redis->lastSave();
486 ~~~
487
488 ### resetStat
489 -----
490 _**Description**_: Reset the stats returned by [info](#info) method.
491
492 These are the counters that are reset:
493
494 * Keyspace hits
495 * Keyspace misses
496 * Number of commands processed
497 * Number of connections received
498 * Number of expired keys
499
500
501 ##### *Parameters*
502 None.
503
504 ##### *Return value*
505 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
506
507 ##### *Example*
508 ~~~
509 $redis->resetStat();
510 ~~~
511
512 ### save
513 -----
514 _**Description**_: Synchronously save the dataset to disk (wait to complete)
515
516 ##### *Parameters*
517 None.
518
519 ##### *Return value*
520 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure. If a save is already running, this command will fail and return `FALSE`.
521
522 ##### *Example*
523 ~~~
524 $redis->save();
525 ~~~
526
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
527 ### slaveof
528 -----
529 _**Description**_: Changes the slave status
530
531 ##### *Parameters*
532 Either host (string) and port (int), or no parameter to stop being a slave.
533
534 ##### *Return value*
535 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
536
537 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
538 ~~~
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
539 $redis->slaveof('10.0.1.7', 6379);
540 /* ... */
541 $redis->slaveof();
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
542 ~~~
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
543
544 ### time
545 -----
546 _**Description**_: Return the current server time.
3372eb9 @titpetric server TOC and methods related to that
titpetric authored
547
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
548 ##### *Parameters*
549 (none)
3372eb9 @titpetric server TOC and methods related to that
titpetric authored
550
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
551 ##### *Return value*
552 If successfull, the time will come back as an associative array with element zero being
553 the unix timestamp, and element one being microseconds.
3372eb9 @titpetric server TOC and methods related to that
titpetric authored
554
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
555 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
556 ~~~
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
557 $redis->time();
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
558 ~~~
dc6d4dd @titpetric testing, moved time and slaveof under server section, replace html co…
titpetric authored
559
7207aae @michael-grunder Add SLOWLOG command
michael-grunder authored
560 ### slowlog
561 -----
562 _**Description**_: Access the Redis slowlog
563
564 ##### *Parameters*
565 *Operation* (string): This can be either `GET`, `LEN`, or `RESET`
566 *Length* (integer), optional: If executing a `SLOWLOG GET` command, you can pass an optional length.
567 #####
568
569 ##### *Return value*
570 The return value of SLOWLOG will depend on which operation was performed.
571 SLOWLOG GET: Array of slowlog entries, as provided by Redis
572 SLOGLOG LEN: Integer, the length of the slowlog
573 SLOWLOG RESET: Boolean, depending on success
574 #####
575
576 ##### *Examples*
577 ~~~
578 // Get ten slowlog entries
579 $redis->slowlog('get', 10);
580 // Get the default number of slowlog entries
581
582 $redis->slowlog('get');
583 // Reset our slowlog
584 $redis->slowlog('reset');
585
586 // Retrieve slowlog length
587 $redis->slowlog('len');
588 ~~~
589
3372eb9 @titpetric server TOC and methods related to that
titpetric authored
590 ## Keys and Strings
c73c2ee @titpetric usage lists classes, subtoc for section connection
titpetric authored
591
dce8a70 @titpetric Keys and strings toc import
titpetric authored
592 ### Strings
593 -----
594
595 * [append](#append) - Append a value to a key
596 * [bitcount](#bitcount) - Count set bits in a string
597 * [bitop](#bitop) - Perform bitwise operations between strings
598 * [decr, decrBy](#decr-decrby) - Decrement the value of a key
599 * [get](#get) - Get the value of a key
600 * [getBit](#getbit) - Returns the bit value at offset in the string value stored at key
601 * [getRange](#getrange) - Get a substring of the string stored at a key
602 * [getSet](#getset) - Set the string value of a key and return its old value
603 * [incr, incrBy](#incr-incrby) - Increment the value of a key
604 * [incrByFloat](#incrbyfloat) - Increment the float value of a key by the given amount
605 * [mGet, getMultiple](#mget-getmultiple) - Get the values of all the given keys
606 * [mSet, mSetNX](#mset-msetnx) - Set multiple keys to multiple values
607 * [set](#set) - Set the string value of a key
608 * [setBit](#setbit) - Sets or clears the bit at offset in the string value stored at key
609 * [setex, psetex](#setex-psetex) - Set the value and expiration of a key
610 * [setnx](#setnx) - Set the value of a key, only if the key does not exist
611 * [setRange](#setrange) - Overwrite part of a string at key starting at the specified offset
612 * [strlen](#strlen) - Get the length of the value stored in a key
613
614 ### Keys
615 -----
616
617 * [del, delete](#del-delete) - Delete a key
618 * [dump](#dump) - Return a serialized version of the value stored at the specified key.
619 * [exists](#exists) - Determine if a key exists
620 * [expire, setTimeout, pexpire](#expire-settimeout-pexpire) - Set a key's time to live in seconds
621 * [expireAt, pexpireAt](#expireat-pexpireat) - Set the expiration for a key as a UNIX timestamp
622 * [keys, getKeys](#keys-getkeys) - Find all keys matching the given pattern
ab55389 @michael-grunder SCAN and variants
michael-grunder authored
623 * [scan](#scan) - Scan for keys in the keyspace (Redis >= 2.8.0)
dce8a70 @titpetric Keys and strings toc import
titpetric authored
624 * [migrate](#migrate) - Atomically transfer a key from a Redis instance to another one
625 * [move](#move) - Move a key to another database
626 * [object](#object) - Inspect the internals of Redis objects
627 * [persist](#persist) - Remove the expiration from a key
628 * [randomKey](#randomkey) - Return a random key from the keyspace
629 * [rename, renameKey](#rename-renamekey) - Rename a key
630 * [renameNx](#renamenx) - Rename a key, only if the new key does not exist
631 * [type](#type) - Determine the type stored at key
632 * [sort](#sort) - Sort the elements in a list, set or sorted set
633 * [ttl, pttl](#ttl-pttl) - Get the time to live for a key
634 * [restore](#restore) - Create a key using the provided serialized value, previously obtained with [dump](#dump).
635
fde1919 @titpetric footer hr after keys toc
titpetric authored
636 -----
637
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
638 ### get
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
639 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
640 _**Description**_: Get the value related to the specified key
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
641
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
642 ##### *Parameters*
3bb7c3b Delete command documentation.
Nasreddine Bouafif authored
643 *key*
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
644
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
645 ##### *Return value*
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
646 *String* or *Bool*: If key didn't exist, `FALSE` is returned. Otherwise, the value related to this key is returned.
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
647
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
648 ##### *Examples*
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
649
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
650 ~~~
be5f71a Format documentation.
Nasreddine Bouafif authored
651 $redis->get('key');
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
652 ~~~
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
653
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
654 ### set
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
655 -----
711f053 @michael-grunder Redis >= 2.6.12 extended set options
michael-grunder authored
656 _**Description**_: Set the string value in argument as value of the key. If you're using Redis >= 2.6.12, you can pass extended options as explained below
044b117 Documentation.
Nasreddine Bouafif authored
657
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
658 ##### *Parameters*
db66d76 @nicolasff Changed SET for better memcache API compatibility.
nicolasff authored
659 *Key*
660 *Value*
711f053 @michael-grunder Redis >= 2.6.12 extended set options
michael-grunder authored
661 *Timeout or Options Array* (optional). If you pass an integer, phpredis will redirect to SETEX, and will try to use Redis >= 2.6.12 extended options if you pass an array with valid values
044b117 Documentation.
Nasreddine Bouafif authored
662
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
663 ##### *Return value*
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
664 *Bool* `TRUE` if the command is successful.
044b117 Documentation.
Nasreddine Bouafif authored
665
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
666 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
667 ~~~
711f053 @michael-grunder Redis >= 2.6.12 extended set options
michael-grunder authored
668 // Simple key -> value set
db66d76 @nicolasff Changed SET for better memcache API compatibility.
nicolasff authored
669 $redis->set('key', 'value');
711f053 @michael-grunder Redis >= 2.6.12 extended set options
michael-grunder authored
670
671 // Will redirect, and actually make an SETEX call
672 $redis->set('key','value', 10);
673
674 // Will set the key, if it doesn't exist, with a ttl of 10 seconds
3f0dcd8 @mithunsatheesh Update README.markdown
mithunsatheesh authored
675 $redis->set('key', 'value', Array('nx', 'ex'=>10));
711f053 @michael-grunder Redis >= 2.6.12 extended set options
michael-grunder authored
676
677 // Will set a key, if it does exist, with a ttl of 1000 miliseconds
3f0dcd8 @mithunsatheesh Update README.markdown
mithunsatheesh authored
678 $redis->set('key', 'value', Array('xx', 'px'=>1000));
711f053 @michael-grunder Redis >= 2.6.12 extended set options
michael-grunder authored
679
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
680 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
681
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
682 ### setex, psetex
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
683 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
684 _**Description**_: Set the string value in argument as value of the key, with a time to live. PSETEX uses a TTL in milliseconds.
7c8e45f @nicolasff SETEX patch thanks to Zakay Danial.
nicolasff authored
685
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
686 ##### *Parameters*
7c8e45f @nicolasff SETEX patch thanks to Zakay Danial.
nicolasff authored
687 *Key*
688 *TTL*
689 *Value*
690
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
691 ##### *Return value*
7c8e45f @nicolasff SETEX patch thanks to Zakay Danial.
nicolasff authored
692 *Bool* `TRUE` if the command is successful.
693
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
694 ##### *Examples*
7c8e45f @nicolasff SETEX patch thanks to Zakay Danial.
nicolasff authored
695
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
696 ~~~
7c8e45f @nicolasff SETEX patch thanks to Zakay Danial.
nicolasff authored
697 $redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
171a969 @nicolasff Add PSETEX.
nicolasff authored
698 $redis->psetex('key', 100, 'value'); // sets key → value, with 0.1 sec TTL.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
699 ~~~
75434ae @titpetric bold/italics, whitespace
titpetric authored
700
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
701 ### setnx
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
702 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
703 _**Description**_: Set the string value in argument as value of the key if the key doesn't already exist in the database.
044b117 Documentation.
Nasreddine Bouafif authored
704
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
705 ##### *Parameters*
044b117 Documentation.
Nasreddine Bouafif authored
706 *key*
707 *value*
708
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
709 ##### *Return value*
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
710 *Bool* `TRUE` in case of success, `FALSE` in case of failure.
044b117 Documentation.
Nasreddine Bouafif authored
711
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
712 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
713 ~~~
aeba446 @nicolasff Typos (thanks “encoder” on IRC)
nicolasff authored
714 $redis->setnx('key', 'value'); /* return TRUE */
715 $redis->setnx('key', 'value'); /* return FALSE */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
716 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
717
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
718 ### del, delete
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
719 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
720 _**Description**_: Remove specified keys.
75434ae @titpetric bold/italics, whitespace
titpetric authored
721
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
722 ##### *Parameters*
a40ec71 Fixed delete() doc.
Nicolas Favre-Felix authored
723 An array of keys, or an undefined number of parameters, each a key: *key1* *key2* *key3* ... *keyN*
75434ae @titpetric bold/italics, whitespace
titpetric authored
724
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
725 ##### *Return value*
3bb7c3b Delete command documentation.
Nasreddine Bouafif authored
726 *Long* Number of keys deleted.
75434ae @titpetric bold/italics, whitespace
titpetric authored
727
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
728 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
729 ~~~
3bb7c3b Delete command documentation.
Nasreddine Bouafif authored
730 $redis->set('key1', 'val1');
731 $redis->set('key2', 'val2');
732 $redis->set('key3', 'val3');
a40ec71 Fixed delete() doc.
Nicolas Favre-Felix authored
733 $redis->set('key4', 'val4');
3bb7c3b Delete command documentation.
Nasreddine Bouafif authored
734
a40ec71 Fixed delete() doc.
Nicolas Favre-Felix authored
735 $redis->delete('key1', 'key2'); /* return 2 */
736 $redis->delete(array('key3', 'key4')); /* return 2 */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
737 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
738
c26621e @nicolasff Doc for PUB/SUB.
nicolasff authored
739
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
740 ### exists
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
741 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
742 _**Description**_: Verify if the specified key exists.
75434ae @titpetric bold/italics, whitespace
titpetric authored
743
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
744 ##### *Parameters*
617d098 documentation : spop and some fixes
Nasreddine Bouafif authored
745 *key*
75434ae @titpetric bold/italics, whitespace
titpetric authored
746
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
747 ##### *Return value*
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
748 *BOOL*: If the key exists, return `TRUE`, otherwise return `FALSE`.
75434ae @titpetric bold/italics, whitespace
titpetric authored
749
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
750 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
751 ~~~
aeba446 @nicolasff Typos (thanks “encoder” on IRC)
nicolasff authored
752 $redis->set('key', 'value');
753 $redis->exists('key'); /* TRUE */
754 $redis->exists('NonExistingKey'); /* FALSE */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
755 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
756
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
757 ### incr, incrBy
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
758 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
759 _**Description**_: Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment.
75434ae @titpetric bold/italics, whitespace
titpetric authored
760
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
761 ##### *Parameters*
81ffa0e @nicolasff Fixed missing doc (github issue #53).
nicolasff authored
762 *key*
acc6a21 incrBy and decrBy added and changelog updated
Simon Effenberg authored
763 *value*: value that will be added to key (only for incrBy)
75434ae @titpetric bold/italics, whitespace
titpetric authored
764
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
765 ##### *Return value*
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
766 *INT* the new value
75434ae @titpetric bold/italics, whitespace
titpetric authored
767
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
768 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
769 ~~~
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
770 $redis->incr('key1'); /* key1 didn't exists, set to 0 before the increment */
771 /* and now has the value 1 */
044b117 Documentation.
Nasreddine Bouafif authored
772
773 $redis->incr('key1'); /* 2 */
774 $redis->incr('key1'); /* 3 */
775 $redis->incr('key1'); /* 4 */
81ffa0e @nicolasff Fixed missing doc (github issue #53).
nicolasff authored
776 $redis->incrBy('key1', 10); /* 14 */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
777 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
778
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
779 ### incrByFloat
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
780 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
781 _**Description**_: Increment the key with floating point precision.
75434ae @titpetric bold/italics, whitespace
titpetric authored
782
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
783 ##### *Parameters*
e15fcfc @michael-grunder Fixed doc formatting
michael-grunder authored
784 *key*
785 *value*: (float) value that will be added to the key
75434ae @titpetric bold/italics, whitespace
titpetric authored
786
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
787 ##### *Return value*
98a0399 @michael-grunder Updated documentation to include INCRBYFLOAT, HINCRBYFLOAT and the ne…
michael-grunder authored
788 *FLOAT* the new value
75434ae @titpetric bold/italics, whitespace
titpetric authored
789
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
790 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
791 ~~~
98a0399 @michael-grunder Updated documentation to include INCRBYFLOAT, HINCRBYFLOAT and the ne…
michael-grunder authored
792 $redis->incrByFloat('key1', 1.5); /* key1 didn't exist, so it will now be 1.5 */
793
794
795 $redis->incrByFloat('key1', 1.5); /* 3 */
796 $redis->incrByFloat('key1', -1.5); /* 1.5 */
f92b74b @liaolliso2012 Update README.markdown
liaolliso2012 authored
797 $redis->incrByFloat('key1', 2.5); /* 4 */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
798 ~~~
98a0399 @michael-grunder Updated documentation to include INCRBYFLOAT, HINCRBYFLOAT and the ne…
michael-grunder authored
799
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
800 ### decr, decrBy
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
801 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
802 _**Description**_: Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer value of the decrement.
75434ae @titpetric bold/italics, whitespace
titpetric authored
803
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
804 ##### *Parameters*
81ffa0e @nicolasff Fixed missing doc (github issue #53).
nicolasff authored
805 *key*
acc6a21 incrBy and decrBy added and changelog updated
Simon Effenberg authored
806 *value*: value that will be substracted to key (only for decrBy)
75434ae @titpetric bold/italics, whitespace
titpetric authored
807
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
808 ##### *Return value*
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
809 *INT* the new value
75434ae @titpetric bold/italics, whitespace
titpetric authored
810
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
811 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
812 ~~~
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
813 $redis->decr('key1'); /* key1 didn't exists, set to 0 before the increment */
814 /* and now has the value -1 */
b215cc7 Documentation.
Nasreddine Bouafif authored
815
f01dd92 Many documentation fixes.
Nicolas Favre-Felix authored
816 $redis->decr('key1'); /* -2 */
817 $redis->decr('key1'); /* -3 */
81ffa0e @nicolasff Fixed missing doc (github issue #53).
nicolasff authored
818 $redis->decrBy('key1', 10); /* -13 */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
819 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
820
1816e44 @titpetric blanket fix method indentation to h3 level
titpetric authored
821 ### mGet, getMultiple
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
822 -----
2b3fa60 @titpetric added description markers, added description for sort (missing from d…
titpetric authored
823 _**Description**_: Get the values of all the specified keys. If one or more keys dont exist, the array will contain `FALSE` at the position of the key.
75434ae @titpetric bold/italics, whitespace
titpetric authored
824
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
825 ##### *Parameters*
741d986 Better markdown for types, added doc for sets.
Nicolas Favre-Felix authored
826 *Array*: Array containing the list of the keys
75434ae @titpetric bold/italics, whitespace
titpetric authored
827
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
828 ##### *Return value*
741d986 Better markdown for types, added doc for sets.
Nicolas Favre-Felix authored
829 *Array*: Array containing the values related to keys in argument
75434ae @titpetric bold/italics, whitespace
titpetric authored
830
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
831 ##### *Examples*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
832 ~~~
b215cc7 Documentation.
Nasreddine Bouafif authored
833 $redis->set('key1', 'value1');
834 $redis->set('key2', 'value2');
835 $redis->set('key3', 'value3');
43571d1 @nicolasff Added mGet as an alias to GetMultiple in doc.
nicolasff authored
836 $redis->mGet(array('key1', 'key2', 'key3')); /* array('value1', 'value2', 'value3');
837 $redis->mGet(array('key0', 'key1', 'key5')); /* array(`FALSE`, 'value2', `FALSE`);
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
838 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
839
b8ee612 @titpetric lists and list toc
titpetric authored
840 ### getSet
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
841 -----
b8ee612 @titpetric lists and list toc
titpetric authored
842 _**Description**_: Sets a value and returns the previous entry at that key.
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
843 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
844 *Key*: key
75434ae @titpetric bold/italics, whitespace
titpetric authored
845
b8ee612 @titpetric lists and list toc
titpetric authored
846 *STRING*: value
75434ae @titpetric bold/italics, whitespace
titpetric authored
847
b8ee612 @titpetric lists and list toc
titpetric authored
848 ##### *Return value*
849 A string, the previous value located at this key.
850 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
851 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
852 $redis->set('x', '42');
853 $exValue = $redis->getSet('x', 'lol'); // return '42', replaces x by 'lol'
854 $newValue = $redis->get('x')' // return 'lol'
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
855 ~~~
044b117 Documentation.
Nasreddine Bouafif authored
856
b8ee612 @titpetric lists and list toc
titpetric authored
857 ### randomKey
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
858 -----
b8ee612 @titpetric lists and list toc
titpetric authored
859 _**Description**_: Returns a random key.
75434ae @titpetric bold/italics, whitespace
titpetric authored
860
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
861 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
862 None.
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
863 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
864 *STRING*: an existing key in redis.
75434ae @titpetric bold/italics, whitespace
titpetric authored
865
b8ee612 @titpetric lists and list toc
titpetric authored
866 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
867 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
868 $key = $redis->randomKey();
869 $surprise = $redis->get($key); // who knows what's in there.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
870 ~~~
b215cc7 Documentation.
Nasreddine Bouafif authored
871
b8ee612 @titpetric lists and list toc
titpetric authored
872 ### move
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
873 -----
b8ee612 @titpetric lists and list toc
titpetric authored
874 _**Description**_: Moves a key to a different database.
75434ae @titpetric bold/italics, whitespace
titpetric authored
875
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
876 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
877 *Key*: key, the key to move.
878
879 *INTEGER*: dbindex, the database number to move the key to.
75434ae @titpetric bold/italics, whitespace
titpetric authored
880
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
881 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
882 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
883 ##### *Example*
75434ae @titpetric bold/italics, whitespace
titpetric authored
884
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
885 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
886 $redis->select(0); // switch to DB 0
887 $redis->set('x', '42'); // write 42 to x
888 $redis->move('x', 1); // move to DB 1
889 $redis->select(1); // switch to DB 1
890 $redis->get('x'); // will return 42
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
891 ~~~
a62d12a @nasr Add lPushx, rPushx and lInsert commands
nasr authored
892
b8ee612 @titpetric lists and list toc
titpetric authored
893 ### rename, renameKey
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
894 -----
b8ee612 @titpetric lists and list toc
titpetric authored
895 _**Description**_: Renames a key.
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
896 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
897 *STRING*: srckey, the key to rename.
75434ae @titpetric bold/italics, whitespace
titpetric authored
898
b8ee612 @titpetric lists and list toc
titpetric authored
899 *STRING*: dstkey, the new name for the key.
75434ae @titpetric bold/italics, whitespace
titpetric authored
900
b8ee612 @titpetric lists and list toc
titpetric authored
901 ##### *Return value*
902 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
903 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
904 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
905 $redis->set('x', '42');
906 $redis->rename('x', 'y');
907 $redis->get('y'); // → 42
908 $redis->get('x'); // → `FALSE`
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
909 ~~~
a62d12a @nasr Add lPushx, rPushx and lInsert commands
nasr authored
910
b8ee612 @titpetric lists and list toc
titpetric authored
911 ### renameNx
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
912 -----
b8ee612 @titpetric lists and list toc
titpetric authored
913 _**Description**_: Same as rename, but will not replace a key if the destination already exists. This is the same behaviour as setNx.
914
dce8a70 @titpetric Keys and strings toc import
titpetric authored
915 ### expire, setTimeout, pexpire
b8ee612 @titpetric lists and list toc
titpetric authored
916 -----
917 _**Description**_: Sets an expiration date (a timeout) on an item. pexpire requires a TTL in milliseconds.
75434ae @titpetric bold/italics, whitespace
titpetric authored
918
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
919 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
920 *Key*: key. The key that will disappear.
75434ae @titpetric bold/italics, whitespace
titpetric authored
921
b8ee612 @titpetric lists and list toc
titpetric authored
922 *Integer*: ttl. The key's remaining Time To Live, in seconds.
75434ae @titpetric bold/italics, whitespace
titpetric authored
923
b8ee612 @titpetric lists and list toc
titpetric authored
924 ##### *Return value*
925 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
926 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
927 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
928 $redis->set('x', '42');
929 $redis->setTimeout('x', 3); // x will disappear in 3 seconds.
930 sleep(5); // wait 5 seconds
931 $redis->get('x'); // will return `FALSE`, as 'x' has expired.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
932 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
933
b8ee612 @titpetric lists and list toc
titpetric authored
934 ### expireAt, pexpireAt
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
935 -----
b8ee612 @titpetric lists and list toc
titpetric authored
936 _**Description**_: Sets an expiration date (a timestamp) on an item. pexpireAt requires a timestamp in milliseconds.
75434ae @titpetric bold/italics, whitespace
titpetric authored
937
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
938 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
939 *Key*: key. The key that will disappear.
75434ae @titpetric bold/italics, whitespace
titpetric authored
940
b8ee612 @titpetric lists and list toc
titpetric authored
941 *Integer*: Unix timestamp. The key's date of death, in seconds from Epoch time.
75434ae @titpetric bold/italics, whitespace
titpetric authored
942
b8ee612 @titpetric lists and list toc
titpetric authored
943 ##### *Return value*
944 *BOOL*: `TRUE` in case of success, `FALSE` in case of failure.
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
945 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
946 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
947 $redis->set('x', '42');
948 $now = time(NULL); // current timestamp
949 $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
950 sleep(5); // wait 5 seconds
951 $redis->get('x'); // will return `FALSE`, as 'x' has expired.
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
952 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
953
b8ee612 @titpetric lists and list toc
titpetric authored
954 ### keys, getKeys
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
955 -----
b8ee612 @titpetric lists and list toc
titpetric authored
956 _**Description**_: Returns the keys that match a certain pattern.
756b434 @nasr Adding blPop and brPop commands
nasr authored
957
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
958 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
959 *STRING*: pattern, using '*' as a wildcard.
75434ae @titpetric bold/italics, whitespace
titpetric authored
960
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
961 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
962 *Array of STRING*: The keys that match a certain pattern.
756b434 @nasr Adding blPop and brPop commands
nasr authored
963
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
964 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
965 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
966 $allKeys = $redis->keys('*'); // all keys will match this.
967 $keyWithUserPrefix = $redis->keys('user*');
968 ~~~
756b434 @nasr Adding blPop and brPop commands
nasr authored
969
ab55389 @michael-grunder SCAN and variants
michael-grunder authored
970 ### scan
971 -----
972 _**Description**_: Scan the keyspace for keys
973
974 ##### *Parameters*
975 *LONG (reference)*: Iterator, initialized to NULL
976 *STRING, Optional*: Pattern to match
a77439a @nicolasff Minor documentation fixes
nicolasff authored
977 *LONG, Optional*: Count of keys per iteration (only a suggestion to Redis)
ab55389 @michael-grunder SCAN and variants
michael-grunder authored
978
979 ##### *Return value*
980 *Array, boolean*: This function will return an array of keys or FALSE if there are no more keys
756b434 @nasr Adding blPop and brPop commands
nasr authored
981
ab55389 @michael-grunder SCAN and variants
michael-grunder authored
982 ##### *Example*
983 ~~~
984 $it = NULL; /* Initialize our iterator to NULL */
985 $redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); /* retry when we get no keys back */
986 while($arr_keys = $redis->scan($it)) {
987 foreach($arr_keys as $str_key) {
988 echo "Here is a key: $str_key\n";
989 }
990 echo "No more keys to scan!\n";
991 }
992 ~~~
756b434 @nasr Adding blPop and brPop commands
nasr authored
993
b8ee612 @titpetric lists and list toc
titpetric authored
994 ### object
995 -----
996 _**Description**_: Describes the object pointed to by a key.
756b434 @nasr Adding blPop and brPop commands
nasr authored
997
b8ee612 @titpetric lists and list toc
titpetric authored
998 ##### *Parameters*
999 The information to retrieve (string) and the key (string). Info can be one of the following:
756b434 @nasr Adding blPop and brPop commands
nasr authored
1000
b8ee612 @titpetric lists and list toc
titpetric authored
1001 * "encoding"
1002 * "refcount"
1003 * "idletime"
756b434 @nasr Adding blPop and brPop commands
nasr authored
1004
b8ee612 @titpetric lists and list toc
titpetric authored
1005 ##### *Return value*
1006 *STRING* for "encoding", *LONG* for "refcount" and "idletime", `FALSE` if the key doesn't exist.
756b434 @nasr Adding blPop and brPop commands
nasr authored
1007
b8ee612 @titpetric lists and list toc
titpetric authored
1008 ##### *Example*
1009 ~~~
1010 $redis->object("encoding", "l"); // → ziplist
1011 $redis->object("refcount", "l"); // → 1
1012 $redis->object("idletime", "l"); // → 400 (in seconds, with a precision of 10 seconds).
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1013 ~~~
756b434 @nasr Adding blPop and brPop commands
nasr authored
1014
b8ee612 @titpetric lists and list toc
titpetric authored
1015 ### type
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1016 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1017 _**Description**_: Returns the type of data pointed by a given key.
75434ae @titpetric bold/italics, whitespace
titpetric authored
1018
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1019 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1020 *Key*: key
1021
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1022 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1023
1024 Depending on the type of the data pointed by the key, this method will return the following value:
1025 string: Redis::REDIS_STRING
1026 set: Redis::REDIS_SET
1027 list: Redis::REDIS_LIST
1028 zset: Redis::REDIS_ZSET
1029 hash: Redis::REDIS_HASH
1030 other: Redis::REDIS_NOT_FOUND
d1f9230 Redis Documentation.
Nasreddine Bouafif authored
1031
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1032 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1033 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1034 $redis->type('key');
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1035 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
1036
b8ee612 @titpetric lists and list toc
titpetric authored
1037 ### append
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1038 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1039 _**Description**_: Append specified string to the string stored in specified key.
1040
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1041 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1042 *Key*
1043 *Value*
d1f9230 Redis Documentation.
Nasreddine Bouafif authored
1044
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1045 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1046 *INTEGER*: Size of the value after the append
1047
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1048 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1049 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1050 $redis->set('key', 'value1');
1051 $redis->append('key', 'value2'); /* 12 */
1052 $redis->get('key'); /* 'value1value2' */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1053 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
1054
968d3fd @titpetric link keys and strings
titpetric authored
1055 ### getRange
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1056 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1057 _**Description**_: Return a substring of a larger string
75434ae @titpetric bold/italics, whitespace
titpetric authored
1058
968d3fd @titpetric link keys and strings
titpetric authored
1059 *Note*: substr also supported but deprecated in redis.
1060
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1061 ##### *Parameters*
d1f9230 Redis Documentation.
Nasreddine Bouafif authored
1062 *key*
b8ee612 @titpetric lists and list toc
titpetric authored
1063 *start*
1064 *end*
75434ae @titpetric bold/italics, whitespace
titpetric authored
1065
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1066 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1067 *STRING*: the substring
75434ae @titpetric bold/italics, whitespace
titpetric authored
1068
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1069 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1070 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1071 $redis->set('key', 'string value');
1072 $redis->getRange('key', 0, 5); /* 'string' */
1073 $redis->getRange('key', -5, -1); /* 'value' */
1074 ~~~
1075
1076 ### setRange
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1077 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1078 _**Description**_: Changes a substring of a larger string.
75434ae @titpetric bold/italics, whitespace
titpetric authored
1079
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1080 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1081 *key*
1082 *offset*
1083 *value*
d1f9230 Redis Documentation.
Nasreddine Bouafif authored
1084
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1085 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1086 *STRING*: the length of the string after it was modified.
75434ae @titpetric bold/italics, whitespace
titpetric authored
1087
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1088 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1089 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1090 $redis->set('key', 'Hello world');
1091 $redis->setRange('key', 6, "redis"); /* returns 11 */
1092 $redis->get('key'); /* "Hello redis" */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1093 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
1094
b8ee612 @titpetric lists and list toc
titpetric authored
1095 ### strlen
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1096 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1097 _**Description**_: Get the length of a string value.
75434ae @titpetric bold/italics, whitespace
titpetric authored
1098
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1099 ##### *Parameters*
d1f9230 Redis Documentation.
Nasreddine Bouafif authored
1100 *key*
75434ae @titpetric bold/italics, whitespace
titpetric authored
1101
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1102 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1103 *INTEGER*
75434ae @titpetric bold/italics, whitespace
titpetric authored
1104
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1105 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1106 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1107 $redis->set('key', 'value');
1108 $redis->strlen('key'); /* 5 */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1109 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
1110
b8ee612 @titpetric lists and list toc
titpetric authored
1111 ### getBit
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1112 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1113 _**Description**_: Return a single bit out of a larger string
55dcdf9 @nicolasff Added note about LREM argument order (GitHub issue #54).
nicolasff authored
1114
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1115 ##### *Parameters*
2619227 @nicolasff Typo. http://twitter.com/fastest963/status/27722652552
nicolasff authored
1116 *key*
b8ee612 @titpetric lists and list toc
titpetric authored
1117 *offset*
a374567 Redis Documentation.
Nasreddine Bouafif authored
1118
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1119 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1120 *LONG*: the bit value (0 or 1)
75434ae @titpetric bold/italics, whitespace
titpetric authored
1121
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1122 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1123 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1124 $redis->set('key', "\x7f"); // this is 0111 1111
1125 $redis->getBit('key', 0); /* 0 */
1126 $redis->getBit('key', 1); /* 1 */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1127 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
1128
b8ee612 @titpetric lists and list toc
titpetric authored
1129 ### setBit
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1130 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1131 _**Description**_: Changes a single bit of a string.
1132
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1133 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1134 *key*
1135 *offset*
1136 *value*: bool or int (1 or 0)
a62d12a @nasr Add lPushx, rPushx and lInsert commands
nasr authored
1137
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1138 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1139 *LONG*: 0 or 1, the value of the bit before it was set.
a62d12a @nasr Add lPushx, rPushx and lInsert commands
nasr authored
1140
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1141 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1142 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1143 $redis->set('key', "*"); // ord("*") = 42 = 0x2f = "0010 1010"
1144 $redis->setBit('key', 5, 1); /* returns 0 */
1145 $redis->setBit('key', 7, 1); /* returns 0 */
1146 $redis->get('key'); /* chr(0x2f) = "/" = b("0010 1111") */
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1147 ~~~
a62d12a @nasr Add lPushx, rPushx and lInsert commands
nasr authored
1148
b8ee612 @titpetric lists and list toc
titpetric authored
1149 ### bitop
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1150 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1151 _**Description**_: Bitwise operation on multiple keys.
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1152
b8ee612 @titpetric lists and list toc
titpetric authored
1153 ##### *Parameters*
1154 *operation*: either "AND", "OR", "NOT", "XOR"
1155 *ret_key*: return key
1156 *key1*
1157 *key2...*
a374567 Redis Documentation.
Nasreddine Bouafif authored
1158
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1159 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1160 *LONG*: The size of the string stored in the destination key.
f0f722a Doc.
Nicolas Favre-Felix authored
1161
b8ee612 @titpetric lists and list toc
titpetric authored
1162 ### bitcount
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1163 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1164 _**Description**_: Count bits in a string.
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1165
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1166 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1167 *key*
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1168
b8ee612 @titpetric lists and list toc
titpetric authored
1169 ##### *Return value*
1170 *LONG*: The number of bits set to 1 in the value behind the input key.
f0f722a Doc.
Nicolas Favre-Felix authored
1171
b8ee612 @titpetric lists and list toc
titpetric authored
1172 ### sort
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1173 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1174 _**Description**_: Sort the elements in a list, set or sorted set.
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1175
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1176 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1177 *Key*: key
1178 *Options*: array(key => value, ...) - optional, with the following keys and values:
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1179 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1180 'by' => 'some_pattern_*',
1181 'limit' => array(0, 1),
1182 'get' => 'some_other_pattern_*' or an array of patterns,
1183 'sort' => 'asc' or 'desc',
1184 'alpha' => TRUE,
1185 'store' => 'external-key'
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1186 ~~~
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1187 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1188 An array of values, or a number corresponding to the number of elements stored if that was used.
1189
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1190 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1191 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1192 $redis->delete('s');
1193 $redis->sadd('s', 5);
1194 $redis->sadd('s', 4);
1195 $redis->sadd('s', 2);
1196 $redis->sadd('s', 1);
1197 $redis->sadd('s', 3);
1198
1199 var_dump($redis->sort('s')); // 1,2,3,4,5
1200 var_dump($redis->sort('s', array('sort' => 'desc'))); // 5,4,3,2,1
1201 var_dump($redis->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)5
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1202 ~~~
a374567 Redis Documentation.
Nasreddine Bouafif authored
1203
f0f722a Doc.
Nicolas Favre-Felix authored
1204
b8ee612 @titpetric lists and list toc
titpetric authored
1205
1206
1207 ### ttl, pttl
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1208 -----
1b62414 @michael-grunder Update documentation and unit tests for TTL/PTTL
michael-grunder authored
1209 _**Description**_: Returns the time to live left for a given key in seconds (ttl), or milliseconds (pttl).
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1210
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1211 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1212 *Key*: key
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1213
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1214 ##### *Return value*
1b62414 @michael-grunder Update documentation and unit tests for TTL/PTTL
michael-grunder authored
1215 *LONG*: The time to live in seconds. If the key has no ttl, `-1` will be returned, and `-2` if the key doesn't exist.
b8ee612 @titpetric lists and list toc
titpetric authored
1216
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1217 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1218 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1219 $redis->ttl('key');
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1220 ~~~
617d098 documentation : spop and some fixes
Nasreddine Bouafif authored
1221
b8ee612 @titpetric lists and list toc
titpetric authored
1222 ### persist
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1223 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1224 _**Description**_: Remove the expiration timer from a key.
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1225
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1226 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1227 *Key*: key
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1228
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1229 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1230 *BOOL*: `TRUE` if a timeout was removed, `FALSE` if the key didn’t exist or didn’t have an expiration timer.
1231
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1232 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1233 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1234 $redis->persist('key');
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1235 ~~~
f0f722a Doc.
Nicolas Favre-Felix authored
1236
b8ee612 @titpetric lists and list toc
titpetric authored
1237 ### mset, msetnx
def41f7 @titpetric blanked add hr insert behind every h3
titpetric authored
1238 -----
b8ee612 @titpetric lists and list toc
titpetric authored
1239 _**Description**_: Sets multiple key-value pairs in one atomic command. MSETNX only returns TRUE if all the keys were set (see SETNX).
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
1240
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1241 ##### *Parameters*
b8ee612 @titpetric lists and list toc
titpetric authored
1242 *Pairs*: array(key => value, ...)
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
1243
8ffec24 @titpetric re-added em/asterisks on h5 consistently
titpetric authored
1244 ##### *Return value*
b8ee612 @titpetric lists and list toc
titpetric authored
1245 *Bool* `TRUE` in case of success, `FALSE` in case of failure.
9ab2739 Documentation formatting.
Nasreddine Bouafif authored
1246
1c6ee3e @titpetric alphabetized set methods, created toc
titpetric authored
1247 ##### *Example*
1354cf9 @titpetric replaced html pre tags with markdown syntax
titpetric authored
1248 ~~~
b8ee612 @titpetric lists and list toc
titpetric authored
1249
1250 $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
</