Skip to content

Commit 26be194

Browse files
Merge pull request #1993 from nbraun-amazon/develop
Add documentation for backoff algorithms Related to #1986
2 parents d1097f6 + 0c04f65 commit 26be194

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
@@ -5406,9 +5406,6 @@ public function testMaxRetriesOption() {
54065406
}
54075407

54085408
public function testBackoffOptions() {
5409-
$this->redis->setOption(Redis::OPT_MAX_RETRIES, 5);
5410-
$this->assertEquals($this->redis->getOption(Redis::OPT_MAX_RETRIES), 5);
5411-
54125409
$this->redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_DEFAULT);
54135410
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_DEFAULT);
54145411

@@ -5421,6 +5418,9 @@ public function testBackoffOptions() {
54215418
$this->redis -> setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_EXPONENTIAL);
54225419
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_EXPONENTIAL);
54235420

5421+
$this->redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_EQUAL_JITTER);
5422+
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_EQUAL_JITTER);
5423+
54245424
$this->redis->setOption(Redis::OPT_BACKOFF_ALGORITHM, Redis::BACKOFF_ALGORITHM_FULL_JITTER);
54255425
$this->assertEquals($this->redis->getOption(Redis::OPT_BACKOFF_ALGORITHM), Redis::BACKOFF_ALGORITHM_FULL_JITTER);
54265426

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy