- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 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/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!