Skip to content

Commit d089310

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4237' into PR_2025_10_01_flowers
2 parents b412a5c + 7c01ddd commit d089310

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

lib/internal/Magento/Framework/App/Backpressure/SlidingWindow/RedisRequestLogger.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -61,6 +61,7 @@ public function __construct(
6161
public function incrAndGetFor(ContextInterface $context, int $timeSlot, int $discardAfter): int
6262
{
6363
$id = $this->generateId($context, $timeSlot);
64+
$this->redisClient->pipeline();
6465
$this->redisClient->incrBy($id, 1);
6566
$this->redisClient->expireAt($id, time() + $discardAfter);
6667

lib/internal/Magento/Framework/App/Backpressure/SlidingWindow/RedisRequestLogger/RedisClient.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -68,16 +68,14 @@ class RedisClient
6868
/**
6969
* @var Credis_Client
7070
*/
71-
private $pipeline;
71+
private $client;
7272

7373
/**
7474
* @param DeploymentConfig $config
75-
* @throws FileSystemException
76-
* @throws RuntimeException
7775
*/
7876
public function __construct(DeploymentConfig $config)
7977
{
80-
$credisClient = new Credis_Client(
78+
$this->client = new Credis_Client(
8179
$this->getHost($config),
8280
$this->getPort($config),
8381
$this->getTimeout($config),
@@ -86,8 +84,6 @@ public function __construct(DeploymentConfig $config)
8684
$this->getPassword($config),
8785
$this->getUser($config)
8886
);
89-
90-
$this->pipeline = $credisClient->pipeline();
9187
}
9288

9389
/**
@@ -99,7 +95,7 @@ public function __construct(DeploymentConfig $config)
9995
*/
10096
public function incrBy(string $key, int $decrement)
10197
{
102-
return $this->pipeline->incrBy($key, $decrement);
98+
return $this->client->incrBy($key, $decrement);
10399
}
104100

105101
/**
@@ -111,7 +107,7 @@ public function incrBy(string $key, int $decrement)
111107
*/
112108
public function expireAt(string $key, int $timestamp)
113109
{
114-
return $this->pipeline->expireAt($key, $timestamp);
110+
return $this->client->expireAt($key, $timestamp);
115111
}
116112

117113
/**
@@ -122,7 +118,17 @@ public function expireAt(string $key, int $timestamp)
122118
*/
123119
public function get(string $key)
124120
{
125-
return $this->pipeline->get($key);
121+
return $this->client->get($key);
122+
}
123+
124+
/**
125+
* Start pipeline
126+
*
127+
* @return void
128+
*/
129+
public function pipeline(): void
130+
{
131+
$this->client->pipeline();
126132
}
127133

128134
/**
@@ -132,7 +138,7 @@ public function get(string $key)
132138
*/
133139
public function exec(): array
134140
{
135-
return $this->pipeline->exec();
141+
return $this->client->exec();
136142
}
137143

138144
/**

lib/internal/Magento/Framework/App/Test/Unit/Backpressure/SlidingWindow/RedisRequestLoggerTest.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Framework\App\Test\Unit\Backpressure\SlidingWindow;
@@ -67,11 +66,16 @@ public function testIncrAndGetFor()
6766
{
6867
$expectedId = 'custompref_typeId_2_identity_400';
6968

70-
$this->redisClientMock->method('incrBy')
69+
$this->redisClientMock->expects(self::once())
70+
->method('pipeline');
71+
$this->redisClientMock->expects(self::once())
72+
->method('incrBy')
7173
->with($expectedId, 1);
72-
$this->redisClientMock->method('expireAt')
74+
$this->redisClientMock->expects(self::once())
75+
->method('expireAt')
7376
->with($expectedId, time() + 500);
74-
$this->redisClientMock->method('exec')
77+
$this->redisClientMock->expects(self::once())
78+
->method('exec')
7579
->willReturn(['45']);
7680

7781
self::assertEquals(
@@ -83,9 +87,10 @@ public function testIncrAndGetFor()
8387
public function testGetFor()
8488
{
8589
$expectedId = 'custompref_typeId_2_identity_600';
86-
$this->redisClientMock->method('get')
87-
->with($expectedId)
88-
->willReturn('23');
90+
$this->redisClientMock->expects(self::once())
91+
->method('get')
92+
->with($expectedId)
93+
->willReturn('23');
8994

9095
self::assertEquals(23, $this->redisRequestLogger->getFor($this->contextMock, 600));
9196
}

0 commit comments

Comments
 (0)