gpt4 book ai didi

c# - 使用 StackExchange 库从 Windows 上的 C# 连接到 Redis 时出错

转载 作者:可可西里 更新时间:2023-11-01 11:28:06 24 4
gpt4 key购买 nike

我正在尝试使用 StackExchange library 在 C# 中连接到 Windows 上的 Redis但出现错误:

StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: HMSET user:user1; SocketFailure on localhost:6379/Subscription, origin: Error, input-buffer: 0, outstanding: 0, last-read: 0s ago, last-write: 0s ago, unanswered-write: 7979s ago, keep-alive: 60s, pending: 0, state: Connecting, last-heartbeat: never, last-mbeat: -1s ago, global: 1s ago

我的代码是这样的:

class RedisConnectionFactory
{
private static readonly Lazy<ConnectionMultiplexer> Connection;

private static Lazy<ConfigurationOptions> configurationOptions = new Lazy<ConfigurationOptions>(() =>
{
var configurationOptions = new ConfigurationOptions();
configurationOptions.EndPoints.Add("127.0.0.1", 6379);
configurationOptions.Password = "<PASS>";
configurationOptions.ClientName = "JakubStompor";
configurationOptions.AbortOnConnectFail = false;
configurationOptions.Ssl = false;
configurationOptions.ConnectTimeout = 1000;
configurationOptions.SyncTimeout = 3000;
return configurationOptions;
});

static RedisConnectionFactory()
{
Connection = new Lazy<ConnectionMultiplexer>(
() => ConnectionMultiplexer.Connect(configurationOptions.Value)
);
}
public static ConnectionMultiplexer GetConnection() => Connection.Value;
}

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var conn = RedisConnectionFactory.GetConnection();
IDatabase db = conn.GetDatabase();
db.HashSet("user:user1", new HashEntry[] { new HashEntry("12", "13"), new HashEntry("14", "15") });
}
}

我已经运行了 redis 服务器,我可以使用命令行进行连接。

最佳答案

您的 ConnectTimeout 会不会太短了?您可以尝试将其增加到 5000 或更多,看看是否有帮助吗?

configurationOptions.ConnectTimeout = 1000;

关于c# - 使用 StackExchange 库从 Windows 上的 C# 连接到 Redis 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43698575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com