- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何使用 StackExchange.Redis ConnectionMultiplexer 而不是 BookSleeve ConnectionUtils 连接到 Redis sentinel。
我目前正在使用 BookSleeve:
ConnectionUtils.Connect("127.0.0.1:26379,serviceName=mymaster");
我尝试用 StackExchange.Redis 替换它:ConnectionMultiplexer.Connect("127.0.0.1:26379,serviceName=mymaster");
但它不起作用。
有什么想法吗?
最佳答案
这不是真正的答案,但我希望对您有所帮助,我将 REDIS Sentinel 与 ServiceStack.Redis 结合使用,我没有找到使用免费 StackExchange.Redis 的解决方案来使用 Sentinel。这是我使用 ServiceStack 的代码:
using ServiceStack.Redis;
private static IRedisClientsManager GetRedisSentinel()
{
IRedisClientsManager redisManager = null;
try
{
List<string> listSentinels = new List<string>();
listSentinels.Add(ConfigurationManager.AppSettings["RedisDB1"]);
listSentinels.Add(ConfigurationManager.AppSettings["RedisDB2"]);
listSentinels.Add(ConfigurationManager.AppSettings["RedisDB3"]);
listSentinels.Add(ConfigurationManager.AppSettings["RedisDB4"]);
RedisSentinel redisSentinel = new RedisSentinel(listSentinels, ConfigurationManager.AppSettings["RedisMaster"]);
redisSentinel.SentinelWorkerConnectTimeoutMs = 500;
redisManager = redisSentinel.Start();
}
catch (Exception ex)
{
_log.Trace(ex, "Error Redis Connection: " + ex.Message);
}
return redisManager;
}
public static object GetRedisCache<T>(string key)
{
object myObject = null;
//naming convention [PLATFORM]:[PROJECT]:[FUNCTION]:[PARAMETERS…]
string redisKey = string.Format("WEB:MyProject:{0}:{1}", typeof(T), key);
//Open Redis
IRedisClientsManager redisManager = GetRedisSentinel();
if (redisManager != null)
{
try
{
using (RedisClient redis = (RedisClient)redisManager.GetClient())
{
//Redis and Object connection
var redisGateways = redis.As<T>();
//Check if the object exists with the key
myObject = redisGateways.GetValue(redisKey);
}
}
catch (Exception ex)
{
_log.Trace(ex, "Error Get In Redis: " + ex.Message);
}
}
return myObject;
}
public static void SaveRedisCache<T>(object myObject, string key, DateTime? expireDateTime = null)
{
if (expireDateTime == null)
expireDateTime = DateTime.Now.AddMinutes(20);
//naming convention [PLATFORM]:[PROJECT]:[FUNCTION]:[PARAMETERS…]
string redisKey = string.Format("WEB:MyProject:{0}:{1}", typeof(T), key);
if (myObject != null)
{
//Open Redis
IRedisClientsManager redisManager = GetRedisSentinel();
if (redisManager != null)
{
try
{
using (RedisClient redis = (RedisClient)redisManager.GetClient())
{
//Redis and Object connection
var redisGateways = redis.As<T>();
//Store in Redis and put 20 minutes as expire
bool isExists = redisGateways.SetEntryIfNotExists(redisKey, (T)myObject);
if (isExists)
redisGateways.ExpireEntryAt(redisKey, (DateTime)expireDateTime);
else
redisGateways.SetEntry(redisKey, (T)myObject); //Update
}
}
catch (Exception ex)
{
_log.Trace(ex, "Error Save In Redis: " + ex.Message);
}
}
}
}
public static void EraseRedisCache<T>(string key)
{
//naming convention [PLATFORM]:[PROJECT]:[FUNCTION]:[PARAMETERS…]
string redisKey = string.Format("WEB:MyProject:{0}:{1}", typeof(T), key);
//Open Redis
IRedisClientsManager redisManager = GetRedisSentinel();
if (redisManager != null)
{
try
{
using (RedisClient redis = (RedisClient)redisManager.GetClient())
{
//Redis and Object connection
var redisGateways = redis.As<T>();
redisGateways.RemoveEntry(redisKey);
}
}
catch (Exception ex)
{
_log.Trace(ex, "Error Remove In Redis: " + ex.Message);
}
}
}
关于c# - 使用 StackExchange.Redis ConnectionMultiplexer 而不是 BookSleeve ConnectionUtils 连接到 Redis sentinel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23503424/
我是 Redis 和 BookSleeve 的新手。我正在评估是否应该使用 BookSleeve 或 ServiceStack.Redis。 ServiceStack 看起来更直接,但我喜欢 Book
我需要在现有集合和用户输入的一些值之间执行 Except 操作。我怎样才能最好地做到这一点?我首先考虑使用一个临时集来存储用户的值。这会在多线程应用程序(网络)中工作吗?如果是这样,我如何确定在执行
我正在更新我的网络服务以使用最新的 BookSleeve图书馆,1.3.38。以前我用的是 1.1.0.7 在做一些基准测试时,我注意到使用新版本的 BookSleeve 在 Redis 中设置哈希比
我无法通过执行以下操作重新连接到我的 Redis 数据库: 创建一个名为“connection”的新 RedisConnection 打开连接connection.Open().Wait(); 关闭连
当我使用 BookSleeve 连接到我的 Redis 服务器并从中添加/获取条目时,我收到了一个 SocketException。具体的异常(exception)是:通常只允许每个套接字地址(协议(
所以我有这个单元测试: [TestMethod] public void TestNullString() { String expectedTestValue = null; var
我正在尝试根据 BookSleeve 组合一个 super 简单的排队示例。 到目前为止,这是我在队列消费者方面所拥有的: using System; using System.Text; using
是否有关于 BookSleeve Redis 入门的文章或资源?谢谢 最佳答案 这些是我在加快速度时阅读的一些文章/链接: http://marcgravell.blogspot.com/2011/0
我正在尝试使用 Redis Booksleeve 存储多个成员(member)评分值,但 Booksleeve api 似乎不支持此功能。 conn.SortedSets.Add 重载仅支持单对值 -
除非我遗漏了什么,否则我看不到允许您设置多个具有到期时间的 key 的 Multiple Set/Add 重载。 var conn = new RedisConnection("server"); D
我有大约 336 个键要删除,它们是 SortedSet,我在 Ubuntu 服务器上使用 BookSleeve 作为 C3 客户端和 Redis。下面的代码有效,但如果我删除 Console.Wri
BookSleeve性能非常好,因为它尽可能多地使用异步 IO。 但问题是,它可能会从异步操作中抛出致命异常并使我的应用程序崩溃。 我知道关键字 await 可以提供帮助,但我不能在每次调用时都使用
谁能告诉我如何从 BookSleeve 调用命令 BGSAVE 到 Redis? 我在 BookSleeve 中搜索了很多可用的方法,但没有找到任何与 SAVE 或 BGSAVE 相关的命令。 谢谢!
我正在使用 Booksleeve 通过 C# 代码与 Redis 通信。该代码首先从哈希中检索所有字段和值: var vals = await Redis.Hashes.GetAll(0, redis
我正在尝试获取值列表,其中键名称以“猴子”开头。 我真的找不到这方面的文档。 :( 我该怎么做?我应该使用什么 API? 键、集合、字符串?什么方法? 或者它尚不可用,但有解决方法? 谢谢 最佳答案
我正在为 Redis 使用 Booksleeve 哈希 API。我正在做以下事情: CurrentConnection.Hashes.Set(0, "item:1", "priority", ta
我一直在 C# 中使用 Booksleeve 作为我的 redis 驱动程序并且对此非常满意 - 但我发现需要对排序集进行一些工作。看起来这些在 Booksleeve 中只得到最少的支持——例如,没有
我正在尝试在 appharbor 上设置 Redis。我已按照他们的说明进行操作,但我再次遇到 Booksleeve API 问题。这是我用来使其最初工作的代码: var
我有以下类(class)女巫在论坛中存储一条消息 using System; using System.Collections.Generic; public partial class ForumM
我对 Marc Gravell 的 Booksleeve 图书馆有疑问。 我试图了解 booksleeve 如何处理 Int64 值(实际上我在 Redis 中有 billion long 值) 我使
我是一名优秀的程序员,十分优秀!