|
1 | 1 | # PhpRedis |
2 | 2 |
|
3 | | -[](https://travis-ci.org/phpredis/phpredis) |
| 3 | +[](https://github.com/phpredis/phpredis/actions/workflows/ci.yml) |
4 | 4 | [](https://scan.coverity.com/projects/phpredis-phpredis) |
| 5 | +[](https://img.shields.io/travis/php-v/phpredis/phpredis/develop) |
5 | 6 |
|
6 | 7 | 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). |
7 | 8 | This code has been developed and maintained by Owlient from November 2009 to March 2011. |
@@ -34,6 +35,7 @@ You can also make a one-time contribution with one of the links below. |
34 | 35 | 1. [Classes and methods](#classes-and-methods) |
35 | 36 | * [Usage](#usage) |
36 | 37 | * [Connection](#connection) |
| 38 | + * [Retry and backoff](#retry-and-backoff) |
37 | 39 | * [Server](#server) |
38 | 40 | * [Keys and strings](#keys-and-strings) |
39 | 41 | * [Hashes](#hashes) |
@@ -77,7 +79,7 @@ session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeou |
77 | 79 |
|
78 | 80 | 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). |
79 | 81 | The session handler requires a version of Redis supporting `EX` and `NX` options of `SET` command (at least 2.6.12). |
80 | | -phpredis can also connect to a unix domain socket: `session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0`. |
| 82 | +phpredis can also connect to a unix domain socket: `session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0"`. |
81 | 83 |
|
82 | 84 | ### Session locking |
83 | 85 |
|
@@ -293,7 +295,7 @@ $redis->auth(['phpredis', 'haxx00r']); |
293 | 295 | $redis->auth(['foobared']); |
294 | 296 |
|
295 | 297 | /* You can also use an associative array specifying user and pass */ |
296 | | -$redis->auth(['user' => 'phpredis', 'pass' => 'phpredis]); |
| 298 | +$redis->auth(['user' => 'phpredis', 'pass' => 'phpredis']); |
297 | 299 | $redis->auth(['pass' => 'phpredis']); |
298 | 300 | ~~~ |
299 | 301 |
|
@@ -356,6 +358,7 @@ $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // Don't ser |
356 | 358 | $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // Use built-in serialize/unserialize |
357 | 359 | $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // Use igBinary serialize/unserialize |
358 | 360 | $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_MSGPACK); // Use msgpack serialize/unserialize |
| 361 | +$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_JSON); // Use JSON to serialize/unserialize |
359 | 362 |
|
360 | 363 | $redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys |
361 | 364 |
|
@@ -388,7 +391,7 @@ Parameter value. |
388 | 391 | ##### *Example* |
389 | 392 | ~~~php |
390 | 393 | // return Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP, |
391 | | -// Redis::SERIALIZER_IGBINARY, or Redis::SERIALIZER_MSGPACK |
| 394 | +// Redis::SERIALIZER_IGBINARY, Redis::SERIALIZER_MSGPACK or Redis::SERIALIZER_JSON |
392 | 395 | $redis->getOption(Redis::OPT_SERIALIZER); |
393 | 396 | ~~~ |
394 | 397 |
|
@@ -427,6 +430,41 @@ _**Description**_: Sends a string to Redis, which replies with the same string |
427 | 430 |
|
428 | 431 | *STRING*: the same message. |
429 | 432 |
|
| 433 | +## Retry and backoff |
| 434 | + |
| 435 | +1. [Maximum retries](#maximum-retries) |
| 436 | +1. [Backoff algorithms](#backoff-algorithms) |
| 437 | + |
| 438 | +### Maximum retries |
| 439 | +You can set and get the maximum retries upon connection issues using the `OPT_MAX_RETRIES` option. Note that this is the number of _retries_, meaning if you set this option to _n_, there will be a maximum _n+1_ attemps overall. Defaults to 10. |
| 440 | + |
| 441 | +##### *Example* |
| 442 | + |
| 443 | +~~~php |
| 444 | +$redis->setOption(Redis::OPT_MAX_RETRIES, 5); |
| 445 | +$redis->getOption(Redis::OPT_MAX_RETRIES); |
| 446 | +~~~ |
| 447 | + |
| 448 | +### Backoff algorithms |
| 449 | +You can set the backoff algorithm using the `Redis::OPT_BACKOFF_ALGORITHM` option and choose among the following algorithms described in this blog post by Marc Brooker from AWS: [Exponential Backoff And Jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter): |
| 450 | + |
| 451 | +* Default: `Redis::BACKOFF_ALGORITHM_DEFAULT` |
| 452 | +* Decorrelated jitter: `Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER` |
| 453 | +* Full jitter: `Redis::BACKOFF_ALGORITHM_FULL_JITTER` |
| 454 | +* Equal jitter: `Redis::BACKOFF_ALGORITHM_EQUAL_JITTER` |
| 455 | +* Exponential: `Redis::BACKOFF_ALGORITHM_EXPONENTIAL` |
| 456 | +* Uniform: `Redis::BACKOFF_ALGORITHM_UNIFORM` |
| 457 | +* Constant: `Redis::BACKOFF_ALGORITHM_CONSTANT` |
| 458 | + |
| 459 | +These algorithms depend on the _base_ and _cap_ parameters, both in milliseconds, which you can set using the `Redis::OPT_BACKOFF_BASE` and `Redis::OPT_BACKOFF_CAP` options, respectively. |
| 460 | + |
| 461 | +##### *Example* |
| 462 | + |
| 463 | +~~~php |
| 464 | +$redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER); |
| 465 | +$redis->setOption(Redis::OPT_BACKOFF_BASE, 500); // base for backoff computation: 500ms |
| 466 | +$redis->setOption(Redis::OPT_BACKOFF_CAP, 750); // backoff time capped at 750ms |
| 467 | +~~~ |
430 | 468 |
|
431 | 469 | ## Server |
432 | 470 |
|
@@ -882,7 +920,7 @@ $redis->exists('key'); /* 1 */ |
882 | 920 | $redis->exists('NonExistingKey'); /* 0 */ |
883 | 921 |
|
884 | 922 | $redis->mset(['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz']); |
885 | | -$redis->exists(['foo', 'bar', 'baz]); /* 3 */ |
| 923 | +$redis->exists(['foo', 'bar', 'baz']); /* 3 */ |
886 | 924 | $redis->exists('foo', 'bar', 'baz'); /* 3 */ |
887 | 925 | ~~~ |
888 | 926 |
|
@@ -2254,7 +2292,7 @@ $redis->lLen('key1');/* 2 */ |
2254 | 2292 |
|
2255 | 2293 | ### sAdd |
2256 | 2294 | ----- |
2257 | | -_**Description**_: Adds a value to the set value stored at key. If this value is already in the set, `FALSE` is returned. |
| 2295 | +_**Description**_: Adds a value to the set value stored at key. |
2258 | 2296 | ##### *Parameters* |
2259 | 2297 | *key* |
2260 | 2298 | *value* |
@@ -2615,7 +2653,7 @@ $redis->sAdd('s2', '4'); |
2615 | 2653 | var_dump($redis->sUnion('s0', 's1', 's2')); |
2616 | 2654 |
|
2617 | 2655 | /* Pass a single array */ |
2618 | | -var_dump($redis->sUnion(['s0', 's1', 's2']); |
| 2656 | +var_dump($redis->sUnion(['s0', 's1', 's2'])); |
2619 | 2657 |
|
2620 | 2658 | ~~~ |
2621 | 2659 | Return value: all elements that are either in s0 or in s1 or in s2. |
@@ -3794,7 +3832,7 @@ $obj_redis->xRange('mystream', '-', '+', 2); |
3794 | 3832 |
|
3795 | 3833 | ##### *Prototype* |
3796 | 3834 | ~~~php |
3797 | | -$obj_redis->xRead($arr_streams [, $i_count, $i_block); |
| 3835 | +$obj_redis->xRead($arr_streams [, $i_count, $i_block]); |
3798 | 3836 | ~~~ |
3799 | 3837 |
|
3800 | 3838 | _**Description**_: Read data from one or more streams and only return IDs greater than sent in the command. |
@@ -4010,7 +4048,7 @@ $redis->rawCommand("set", "foo", "bar"); |
4010 | 4048 | $redis->rawCommand("get", "foo"); |
4011 | 4049 |
|
4012 | 4050 | /* Returns: 3 */ |
4013 | | -$redis->rawCommand("rpush", "mylist", "one", 2, 3.5)); |
| 4051 | +$redis->rawCommand("rpush", "mylist", "one", 2, 3.5); |
4014 | 4052 |
|
4015 | 4053 | /* Returns: ["one", "2", "3.5000000000000000"] */ |
4016 | 4054 | $redis->rawCommand("lrange", "mylist", 0, -1); |
|
0 commit comments