Microsoft.AspNetCore.SignalR.Redis API review (#2036)
This commit is contained in:
parent
b3a9011698
commit
0da06fb5d2
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
|
|||
var protocols = GenerateProtocols(ProtocolCount).ToArray();
|
||||
var options = Options.Create(new RedisOptions()
|
||||
{
|
||||
Factory = _ => Task.FromResult<IConnectionMultiplexer>(new TestConnectionMultiplexer(server))
|
||||
ConnectionFactory = _ => Task.FromResult<IConnectionMultiplexer>(new TestConnectionMultiplexer(server))
|
||||
});
|
||||
var resolver = new DefaultHubProtocolResolver(protocols, NullLogger<DefaultHubProtocolResolver>.Instance);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace ChatSample
|
|||
{
|
||||
// TODO: handle connection failures
|
||||
_redisConnection = await ConnectToRedis(_options, _logger);
|
||||
_redisDatabase = _redisConnection.GetDatabase(_options.Options.DefaultDatabase.GetValueOrDefault());
|
||||
_redisDatabase = _redisConnection.GetDatabase(_options.Configuration.DefaultDatabase.GetValueOrDefault());
|
||||
|
||||
// Register connection
|
||||
_redisDatabase.SetAdd(ServerIndexRedisKey, ServerId);
|
||||
|
|
@ -103,14 +103,14 @@ namespace ChatSample
|
|||
private static async Task<IConnectionMultiplexer> ConnectToRedis(RedisOptions options, ILogger logger)
|
||||
{
|
||||
var loggerTextWriter = new LoggerTextWriter(logger);
|
||||
if (options.Factory != null)
|
||||
if (options.ConnectionFactory != null)
|
||||
{
|
||||
return await options.Factory(loggerTextWriter);
|
||||
return await options.ConnectionFactory(loggerTextWriter);
|
||||
}
|
||||
|
||||
if (options.Options.EndPoints.Any())
|
||||
if (options.Configuration.EndPoints.Any())
|
||||
{
|
||||
return await ConnectionMultiplexer.ConnectAsync(options.Options, loggerTextWriter);
|
||||
return await ConnectionMultiplexer.ConnectAsync(options.Configuration, loggerTextWriter);
|
||||
}
|
||||
|
||||
var configurationOptions = new ConfigurationOptions();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ using MessagePack;
|
|||
using Microsoft.AspNetCore.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Redis.Internal
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
return AddRedis(builder, o =>
|
||||
{
|
||||
o.Options = ConfigurationOptions.Parse(redisConnectionString);
|
||||
o.Configuration = ConfigurationOptions.Parse(redisConnectionString);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
return AddRedis(builder, o =>
|
||||
{
|
||||
o.Options = ConfigurationOptions.Parse(redisConnectionString);
|
||||
o.Configuration = ConfigurationOptions.Parse(redisConnectionString);
|
||||
configure(o);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
|||
_channels = new RedisChannels(typeof(THub).FullName);
|
||||
_protocol = new RedisProtocol(hubProtocolResolver.AllProtocols);
|
||||
|
||||
RedisLog.ConnectingToEndpoints(_logger, options.Value.Options.EndPoints, _serverName);
|
||||
RedisLog.ConnectingToEndpoints(_logger, options.Value.Configuration.EndPoints, _serverName);
|
||||
_ = EnsureRedisServerConnection();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,31 +11,31 @@ namespace Microsoft.AspNetCore.SignalR.Redis
|
|||
{
|
||||
public class RedisOptions
|
||||
{
|
||||
public ConfigurationOptions Options { get; set; } = new ConfigurationOptions
|
||||
public ConfigurationOptions Configuration { get; set; } = new ConfigurationOptions
|
||||
{
|
||||
// Enable reconnecting by default
|
||||
AbortOnConnectFail = false
|
||||
};
|
||||
|
||||
public Func<TextWriter, Task<IConnectionMultiplexer>> Factory { get; set; }
|
||||
public Func<TextWriter, Task<IConnectionMultiplexer>> ConnectionFactory { get; set; }
|
||||
|
||||
internal async Task<IConnectionMultiplexer> ConnectAsync(TextWriter log)
|
||||
{
|
||||
// Factory is publically settable. Assigning to a local variable before null check for thread safety.
|
||||
var localFactory = Factory;
|
||||
if (localFactory == null)
|
||||
var factory = ConnectionFactory;
|
||||
if (factory == null)
|
||||
{
|
||||
// REVIEW: Should we do this?
|
||||
if (Options.EndPoints.Count == 0)
|
||||
if (Configuration.EndPoints.Count == 0)
|
||||
{
|
||||
Options.EndPoints.Add(IPAddress.Loopback, 0);
|
||||
Options.SetDefaultPorts();
|
||||
Configuration.EndPoints.Add(IPAddress.Loopback, 0);
|
||||
Configuration.SetDefaultPorts();
|
||||
}
|
||||
|
||||
return await ConnectionMultiplexer.ConnectAsync(Options, log);
|
||||
return await ConnectionMultiplexer.ConnectAsync(Configuration, log);
|
||||
}
|
||||
|
||||
return await localFactory(log);
|
||||
return await factory(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,16 +26,16 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
|||
|
||||
var options = provider.GetService<IOptions<RedisOptions>>();
|
||||
Assert.NotNull(options.Value);
|
||||
Assert.NotNull(options.Value.Options);
|
||||
Assert.Equal(password, options.Value.Options.Password);
|
||||
Assert.Collection(options.Value.Options.EndPoints,
|
||||
Assert.NotNull(options.Value.Configuration);
|
||||
Assert.Equal(password, options.Value.Configuration.Password);
|
||||
Assert.Collection(options.Value.Configuration.EndPoints,
|
||||
endpoint =>
|
||||
{
|
||||
var dnsEndpoint = Assert.IsType<DnsEndPoint>(endpoint);
|
||||
Assert.Equal(host, dnsEndpoint.Host);
|
||||
Assert.Equal(port, dnsEndpoint.Port);
|
||||
});
|
||||
Assert.Equal(useSsl, options.Value.Options.Ssl);
|
||||
Assert.Equal(useSsl, options.Value.Configuration.Ssl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -550,7 +550,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
|||
|
||||
private RedisHubLifetimeManager<MyHub> CreateLifetimeManager(TestRedisServer server, MessagePackHubProtocolOptions messagePackOptions = null, JsonHubProtocolOptions jsonOptions = null)
|
||||
{
|
||||
var options = new RedisOptions() { Factory = async (t) => await Task.FromResult(new TestConnectionMultiplexer(server)) };
|
||||
var options = new RedisOptions() { ConnectionFactory = async (t) => await Task.FromResult(new TestConnectionMultiplexer(server)) };
|
||||
messagePackOptions = messagePackOptions ?? new MessagePackHubProtocolOptions();
|
||||
jsonOptions = jsonOptions ?? new JsonHubProtocolOptions();
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis.Tests
|
|||
.AddRedis(options =>
|
||||
{
|
||||
// We start the servers before starting redis so we want to time them out ASAP
|
||||
options.Options.ConnectTimeout = 1;
|
||||
options.Configuration.ConnectTimeout = 1;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue