[Event Sourcing] Making Progress

This commit is contained in:
Carlos Buenosvinos
2022-04-09 09:04:50 +02:00
parent 0e0dc32919
commit c536f24555
2 changed files with 3 additions and 11 deletions

View File

@@ -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

View File

@@ -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