3

最初我试图将一些项目集合插入到 2 个 redis 集中(也许这根本不是一个好主意,但是......)。我尝试一次添加的条目数量: 750+

现在我在尝试使用 StackExchange.redis客户端执行此操作时确实收到超时异常,有趣的是我能够使用我之前调查过的“旧版”booksleeve 客户端完成类似的操作。

所以,我肯定在某些事情上错了(甚至可能在我最初的 bookSleeve 实现中),只是想弄清楚到底出了什么问题。以下是我与 redis 客户端一起使用的代码示例: BookSleeve:

using (var tran = connection.CreateTransaction())
{
Task lastOpTask = null;
tran.SuspendFlush();
try
{
    // perform required configurations/ actions
    tran.Sets.Add(_redisConfiguration.DbNumber, CurrentIdsSetDbKey, stringIds);
    tran.Sets.Add(_redisConfiguration.DbNumber, CurrentDetailsSetDbKey, stringDetails);
    lastOpTask = tran.Execute();
    isOperationSuccessful = true;
}
catch (TaskCanceledException ex)
{
    ...
}
catch (TimeoutException ex1)
{
    ...
}
finally
{
    tran.ResumeFlush();
}

if (lastOpTask != null)
{
    connection.Wait(lastOpTask);
    ...
}
}

StackExchange.redis 实现相同的代码:

var tran = db.CreateTransaction();

// todo: do we need to add here any condition or PipeLining? any watch/unwatch verifications?
tran.SetAddAsync(CurrentIdsSetDbKey, stringIds);
tran.SetAddAsync(CurrentDetailsSetDbKey, stringDetails);

try
{
    isOperationSuccessful = tran.Execute();
}
catch (TaskCanceledException ex)
{
    ...
}
catch (TimeoutException ex1)
{
    ...
}

开始单元测试后,我收到 StackExchange 客户端的下一个错误:

Message: Timeout performing EXEC, inst: 3, queue: 3, qu=0, qs=3, qc=0, wr=0/0

Source: in StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 1693 in StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 92 in StackExchange.Redis.RedisTransaction.Execute(CommandFlags flags) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\RedisTransaction.cs:line 51 in DFS.Cache.CacheManager.RedisStackExchange.RedisContestCacheManager.RegisterAvailableContests(IList1 contests) in d:\Projects\DFS\Code\DFS\DFS.Cache.CacheManager.RedisStackExchange\RedisContestCacheManager.cs:line 131

只是想知道,我到底做错了什么。提前感谢您的任何建议!

PS 对于 stackEchange.redis 配置,我使用的是 Marc 从 github 提供的配置示例(可在此处获得:StackExchange/StackExchange.Redis/blob/master/Docs/Configuration.md)

PS 请查看当前的 StackExchange 客户端配置文件:

var config = new ConfigurationOptions
{
    EndPoints =
        {
            {"MasterIP", 6379},
            {"SlaveIP", 6380}
        },
    CommandMap = CommandMap.Create(new HashSet<string>
        {
            // EXCLUDE a few commands (to work with data-flow-related mode only)
            "INFO",
            "CONFIG",
            "CLUSTER",
            "PING",
            "ECHO",
            "CLIENT"
        }, available: false),
    KeepAlive = 60, // 60 sec to ensure connection is alive
    ConnectTimeout = 5000, // 5 sec
    SyncTimeout = 5000, // 5 sec
    ServiceName = "mymaster", // sentinel service name
    DefaultVersion = new Version(2, 8, 8),
    Password = "password"
};

标准条目(用于集合)如下所示:

{
    "Id":"08e5ffdbced046cb8f55c50e4bab822d",
    "Entries":0,
    "State":"i",
    "Name":"very dummy entry name value: autoGet 299",
    "Summary": "entry summary details, some long string 299, some common info, some data: true, 8200"
    "IsMultiple":true,
    "IsPublic":true,
    "MaxEntries":8200,
    "IsEntryVisible":true,
    "StartDate":"9/10/2014 12:00:00 AM"
}

PS 在 Marc 的回复之后,我运行了几个测试并在单元测试中遇到了一些其他错误,例如

{"Timeout performing SISMEMBER set:raw:Ids, inst: 1, queue: 6, qu=0, qs=6, qc=0, wr=0/0"} when set contains not more than 300 items. 

所以我同意这是连接问题,与当前切换到 StackExchange.redis 客户端无关。

4

1 回答 1

1

以下通过就好了,并在本地报告 10ms。如果您能稍微填写一下空白,我会非常感兴趣,这样我就可以进行有代表性的测试来重现该问题。请注意,这qu=0, qs=3告诉我在超时时,我们正在等待 redis 服务器响应。显然,本地带宽和延迟会很有趣,但从根本上说,它应该可以工作。我也对您的同步超时设置感兴趣。

using System.Diagnostics;
using System.Linq;
using NUnit.Framework;

namespace StackExchange.Redis.Tests.Issues
{
    [TestFixture]
    public class SO22786599 : TestBase
    {
        [Test]
        public void Execute()
        {
            string CurrentIdsSetDbKey = Me() + ".x";
            string CurrentDetailsSetDbKey = Me() + ".y";

            RedisValue[] stringIds = Enumerable.Range(1, 750).Select(i => (RedisValue)(i + " id")).ToArray();
            RedisValue[] stringDetails = Enumerable.Range(1, 750).Select(i => (RedisValue)(i + " detail")).ToArray();

            using (var conn = Create())
            {
                var db = conn.GetDatabase();
                var tran = db.CreateTransaction();

                tran.SetAddAsync(CurrentIdsSetDbKey, stringIds);
                tran.SetAddAsync(CurrentDetailsSetDbKey, stringDetails);

                var watch = Stopwatch.StartNew();
                var isOperationSuccessful = tran.Execute();
                watch.Stop();
                System.Console.WriteLine("{0}ms", watch.ElapsedMilliseconds);
                Assert.IsTrue(isOperationSuccessful);                
            }
        }
    }
}
于 2014-04-01T18:39:04.923 回答