Skip to content

Commit f910a4d

Browse files
author
Gerardo Perosio
committed
Merge remote-tracking branch 'upstream/develop' into develop
2 parents cd3d56d + 7807e87 commit f910a4d

26 files changed

+4377
-4648
lines changed

.travis.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,41 @@ php:
55
- 5.4
66
- 5.5
77
- 5.6
8-
services: redis-server
9-
before_install: phpize
10-
install: ./configure --prefix=/usr && sudo make install
11-
before_script: echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
12-
script: php tests/TestRedis.php
8+
- 7.0
9+
- 7.1
10+
- nightly
11+
env: CC=gcc
12+
matrix:
13+
allow_failures:
14+
- php: nightly
15+
include:
16+
- php: 5.4
17+
env: CC=clang
18+
- php: 5.5
19+
env: CC=clang
20+
- php: 5.6
21+
env: CC=clang
22+
- php: 7.0
23+
env: CC=clang
24+
- php: 7.1
25+
env: CC=clang
26+
addons:
27+
apt:
28+
packages: clang
29+
before_install:
30+
- phpize
31+
- pecl install igbinary
32+
- ./configure --enable-redis-igbinary CFLAGS=-Wall
33+
install: make install
34+
before_script:
35+
- gem install redis
36+
- mkdir -p tests/nodes/ && echo >> tests/nodes/nodemap
37+
- for PORT in $(seq 6379 6382); do redis-server --port $PORT --daemonize yes; done
38+
- for PORT in $(seq 7000 7011); do redis-server --port $PORT --cluster-enabled yes --cluster-config-file $PORT.conf --daemonize yes; echo 127.0.0.1:$PORT >> tests/nodes/nodemap; done
39+
- wget https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb
40+
- echo yes | ruby redis-trib.rb create --replicas 3 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 127.0.0.1:7007 127.0.0.1:7008 127.0.0.1:7009 127.0.0.1:7010 127.0.0.1:7011
41+
- echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
42+
script:
43+
- php tests/TestRedis.php --class Redis
44+
- php tests/TestRedis.php --class RedisArray
45+
- php tests/TestRedis.php --class RedisCluster

README.markdown

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
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).
66
This code has been developed and maintained by Owlient from November 2009 to March 2011.
77

8-
You can send comments, patches, questions [here on github](https://github.com/phpredis/phpredis/issues), to [email protected] ([@yowgi](http://twitter.com/yowgi)), or to [email protected] ([@grumi78](http://twitter.com/grumi78)).
8+
You can send comments, patches, questions [here on github](https://github.com/phpredis/phpredis/issues), to [email protected] ([@yowgi](https://twitter.com/yowgi)), to [email protected] ([@grumi78](https://twitter.com/grumi78)) or to [email protected] ([@yatsukhnenko](https://twitter.com/yatsukhnenko)).
99

1010

1111
# Table of contents
@@ -82,7 +82,7 @@ You can install install it using Homebrew:
8282
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:
8383
~~~
8484
session.save_handler = redis
85-
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"
85+
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2&read_timeout=2.5"
8686
~~~
8787

8888
`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:
@@ -209,6 +209,7 @@ _**Description**_: Connects to a Redis instance.
209209
*timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
210210
*reserved*: should be NULL if retry_interval is specified
211211
*retry_interval*: int, value in milliseconds (optional)
212+
*read_timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
212213

213214
##### *Return value*
214215

@@ -245,6 +246,7 @@ persistent equivalents.
245246
*timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
246247
*persistent_id*: string. identity for the requested persistent connection
247248
*retry_interval*: int, value in milliseconds (optional)
249+
*read_timeout*: float, value in seconds (optional, default is 0 meaning unlimited)
248250

249251
##### *Return value*
250252

@@ -1015,18 +1017,38 @@ _**Description**_: Scan the keyspace for keys
10151017
*LONG, Optional*: Count of keys per iteration (only a suggestion to Redis)
10161018

10171019
##### *Return value*
1018-
*Array, boolean*: This function will return an array of keys or FALSE if there are no more keys
1020+
*Array, boolean*: This function will return an array of keys or FALSE if Redis returned zero keys
10191021

10201022
##### *Example*
10211023
~~~
1022-
$it = NULL; /* Initialize our iterator to NULL */
1023-
$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); /* retry when we get no keys back */
1024-
while($arr_keys = $redis->scan($it)) {
1025-
foreach($arr_keys as $str_key) {
1024+
1025+
/* Without enabling Redis::SCAN_RETRY (default condition) */
1026+
$it = NULL;
1027+
do {
1028+
// Scan for some keys
1029+
$arr_keys = $redis->scan($it);
1030+
1031+
// Redis may return empty results, so protect against that
1032+
if ($arr_keys !== FALSE) {
1033+
foreach($arr_keys as $str_key) {
1034+
echo "Here is a key: $str_key\n";
1035+
}
1036+
}
1037+
} while ($it > 0);
1038+
echo "No more keys to scan!\n";
1039+
1040+
/* With Redis::SCAN_RETRY enabled */
1041+
$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
1042+
$it = NULL;
1043+
1044+
/* phpredis will retry the SCAN command if empty results are returned from the
1045+
server, so no empty results check is required. */
1046+
while ($arr_keys = $redis->scan($it)) {
1047+
foreach ($arr_keys as $str_key) {
10261048
echo "Here is a key: $str_key\n";
10271049
}
1028-
echo "No more keys to scan!\n";
10291050
}
1051+
echo "No more keys to scan!\n";
10301052
~~~
10311053

10321054
### object
@@ -1329,19 +1351,26 @@ $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key
13291351
### migrate
13301352
-----
13311353
_**Description**_: Migrates a key to a different Redis instance.
1354+
1355+
**Note:**: Redis introduced migrating multiple keys in 3.0.6, so you must have at least
1356+
that version in order to call `migrate` with an array of keys.
1357+
13321358
##### *Parameters*
1333-
*host* string. The destination host
1334-
*port* integer. The TCP port to connect to.
1335-
*key* string. The key to migrate.
1336-
*destination-db* integer. The target DB.
1337-
*timeout* integer. The maximum amount of time given to this transfer.
1338-
*copy* boolean, optional. Should we send the COPY flag to redis
1339-
*replace* boolean, optional. Should we send the REPLACE flag to redis
1359+
*host* string. The destination host
1360+
*port* integer. The TCP port to connect to.
1361+
*key(s)* string or array.
1362+
*destination-db* integer. The target DB.
1363+
*timeout* integer. The maximum amount of time given to this transfer.
1364+
*copy* boolean, optional. Should we send the COPY flag to redis.
1365+
*replace* boolean, optional. Should we send the REPLACE flag to redis
13401366
##### *Examples*
13411367
~~~
13421368
$redis->migrate('backup', 6379, 'foo', 0, 3600);
13431369
$redis->migrate('backup', 6379, 'foo', 0, 3600, true, true); /* copy and replace */
13441370
$redis->migrate('backup', 6379, 'foo', 0, 3600, false, true); /* just REPLACE flag */
1371+
1372+
/* Migrate multiple keys (requires Redis >= 3.0.6)
1373+
$redis->migrate('backup', 6379, ['key1', 'key2', 'key3'], 0, 3600);
13451374
~~~
13461375

13471376

@@ -1362,6 +1391,7 @@ $redis->migrate('backup', 6379, 'foo', 0, 3600, false, true); /* just REPLACE fl
13621391
* [hSetNx](#hsetnx) - Set the value of a hash field, only if the field does not exist
13631392
* [hVals](#hvals) - Get all the values in a hash
13641393
* [hScan](#hscan) - Scan a hash key for members
1394+
* [hStrLen](#hstrlen) - Get the string length of the value associated with field in the hash
13651395

13661396
### hSet
13671397
-----
@@ -1646,6 +1676,15 @@ while($arr_keys = $redis->hScan('hash', $it)) {
16461676
}
16471677
~~~
16481678

1679+
### hStrLen
1680+
-----
1681+
_**Description**_: Get the string length of the value associated with field in the hash stored at key.
1682+
##### *Parameters*
1683+
*key*: String
1684+
*field*: String
1685+
##### *Return value*
1686+
*LONG* the string length of the value associated with field, or zero when field is not present in the hash or key does not exist at all.
1687+
16491688
## Lists
16501689

16511690
* [blPop, brPop](#blpop-brpop) - Remove and get the first/last element in a list
@@ -2078,7 +2117,7 @@ $redis->lSize('key1');/* 2 */
20782117
* [sIsMember, sContains](#sismember-scontains) - Determine if a given value is a member of a set
20792118
* [sMembers, sGetMembers](#smembers-sgetmembers) - Get all the members in a set
20802119
* [sMove](#smove) - Move a member from one set to another
2081-
* [sPop](#spop) - Remove and return a random member from a set
2120+
* [sPop](#spop) - Remove and return one or more members of a set at random
20822121
* [sRandMember](#srandmember) - Get one or multiple random members from a set
20832122
* [sRem, sRemove](#srem-sremove) - Remove one or more members from a set
20842123
* [sUnion](#sunion) - Add multiple sets
@@ -2348,16 +2387,24 @@ $redis->sMove('key1', 'key2', 'member13'); /* 'key1' => {'member11', 'member12'
23482387
_**Description**_: Removes and returns a random element from the set value at Key.
23492388
##### *Parameters*
23502389
*key*
2351-
##### *Return value*
2390+
*count*: Integer, optional
2391+
##### *Return value (without count argument)*
23522392
*String* "popped" value
23532393
*Bool* `FALSE` if set identified by key is empty or doesn't exist.
2394+
##### *Return value (with count argument)*
2395+
*Array*: Member(s) returned or an empty array if the set doesn't exist
2396+
*Bool*: `FALSE` on error if the key is not a set
23542397
##### *Example*
23552398
~~~
23562399
$redis->sAdd('key1' , 'member1');
23572400
$redis->sAdd('key1' , 'member2');
23582401
$redis->sAdd('key1' , 'member3'); /* 'key1' => {'member3', 'member1', 'member2'}*/
23592402
$redis->sPop('key1'); /* 'member1', 'key1' => {'member3', 'member2'} */
23602403
$redis->sPop('key1'); /* 'member3', 'key1' => {'member2'} */
2404+
2405+
/* With count */
2406+
$redis->sAdd('key2', 'member1', 'member2', 'member3');
2407+
$redis->sPop('key2', 3); /* Will return all members but in no particular order */
23612408
~~~
23622409

23632410
### sRandMember

arrays.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ The connect_timeout value is a double and is used to specify a timeout in number
5555
$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("connect_timeout" => 0.5));
5656
</pre>
5757

58+
#### Specifying the "read_timeout" parameter
59+
The read_timeout value is a double and is used to specify a timeout in number of seconds when waiting response from the server.
60+
<pre>
61+
$ra = new RedisArray(array("host1", "host2:63792", "host2:6380"), array("read_timeout" => 0.5));
62+
</pre>
63+
64+
5865
#### Defining arrays in Redis.ini
5966

6067
Because php.ini parameters must be pre-defined, Redis Arrays must all share the same .ini settings.

cluster.markdown

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ To maintain consistency with the RedisArray class, one can create and connect to
1313
$obj_cluster = new RedisCluster(NULL, Array('host:7000', 'host:7001', 'host:7003'));
1414

1515
// Connect and specify timeout and read_timeout
16-
$obj_cluster = new RedisCluster(
17-
NULL, Array("host:7000", "host:7001"), 1.5, 1.5
18-
);
16+
$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5);
1917

2018
// Connect with read/write timeout as well as specify that phpredis should use
2119
// persistent connections to each node.
22-
$obj_cluster = new RedisCluster(
23-
NULL, Array("host:7000", "host:7001"), 1.5, 1.5, true
24-
);
20+
$obj_cluster = new RedisCluster(NULL, Array("host:7000", "host:7001"), 1.5, 1.5, true);
2521

2622
</pre>
2723

0 commit comments

Comments
 (0)