Skip to content

Commit 50b752b

Browse files
ekonduremrahkondur
andauthored
#34 Added Configuration Options to Settings (#35)
Co-authored-by: Emrah Kondur <emrah.kondur@invicti.com>
1 parent 45f3404 commit 50b752b

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

IUTest/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using IUTest;
22
using RedisUI;
3+
using StackExchange.Redis;
34

45
var builder = WebApplication.CreateBuilder(args);
56

@@ -22,9 +23,15 @@
2223

2324
app.UseRouting();
2425

26+
ConfigurationOptions options = new ConfigurationOptions
27+
{
28+
EndPoints = { { "localhost", 6379 } },
29+
};
30+
2531
app.UseRedisUI(new RedisUISettings
2632
{
27-
AuthorizationFilter = new FooAuthorizationFilter(app.Environment.IsDevelopment())
33+
AuthorizationFilter = new FooAuthorizationFilter(app.Environment.IsDevelopment()),
34+
//ConfigurationOptions = options
2835
});
2936

3037
app.UseAuthorization();

RedisUI/Models/RedisUISettings.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace RedisUI
1+
using StackExchange.Redis;
2+
3+
namespace RedisUI
24
{
35
public class RedisUISettings
46
{
@@ -7,6 +9,11 @@ public class RedisUISettings
79
/// </summary>
810
public string ConnectionString { get; set; } = "localhost";
911

12+
/// <summary>
13+
/// Gets or sets the ConfigurationOptions instance.
14+
/// </summary>
15+
public ConfigurationOptions ConfigurationOptions { get; set; }
16+
1017
/// <summary>
1118
/// Gets or sets the path for the Redis server.
1219
/// </summary>

RedisUI/RedisUIMiddleware.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ public async Task InvokeAsync(HttpContext context)
3737
var db = context.Request.Query["db"].ToString();
3838
int currentDb = string.IsNullOrEmpty(db) ? 0 : int.Parse(db);
3939

40-
IDatabase redisDb = ConnectionMultiplexer.Connect(_settings.ConnectionString).GetDatabase(currentDb);
40+
IDatabase redisDb;
41+
42+
if (_settings.ConfigurationOptions != null)
43+
{
44+
redisDb = ConnectionMultiplexer.Connect(_settings.ConfigurationOptions).GetDatabase(currentDb);
45+
}
46+
else
47+
{
48+
redisDb = ConnectionMultiplexer.Connect(_settings.ConnectionString).GetDatabase(currentDb);
49+
}
4150

4251
var dbSize = await redisDb.ExecuteAsync("DBSIZE");
4352

0 commit comments

Comments
 (0)