Skip to content

Commit 1312548

Browse files
committed
Cleanup for qa
1 parent 6011609 commit 1312548

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

packages/http/src/Session/Config/RedisSessionConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class RedisSessionConfig implements SessionConfig
1616
*/
1717
public function __construct(
1818
private(set) Duration $expiration,
19-
private(set) string $prefix = 'session',
19+
private(set) string $prefix = 'session:',
2020
) {}
2121

2222
public function createManager(Container $container): RedisSessionManager

packages/http/src/Session/Managers/RedisSessionManager.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,16 @@ private function persist(SessionId $id, ?array $data = null): Session
120120

121121
private function getKey(SessionId $id): string
122122
{
123-
return sprintf('%s_%s', $this->sessionConfig->prefix, $id);
123+
return sprintf('%s%s', $this->sessionConfig->prefix, $id);
124124
}
125125

126126
private function getSessionIdFromKey(string $key): SessionId
127127
{
128-
return new SessionId(new ImmutableString($key)->afterFirst('_')->toString());
128+
return new SessionId(
129+
new ImmutableString($key)
130+
->afterFirst($this->sessionConfig->prefix)
131+
->toString(),
132+
);
129133
}
130134

131135
public function cleanup(): void
@@ -135,17 +139,16 @@ public function cleanup(): void
135139
do {
136140
$result = $this->redis->command('SCAN', $cursor, 'MATCH', $this->getKey(new SessionId('*')), 'COUNT', '100');
137141
$cursor = $result[0];
138-
142+
ld($result);
139143
foreach ($result[1] as $key) {
140144
$sessionId = $this->getSessionIdFromKey($key);
141145

142146
if ($this->isValid($sessionId)) {
143147
continue;
144148
}
145149

146-
$this->destroy($sessionId);
150+
$this->destroy($sessionId);
147151
}
148-
149-
} while( $cursor != '0');
152+
} while ($cursor !== '0');
150153
}
151154
}

tests/Integration/Http/RedisSessionTest.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp(): void
3131
$this->container->config(new RedisSessionConfig(expiration: Duration::hours(2)));
3232
$this->container->singleton(
3333
SessionManager::class,
34-
fn() => new RedisSessionManager(
34+
fn () => new RedisSessionManager(
3535
$this->container->get(Clock::class),
3636
$this->container->get(Redis::class),
3737
$this->container->get(SessionConfig::class),
@@ -242,7 +242,7 @@ private function assertSessionExistsInDatabase(SessionId $sessionId): void
242242
{
243243
$session = $this->getSessionFromDatabase($sessionId);
244244

245-
$this->assertNotNull($session, "Session {$sessionId} should not exist in database");
245+
$this->assertNotNull($session, "Session {$sessionId} should exist in database");
246246
}
247247

248248
private function assertSessionNotExistsInDatabase(SessionId $sessionId): void
@@ -252,17 +252,6 @@ private function assertSessionNotExistsInDatabase(SessionId $sessionId): void
252252
$this->assertNull($session, "Session {$sessionId} should not exist in database");
253253
}
254254

255-
private function assertSessionDataInDatabase(SessionId $sessionId, array $data): void
256-
{
257-
$session = $this->getSessionFromDatabase($sessionId);
258-
259-
$this->assertNotNull($session, "Session {$sessionId} should exist in database");
260-
261-
foreach ($data as $key => $value) {
262-
$this->assertEquals($value, $session->data[$key], "Session data key '{$key}' should match expected value");
263-
}
264-
}
265-
266255
private function getSessionLastActiveTimestamp(SessionId $sessionId): \Tempest\DateTime\DateTime
267256
{
268257
$session = $this->getSessionFromDatabase($sessionId);
@@ -272,16 +261,15 @@ private function getSessionLastActiveTimestamp(SessionId $sessionId): \Tempest\D
272261
return $session->lastActiveAt;
273262
}
274263

275-
276264
private function getSessionFromDatabase(SessionId $id): ?Session
277265
{
278266
$config = $this->container->get(SessionConfig::class);
279267
$redis = $this->container->get(Redis::class);
280268

281269
try {
282-
$content = $redis->get(sprintf('%s_%s', $config->prefix, $id));
270+
$content = $redis->get(sprintf('%s%s', $config->prefix, $id));
283271
return unserialize($content, ['allowed_classes' => true]);
284-
} catch (Throwable $e) {
272+
} catch (Throwable) {
285273
return null;
286274
}
287275
}

0 commit comments

Comments
 (0)