Skip to content

IRedisConnectionProvider interface #250

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

Merged
merged 4 commits into from
Dec 8, 2022
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
* [@Zulander1](https://github.com/zulander1)
* [@Jeevananthan](https://github.com/Jeevananthan-23)
* [@mariusmuntean](https://github.com/mariusmuntean)
* [@jcreus1](https://github.com/jcreus1)

<!-- Logo -->
[Logo]: images/logo.svg
Expand Down
9 changes: 5 additions & 4 deletions src/Redis.OM.AspNetCore/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Redis.OM;
using Microsoft.Extensions.DependencyInjection;
using Redis.OM.Contracts;

namespace Redis.OM.AspNetCore
{
Expand All @@ -11,13 +12,13 @@ public static IServiceCollection AddRedis(this IServiceCollection services,
string connectionString)
{
var provider = new RedisConnectionProvider(connectionString);
return services.AddSingleton(provider);
return services.AddSingleton<IRedisConnectionProvider>(provider);
}

public static IServiceCollection AddRedis(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration["REDIS_CONNECTION_STRING"];
return services.AddSingleton(new RedisConnectionProvider(connectionString));
return services.AddSingleton<IRedisConnectionProvider>(new RedisConnectionProvider(connectionString));
}
}
}
}
43 changes: 43 additions & 0 deletions src/Redis.OM/Contracts/IRedisConnectionProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Redis.OM.Aggregation;
using Redis.OM.Searching;

namespace Redis.OM.Contracts
{
/// <summary>
/// Provides a connection to redis.
/// </summary>
public interface IRedisConnectionProvider
{
/// <summary>
/// Gets a command level interface to redis.
/// </summary>
IRedisConnection Connection { get; }

/// <summary>
/// Gets an aggregation set for redis.
/// </summary>
/// <typeparam name="T">The indexed type to run aggregations on.</typeparam>
/// <param name="chunkSize">Size of chunks to use during pagination, larger chunks = larger payloads returned but fewer round trips.</param>
/// <returns>the aggregation set.</returns>
RedisAggregationSet<T> AggregationSet<T>(int chunkSize = 100);

/// <summary>
/// Gets a redis collection.
/// </summary>
/// <typeparam name="T">The type the collection will be retrieving.</typeparam>
/// <param name="chunkSize">Size of chunks to use during pagination, larger chunks = larger payloads returned but fewer round trips.</param>
/// <returns>A RedisCollection.</returns>
IRedisCollection<T> RedisCollection<T>(int chunkSize = 100)
where T : notnull;

/// <summary>
/// Gets a redis collection.
/// </summary>
/// <typeparam name="T">The type the collection will be retrieving.</typeparam>
/// <param name="saveState">Whether or not the RedisCollection should maintain the state of documents it enumerates.</param>
/// <param name="chunkSize">Size of chunks to use during pagination, larger chunks = larger payloads returned but fewer round trips.</param>
/// <returns>A RedisCollection.</returns>
IRedisCollection<T> RedisCollection<T>(bool saveState, int chunkSize = 100)
where T : notnull;
}
}
2 changes: 1 addition & 1 deletion src/Redis.OM/RedisConnectionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Redis.OM
/// <summary>
/// Provides a connection to redis.
/// </summary>
public class RedisConnectionProvider
public class RedisConnectionProvider : IRedisConnectionProvider
{
private readonly IConnectionMultiplexer _mux;

Expand Down