src/Library/NetPro.StackExchange.Redis/StackExchange.Redis.Extensions.Core/ServerIteration/ServerEnumerable.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using StackExchange.Redis.Extensions.Core.Configuration;
using System.Collections;
using System.Collections.Generic;
namespace StackExchange.Redis.Extensions.Core.ServerIteration
{
/// <summary>
/// The class that allows you to enumerate all the redis servers.
/// </summary>
public class ServerEnumerable : IEnumerable<IServer>
{
private readonly IConnectionMultiplexer multiplexer;
private readonly ServerEnumerationStrategy.TargetRoleOptions targetRole;
private readonly ServerEnumerationStrategy.UnreachableServerActionOptions unreachableServerAction;
/// <summary>
/// Initializes a new instance of the <see cref="ServerEnumerable"/> class.
/// </summary>
/// <param name="multiplexer">The redis connection.</param>
/// <param name="targetRole">The target role.</param>
/// <param name="unreachableServerAction">The unreachable server strategy.</param>
public ServerEnumerable(
IConnectionMultiplexer multiplexer,
ServerEnumerationStrategy.TargetRoleOptions targetRole,
ServerEnumerationStrategy.UnreachableServerActionOptions unreachableServerAction)
{
this.multiplexer = multiplexer;
this.targetRole = targetRole;
this.unreachableServerAction = unreachableServerAction;
}
/// <summary>
/// Return the enumerator of the Redis servers
/// </summary>
public IEnumerator<IServer> GetEnumerator()
{
foreach (var endPoint in multiplexer.GetEndPoints())
{
var server = multiplexer.GetServer(endPoint);
if (targetRole == ServerEnumerationStrategy.TargetRoleOptions.PreferSlave)
{
if (!server.IsReplica)
continue;
}
if (unreachableServerAction == ServerEnumerationStrategy.UnreachableServerActionOptions.IgnoreIfOtherAvailable)
{
if (!server.IsConnected || !server.Features.Scan)
continue;
}
yield return server;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
后面还有 1 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。