Skip to content

Commit 6745e2b

Browse files
authored
IRedisConnectionProvider interface (#250)
1 parent b5c3634 commit 6745e2b

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
359359
* [@Zulander1](https://github.com/zulander1)
360360
* [@Jeevananthan](https://github.com/Jeevananthan-23)
361361
* [@mariusmuntean](https://github.com/mariusmuntean)
362+
* [@jcreus1](https://github.com/jcreus1)
362363

363364
<!-- Logo -->
364365
[Logo]: images/logo.svg
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
22
using Microsoft.Extensions.Configuration;
33
using Redis.OM;
44
using Microsoft.Extensions.DependencyInjection;
5+
using Redis.OM.Contracts;
56

67
namespace Redis.OM.AspNetCore
78
{
@@ -11,13 +12,13 @@ public static IServiceCollection AddRedis(this IServiceCollection services,
1112
string connectionString)
1213
{
1314
var provider = new RedisConnectionProvider(connectionString);
14-
return services.AddSingleton(provider);
15+
return services.AddSingleton<IRedisConnectionProvider>(provider);
1516
}
1617

1718
public static IServiceCollection AddRedis(this IServiceCollection services, IConfiguration configuration)
1819
{
1920
var connectionString = configuration["REDIS_CONNECTION_STRING"];
20-
return services.AddSingleton(new RedisConnectionProvider(connectionString));
21+
return services.AddSingleton<IRedisConnectionProvider>(new RedisConnectionProvider(connectionString));
2122
}
2223
}
23-
}
24+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Redis.OM.Aggregation;
2+
using Redis.OM.Searching;
3+
4+
namespace Redis.OM.Contracts
5+
{
6+
/// <summary>
7+
/// Provides a connection to redis.
8+
/// </summary>
9+
public interface IRedisConnectionProvider
10+
{
11+
/// <summary>
12+
/// Gets a command level interface to redis.
13+
/// </summary>
14+
IRedisConnection Connection { get; }
15+
16+
/// <summary>
17+
/// Gets an aggregation set for redis.
18+
/// </summary>
19+
/// <typeparam name="T">The indexed type to run aggregations on.</typeparam>
20+
/// <param name="chunkSize">Size of chunks to use during pagination, larger chunks = larger payloads returned but fewer round trips.</param>
21+
/// <returns>the aggregation set.</returns>
22+
RedisAggregationSet<T> AggregationSet<T>(int chunkSize = 100);
23+
24+
/// <summary>
25+
/// Gets a redis collection.
26+
/// </summary>
27+
/// <typeparam name="T">The type the collection will be retrieving.</typeparam>
28+
/// <param name="chunkSize">Size of chunks to use during pagination, larger chunks = larger payloads returned but fewer round trips.</param>
29+
/// <returns>A RedisCollection.</returns>
30+
IRedisCollection<T> RedisCollection<T>(int chunkSize = 100)
31+
where T : notnull;
32+
33+
/// <summary>
34+
/// Gets a redis collection.
35+
/// </summary>
36+
/// <typeparam name="T">The type the collection will be retrieving.</typeparam>
37+
/// <param name="saveState">Whether or not the RedisCollection should maintain the state of documents it enumerates.</param>
38+
/// <param name="chunkSize">Size of chunks to use during pagination, larger chunks = larger payloads returned but fewer round trips.</param>
39+
/// <returns>A RedisCollection.</returns>
40+
IRedisCollection<T> RedisCollection<T>(bool saveState, int chunkSize = 100)
41+
where T : notnull;
42+
}
43+
}

src/Redis.OM/RedisConnectionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Redis.OM
88
/// <summary>
99
/// Provides a connection to redis.
1010
/// </summary>
11-
public class RedisConnectionProvider
11+
public class RedisConnectionProvider : IRedisConnectionProvider
1212
{
1313
private readonly IConnectionMultiplexer _mux;
1414

0 commit comments

Comments
 (0)