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

predis / predis / 20351138744

18 Dec 2025 09:00PM UTC coverage: 92.603% (-0.2%) from 92.788%
20351138744

Pull #1616

github

web-flow
Merge 4023b4e91 into 0ae180c94
Pull Request #1616: Added retry support

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

3 existing lines in 3 files now uncovered.

8213 of 8869 relevant lines covered (92.6%)

112.14 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)
74✔
38
    {
39
        $this->base = $base;
74✔
40
        $this->cap = $cap;
74✔
41
        $this->withJitter = $withJitter;
74✔
42
    }
43

44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function compute(int $failures): int
35✔
48
    {
49
        if ($this->withJitter) {
35✔
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) {
34✔
54
            return min($this->cap, $this->base * 2 ** $failures);
21✔
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