Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 732eb8d

Browse files
nbraun-amazonmichael-grunder
authored andcommitted
Add documentation for backoff algorithms
1 parent d78b0c7 commit 732eb8d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

README.markdown

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ You can also make a one-time contribution with one of the links below.
3535
1. [Classes and methods](#classes-and-methods)
3636
* [Usage](#usage)
3737
* [Connection](#connection)
38+
* [Retry and backoff](#retry-and-backoff)
3839
* [Server](#server)
3940
* [Keys and strings](#keys-and-strings)
4041
* [Hashes](#hashes)
@@ -428,6 +429,41 @@ _**Description**_: Sends a string to Redis, which replies with the same string
428429

429430
*STRING*: the same message.
430431

432+
## Retry and backoff
433+
434+
1. [Maximum retries](#maximum-retries)
435+
1. [Backoff algorithms](#backoff-algorithms)
436+
437+
### Maximum retries
438+
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.
439+
440+
##### *Example*
441+
442+
~~~php
443+
$redis->setOption(Redis::OPT_MAX_RETRIES, 5);
444+
$redis->getOption(Redis::OPT_MAX_RETRIES);
445+
~~~
446+
447+
### Backoff algorithms
448+
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):
449+
450+
* Default: `Redis::BACKOFF_ALGORITHM_DEFAULT`
451+
* Decorrelated jitter: `Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER`
452+
* Full jitter: `Redis::BACKOFF_ALGORITHM_FULL_JITTER`
453+
* Equal jitter: `Redis::BACKOFF_ALGORITHM_EQUAL_JITTER`
454+
* Exponential: `Redis::BACKOFF_ALGORITHM_EXPONENTIAL`
455+
* Uniform: `Redis::BACKOFF_ALGORITHM_UNIFORM`
456+
* Constant: `Redis::BACKOFF_ALGORITHM_CONSTANT`
457+
458+
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.
459+
460+
##### *Example*
461+
462+
~~~php
463+
$redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER);
464+
$redis->setOption(Redis::OPT_BACKOFF_BASE, 500); // base for backoff computation: 500ms
465+
$redis->setOption(Redis::OPT_BACKOFF_CAP, 750); // backoff time capped at 750ms
466+
~~~
431467

432468
## Server
433469

tests/RedisTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5280,9 +5280,6 @@ public function testMaxRetriesOption() {
52805280
}
52815281

52825282
public function testBackoffOptions() {
5283-
$this->redis->setOption(Redis::OPT_MAX_RETRIES, 5);
5284-
$this->assertEquals($this->redis->getOption(Redis::OPT_MAX_RETRIES), 5);
5285-
52865283
$this->redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_DEFAULT);
52875284
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_DEFAULT);
52885285

@@ -5295,6 +5292,9 @@ public function testBackoffOptions() {
52955292
$this->redis -> setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_EXPONENTIAL);
52965293
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_EXPONENTIAL);
52975294

5295+
$this->redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_EQUAL_JITTER);
5296+
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_EQUAL_JITTER);
5297+
52985298
$this->redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_FULL_JITTER);
52995299
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_FULL_JITTER);
53005300

0 commit comments

Comments
 (0)