From c536f24555800a9d4f958276d3cbbd989a4d595c Mon Sep 17 00:00:00 2001 From: Carlos Buenosvinos Date: Sat, 9 Apr 2022 09:04:50 +0200 Subject: [PATCH] [Event Sourcing] Making Progress --- src/Cheeper/Chapter9/DomainModel/EventStore.php | 3 --- .../Infrastructure/DomainModel/RedisEventStore.php | 11 +++-------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Cheeper/Chapter9/DomainModel/EventStore.php b/src/Cheeper/Chapter9/DomainModel/EventStore.php index 14a7be3..c5f98d4 100644 --- a/src/Cheeper/Chapter9/DomainModel/EventStore.php +++ b/src/Cheeper/Chapter9/DomainModel/EventStore.php @@ -9,8 +9,5 @@ interface EventStore { public function append(EventStream $eventStream): void; public function getEventsFor(string $id): EventStream; - - public function fromVersion(string $id, int $version): EventStream; - public function countEventsFor(string $id): int; } //end-snippet \ No newline at end of file diff --git a/src/Cheeper/Chapter9/Infrastructure/DomainModel/RedisEventStore.php b/src/Cheeper/Chapter9/Infrastructure/DomainModel/RedisEventStore.php index bc7fc3b..ebf4833 100644 --- a/src/Cheeper/Chapter9/Infrastructure/DomainModel/RedisEventStore.php +++ b/src/Cheeper/Chapter9/Infrastructure/DomainModel/RedisEventStore.php @@ -48,12 +48,12 @@ class RedisEventStore implements EventStore public function getEventsFor(string $id): EventStream { - return $this->fromVersion($id, 0); + return $this->fromVersion($id); } - public function fromVersion(string $id, int $version): EventStream + private function fromVersion(string $id, int $version = 0): EventStream { - $serializedEvents = (array) $this->redis->lrange( + $serializedEvents = $this->redis->lrange( 'events:' . $id, $version, -1 @@ -74,10 +74,5 @@ class RedisEventStore implements EventStore return new EventStream($id, $events); } - - public function countEventsFor(string $id): int - { - return (int) $this->redis->llen('events:' . $id); - } } //end-snippet \ No newline at end of file