Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Redis release #1072

Draft
wants to merge 5 commits into
base: develop-v1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions EventFlow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.SQLite", "Source\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.SQLite.Tests", "Source\EventFlow.SQLite.Tests\EventFlow.SQLite.Tests.csproj", "{8FAC191C-340D-47C6-B8AE-3D57783749C4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Redis", "Redis", "{B1B5E6C8-1AB0-4848-9803-3CAF6A10F14C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.Redis", "Source\EventFlow.Redis\EventFlow.Redis.csproj", "{6B8E25D6-F7B8-4C2A-A956-8C87BF70D80C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventFlow.Redis.Tests", "Source\EventFlow.Redis.Tests\EventFlow.Redis.Tests.csproj", "{00DED999-173E-4518-81DC-2F1CFCE2F937}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -145,6 +151,14 @@ Global
{8FAC191C-340D-47C6-B8AE-3D57783749C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FAC191C-340D-47C6-B8AE-3D57783749C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FAC191C-340D-47C6-B8AE-3D57783749C4}.Release|Any CPU.Build.0 = Release|Any CPU
{6B8E25D6-F7B8-4C2A-A956-8C87BF70D80C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B8E25D6-F7B8-4C2A-A956-8C87BF70D80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B8E25D6-F7B8-4C2A-A956-8C87BF70D80C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B8E25D6-F7B8-4C2A-A956-8C87BF70D80C}.Release|Any CPU.Build.0 = Release|Any CPU
{00DED999-173E-4518-81DC-2F1CFCE2F937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00DED999-173E-4518-81DC-2F1CFCE2F937}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00DED999-173E-4518-81DC-2F1CFCE2F937}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00DED999-173E-4518-81DC-2F1CFCE2F937}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -175,6 +189,9 @@ Global
{74EFCDE2-CB0F-49B1-9CEC-BE748EB1FBF7} = {88359036-4F35-487C-BF2C-4F31C7BC92D8}
{D2B5B5CA-57C2-4354-ADB7-47A6D81AD521} = {74EFCDE2-CB0F-49B1-9CEC-BE748EB1FBF7}
{8FAC191C-340D-47C6-B8AE-3D57783749C4} = {74EFCDE2-CB0F-49B1-9CEC-BE748EB1FBF7}
{B1B5E6C8-1AB0-4848-9803-3CAF6A10F14C} = {5EE323DE-E69B-451A-8AC3-22DD6A004FBA}
{6B8E25D6-F7B8-4C2A-A956-8C87BF70D80C} = {B1B5E6C8-1AB0-4848-9803-3CAF6A10F14C}
{00DED999-173E-4518-81DC-2F1CFCE2F937} = {B1B5E6C8-1AB0-4848-9803-3CAF6A10F14C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17607E2C-4E8E-45A2-85BD-0A5808E1C0F3}
Expand Down
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
### New in 1.1.1 (working version, not released yet)

* New: NuGet `EventFlow.SQLite` is now released as part of v1 and enables support for SQLite
* New: NuGet `EventFlow.Redis` is now (properly) released as part of v1 and enables support for Redis
* Fix: Invoking `UseEventPersistence` now removes any previously registered event persistence. This
fixes a service ordering issue in the following event store configurations
- MongoDB
- MSSQL
- PostgreSQL


### New in 1.1.0 (released 2024-12-16)

* New: More control of event naming by introducing the interface `IEventNamingStrategy`, see the
Expand Down
27 changes: 13 additions & 14 deletions Source/EventFlow.Redis.Tests/EventFlow.Redis.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="StackExchange.Redis" Version="2.6.48" />
<PackageReference Include="Testcontainers" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Testcontainers" Version="2.1.0" />
</ItemGroup>

</Project>
15 changes: 8 additions & 7 deletions Source/EventFlow.Redis/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace EventFlow.Redis;

public static class Constants
namespace EventFlow.Redis
{
public const string StreamPrefix = "eventflow.events";
public const string ReadModelPrefix = "eventflow.readmodel";
public const string SnapshotPrefix = "eventflow.snapshot";
}
public static class Constants
{
public const string StreamPrefix = "eventflow.events";
public const string ReadModelPrefix = "eventflow.readmodel";
public const string SnapshotPrefix = "eventflow.snapshot";
}
}
37 changes: 21 additions & 16 deletions Source/EventFlow.Redis/EventFlow.Redis.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<Title>EventFlow.Redis</Title>
<Description>Async/await first CQRS+ES and DDD framework for .NET - https://docs.geteventflow.net/</Description>
<PackageTags>CQRS ES event sourcing Redis</PackageTags>
<PackageReleaseNotes>UPDATED BY BUILD</PackageReleaseNotes>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\EventFlow.Redis.xml</DocumentationFile>
<IsPackable>true</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow\EventFlow.csproj"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow\EventFlow.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Redis.OM" Version="0.7.6"/>
<PackageReference Include="StackExchange.Redis" Version="2.8.24"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Redis.OM" Version="0.2.1"/>
<PackageReference Include="StackExchange.Redis" Version="2.6.48"/>
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="EventFlow.Redis.Tests"/>
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="EventFlow.Redis.Tests"/>
</ItemGroup>

</Project>
65 changes: 33 additions & 32 deletions Source/EventFlow.Redis/EventStore/EventStreamCollectionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,42 @@

using StackExchange.Redis;

namespace EventFlow.Redis.EventStore;

internal class EventStreamCollectionResolver : IEventStreamCollectionResolver
namespace EventFlow.Redis.EventStore
{
private readonly IConnectionMultiplexer _multiplexer;

public EventStreamCollectionResolver(IConnectionMultiplexer multiplexer)
internal class EventStreamCollectionResolver : IEventStreamCollectionResolver
{
_multiplexer = multiplexer;
}
private readonly IConnectionMultiplexer _multiplexer;

// Using https://redis.io/commands/scan/ instead of KEYS to reduce blocking on the server.
public async Task<IReadOnlyCollection<PrefixedKey>> GetStreamIdsAsync(CancellationToken cancellationToken = default)
{
var cursor = 0;
var names = new List<PrefixedKey>();
do
public EventStreamCollectionResolver(IConnectionMultiplexer multiplexer)
{
var result = await _multiplexer
.GetDatabase()
.ExecuteAsync("scan", cursor, "MATCH", $"{Constants.StreamPrefix}*")
.ConfigureAwait(false);

var arr = (RedisResult[]) result;
cursor = (int) arr[0];
var prefixedKeys = ((RedisResult[]) arr[1]).Select(n => AsPrefixedKey((string) n));
names.AddRange(prefixedKeys);
} while (cursor != 0);
_multiplexer = multiplexer;
}

return names;
}

private static PrefixedKey AsPrefixedKey(string k)
{
var split = k.Split(':');
return new PrefixedKey(split[0], split[1]);
// Using https://redis.io/commands/scan/ instead of KEYS to reduce blocking on the server.
public async Task<IReadOnlyCollection<PrefixedKey>> GetStreamIdsAsync(CancellationToken cancellationToken = default)
{
var cursor = 0;
var names = new List<PrefixedKey>();
do
{
var result = await _multiplexer
.GetDatabase()
.ExecuteAsync("scan", cursor, "MATCH", $"{Constants.StreamPrefix}*")
.ConfigureAwait(false);

var arr = (RedisResult[])result;
cursor = (int)arr[0];
var prefixedKeys = ((RedisResult[])arr[1]).Select(n => AsPrefixedKey((string)n));
names.AddRange(prefixedKeys);
} while (cursor != 0);

return names;
}

private static PrefixedKey AsPrefixedKey(string k)
{
var split = k.Split(':');
return new PrefixedKey(split[0], split[1]);
}
}
}
}
21 changes: 11 additions & 10 deletions Source/EventFlow.Redis/EventStore/IEventStreamCollectionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace EventFlow.Redis.EventStore;

internal interface IEventStreamCollectionResolver
namespace EventFlow.Redis.EventStore
{
/// <summary>
/// Returns the ids of all streams (aggregates) used by eventflow.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IReadOnlyCollection<PrefixedKey>> GetStreamIdsAsync(CancellationToken cancellationToken = default);
}
internal interface IEventStreamCollectionResolver
{
/// <summary>
/// Returns the ids of all streams (aggregates) used by EventFlow.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IReadOnlyCollection<PrefixedKey>> GetStreamIdsAsync(CancellationToken cancellationToken = default);
}
}
33 changes: 19 additions & 14 deletions Source/EventFlow.Redis/EventStore/RedisCommittedDomainEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,25 @@

using EventFlow.EventStores;

namespace EventFlow.Redis.EventStore;

internal class RedisCommittedDomainEvent : ICommittedDomainEvent
namespace EventFlow.Redis.EventStore
{
public RedisCommittedDomainEvent(string aggregateId, string data, string metadata, int aggregateSequenceNumber)
internal class RedisCommittedDomainEvent : ICommittedDomainEvent
{
AggregateId = aggregateId;
Data = data;
Metadata = metadata;
AggregateSequenceNumber = aggregateSequenceNumber;
}
public RedisCommittedDomainEvent(
string aggregateId,
string data,
string metadata,
int aggregateSequenceNumber)
{
AggregateId = aggregateId;
Data = data;
Metadata = metadata;
AggregateSequenceNumber = aggregateSequenceNumber;
}

public string AggregateId { get; init; }
public string Data { get; init; }
public string Metadata { get; init; }
public int AggregateSequenceNumber { get; init; }
}
public string AggregateId { get; }
public string Data { get; }
public string Metadata { get; }
public int AggregateSequenceNumber { get; }
}
}
Loading
Loading