Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 611047f

Browse files
committed
Pipeline and multi key operations only counts as 1 test
1 parent f9190eb commit 611047f

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/ServiceStack.Redis/RedisNativeClient.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ internal IRedisPipelineShared Pipeline
150150
internal void EndPipeline()
151151
{
152152
ResetSendBuffer();
153-
Pipeline = null;
154-
Interlocked.Increment(ref __requestsPerHour);
153+
154+
if (Pipeline != null)
155+
{
156+
Pipeline = null;
157+
Interlocked.Increment(ref __requestsPerHour);
158+
}
155159
}
156160

157161
public RedisNativeClient(string connectionString)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using NUnit.Framework;
3+
4+
namespace ServiceStack.Redis.Tests
5+
{
6+
[TestFixture]
7+
public class RedisStatsTests
8+
: RedisClientTestsBase
9+
{
10+
[TestFixtureSetUp]
11+
public void TestFixtureSetUp()
12+
{
13+
RedisConfig.AssumeServerVersion = 2821;
14+
}
15+
16+
[Test]
17+
[Explicit]
18+
public void Batch_and_Pipeline_requests_only_counts_as_1_request()
19+
{
20+
var reqCount = RedisNativeClient.RequestsPerHour;
21+
22+
var map = new Dictionary<string,string>();
23+
10.Times(i => map["key" + i] = "value" + i);
24+
25+
Redis.SetValues(map);
26+
27+
Assert.That(RedisNativeClient.RequestsPerHour, Is.EqualTo(reqCount + 1));
28+
29+
var keyTypes = new Dictionary<string, string>();
30+
using (var pipeline = Redis.CreatePipeline())
31+
{
32+
map.Keys.Each(key =>
33+
pipeline.QueueCommand(r => r.Type(key), x => keyTypes[key] = x));
34+
35+
pipeline.Flush();
36+
}
37+
38+
Assert.That(RedisNativeClient.RequestsPerHour, Is.EqualTo(reqCount + 2));
39+
Assert.That(keyTypes.Count, Is.EqualTo(map.Count));
40+
}
41+
}
42+
}

tests/ServiceStack.Redis.Tests/ServiceStack.Redis.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
<Compile Include="RedisPubSubServerTests.cs" />
251251
<Compile Include="RedisPubSubTests.cs" />
252252
<Compile Include="RedisScanTests.cs" />
253+
<Compile Include="RedisStatsTests.cs" />
253254
<Compile Include="RedisTransactionCommonTests.cs" />
254255
<Compile Include="RedisTransactionTests.cs" />
255256
<Compile Include="RedisUtilTests.cs" />

0 commit comments

Comments
 (0)