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

Skip to content

Commit 9eb00e8

Browse files
committed
Better naming
1 parent e06495a commit 9eb00e8

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ public function testGetNonBlocking()
143143
$redis->del('messenger-getnonblocking');
144144
}
145145

146-
public function testxAddWithMaxLength()
146+
public function testMaxEntries()
147147
{
148148
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
149149

150150
$redis->expects($this->exactly(1))->method('xadd')
151151
->with('queue', '*', ['message' => '{"body":"1","headers":[]}'], 20000, true)
152152
->willReturn(1);
153153

154-
$connection = Connection::fromDsn('redis://localhost/queue?xadd_maxlength=20000', [], $redis); // 1 = always
154+
$connection = Connection::fromDsn('redis://localhost/queue?stream_max_entries=20000', [], $redis); // 1 = always
155155
$connection->add('1', []);
156156
}
157157
}

src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class Connection
3232
'group' => 'symfony',
3333
'consumer' => 'consumer',
3434
'auto_setup' => true,
35-
'xadd_maxlength' => 0, // 0 disables trimming, any other value defines an approximate maximum length
35+
'stream_max_entries' => 0, // any value higher than 0 defines an approximate maximum number of stream entries
3636
];
3737

3838
private $connection;
3939
private $stream;
4040
private $group;
4141
private $consumer;
4242
private $autoSetup;
43-
private $xaddMaxLength;
43+
private $maxEntries;
4444
private $couldHavePendingMessages = true;
4545

4646
public function __construct(array $configuration, array $connectionCredentials = [], array $redisOptions = [], \Redis $redis = null)
@@ -52,7 +52,7 @@ public function __construct(array $configuration, array $connectionCredentials =
5252
$this->group = $configuration['group'] ?? self::DEFAULT_OPTIONS['group'];
5353
$this->consumer = $configuration['consumer'] ?? self::DEFAULT_OPTIONS['consumer'];
5454
$this->autoSetup = $configuration['auto_setup'] ?? self::DEFAULT_OPTIONS['auto_setup'];
55-
$this->xaddMaxLength = $configuration['xadd_maxlength'] ?? self::DEFAULT_OPTIONS['xadd_maxlength'];
55+
$this->maxEntries = $configuration['stream_max_entries'] ?? self::DEFAULT_OPTIONS['stream_max_entries'];
5656
}
5757

5858
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
@@ -82,18 +82,18 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
8282
unset($redisOptions['auto_setup']);
8383
}
8484

85-
$xaddMaxLength = null;
86-
if (\array_key_exists('xadd_maxlength', $redisOptions)) {
87-
$xaddMaxLength = filter_var($redisOptions['xadd_maxlength'], FILTER_VALIDATE_INT);
88-
unset($redisOptions['xadd_maxlength']);
85+
$maxEntries = null;
86+
if (\array_key_exists('stream_max_entries', $redisOptions)) {
87+
$maxEntries = filter_var($redisOptions['stream_max_entries'], FILTER_VALIDATE_INT);
88+
unset($redisOptions['stream_max_entries']);
8989
}
9090

9191
return new self([
9292
'stream' => $stream,
9393
'group' => $group,
9494
'consumer' => $consumer,
9595
'auto_setup' => $autoSetup,
96-
'xadd_maxlength' => $xaddMaxLength,
96+
'stream_max_entries' => $maxEntries,
9797
], $connectionCredentials, $redisOptions, $redis);
9898
}
9999

@@ -181,10 +181,10 @@ public function add(string $body, array $headers): void
181181

182182
$e = null;
183183
try {
184-
if ($this->xaddMaxLength) {
184+
if ($this->maxEntries) {
185185
$added = $this->connection->xadd($this->stream, '*', ['message' => json_encode(
186186
['body' => $body, 'headers' => $headers]
187-
)], $this->xaddMaxLength, true);
187+
)], $this->maxEntries, true);
188188
} else {
189189
$added = $this->connection->xadd($this->stream, '*', ['message' => json_encode(
190190
['body' => $body, 'headers' => $headers]

0 commit comments

Comments
 (0)