• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

predis / predis / 20455852140

23 Dec 2025 08:40AM UTC coverage: 92.615% (-0.2%) from 92.788%
20455852140

push

github

web-flow
Added retry support (#1616)

* Initial work on retries

* Added retry class and test coverage

* Added support for standalone and cluster

* Make TimeoutException instance of CommunicationException

* Added pipeline, trasnaction, replication support

* Fixed broken test

* Marked test as relay-incompatible

* Marked test as relay-incompatible

* Fixed analysis errors, added missing tests

* Codestyle fixes

* Fixed test

* Update README.md

* Update README.md

* Update README.md

* Updated README.md

* Refactor retry on read and write

* Added check for timeout value

* Updated README.md

* Fixed README.md

* Codestyle changes

* Added missing coverage

* Added missing test coverage

* Removed comments

* Added retry support for Relay connection (#1620)

* Added integration test case with mocked retry

* Changed client initialisation in tests

* Marked test as relay-incompatible

---------

Co-authored-by: Pavlo Yatsukhnenko <yatsukhnenko@users.noreply.github.com>

301 of 358 new or added lines in 18 files covered. (84.08%)

2 existing lines in 2 files now uncovered.

8214 of 8869 relevant lines covered (92.61%)

112.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/src/Retry/Strategy/ExponentialBackoff.php
1
<?php
2

3
/*
4
 * This file is part of the Predis package.
5
 *
6
 * (c) 2009-2020 Daniele Alessandri
7
 * (c) 2021-2025 Till Krüss
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

13
namespace Predis\Retry\Strategy;
14

15
class ExponentialBackoff implements RetryStrategyInterface
16
{
17
    /**
18
     * @var int
19
     */
20
    protected $base;
21

22
    /**
23
     * @var int
24
     */
25
    protected $cap;
26

27
    /**
28
     * @var bool
29
     */
30
    protected $withJitter;
31

32
    /**
33
     * @param int  $base       in micro seconds
34
     * @param int  $cap        in micro seconds
35
     * @param bool $withJitter
36
     */
37
    public function __construct(int $base = self::DEFAULT_BASE, int $cap = self::DEFAULT_CAP, bool $withJitter = false)
75✔
38
    {
39
        $this->base = $base;
75✔
40
        $this->cap = $cap;
75✔
41
        $this->withJitter = $withJitter;
75✔
42
    }
43

44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function compute(int $failures): int
36✔
48
    {
49
        if ($this->withJitter) {
36✔
50
            return min($this->cap, (mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax()) * ($this->base * 2 ** $failures));
2✔
51
        }
52

53
        if ($this->cap > 0) {
35✔
54
            return min($this->cap, $this->base * 2 ** $failures);
22✔
55
        }
56

57
        return $this->base * 2 ** $failures;
14✔
58
    }
59

60
    /**
61
     * @return int
62
     */
NEW
63
    public function getBase(): int
×
64
    {
NEW
65
        return $this->base;
×
66
    }
67

68
    /**
69
     * @return int
70
     */
NEW
71
    public function getCap(): int
×
72
    {
NEW
73
        return $this->cap;
×
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc