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

Commit a7e96f0

Browse files
committed
Add test verifying composite ops throw NotSupportedEx + eg with atomic ops
1 parent 09cd103 commit a7e96f0

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tests/ServiceStack.Redis.Tests/Issues/PipelineIssueTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,44 @@ public void Disposing_Client_Clears_Pipeline()
3939
Assert.AreEqual("v3", client.Get<string>("k3"));
4040
}
4141
}
42+
43+
[Test]
44+
public void Can_Set_with_DateTime_in_Pipeline()
45+
{
46+
using (var clientsManager = new RedisManagerPool(TestConfig.SingleHost))
47+
{
48+
bool result;
49+
int value = 111;
50+
string key = $"key:{value}";
51+
52+
// Set key with pipeline (batching many requests)
53+
using (var redis = clientsManager.GetClient())
54+
{
55+
using (var pipeline = redis.CreatePipeline())
56+
{
57+
//Only atomic operations can be called within a Transaction or Pipeline
58+
Assert.Throws<NotSupportedException>(() =>
59+
pipeline.QueueCommand(r => r.Set(key, value, DateTime.Now.AddMinutes(1)), r => result = r));
60+
}
61+
62+
using (var pipeline = redis.CreatePipeline())
63+
{
64+
65+
pipeline.QueueCommand(r => r.Set(key, value), r => result = r);
66+
pipeline.QueueCommand(r => r.ExpireEntryAt(key, DateTime.Now.AddMinutes(1)));
67+
68+
pipeline.Flush();
69+
}
70+
}
71+
72+
// Get key
73+
using (var redis = clientsManager.GetClient())
74+
{
75+
var res = redis.Get<int>(key);
76+
Assert.That(res, Is.EqualTo(value));
77+
}
78+
}
79+
80+
}
4281
}
4382
}

0 commit comments

Comments
 (0)