This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 878
/
RedisAllPurposePipeline.cs
78 lines (65 loc) · 1.85 KB
/
RedisAllPurposePipeline.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using ServiceStack.Redis.Pipeline;
namespace ServiceStack.Redis
{
public class RedisAllPurposePipeline : RedisCommandQueue, IRedisPipeline
{
/// <summary>
/// General purpose pipeline
/// </summary>
/// <param name="redisClient"></param>
public RedisAllPurposePipeline(RedisClient redisClient)
: base(redisClient)
{
Init();
}
protected virtual void Init()
{
if (RedisClient.Transaction != null)
throw new InvalidOperationException("A transaction is already in use");
if (RedisClient.Pipeline != null)
throw new InvalidOperationException("A pipeline is already in use");
RedisClient.Pipeline = this;
}
/// <summary>
/// Flush send buffer, and read responses
/// </summary>
public void Flush()
{
// flush send buffers
RedisClient.FlushAndResetSendBuffer();
//receive expected results
foreach (var queuedCommand in QueuedCommands)
{
queuedCommand.ProcessResult();
}
ClosePipeline();
}
protected void Execute()
{
int count = QueuedCommands.Count;
for (int i = 0; i < count; ++i)
{
var op = QueuedCommands[0];
QueuedCommands.RemoveAt(0);
op.Execute(RedisClient);
QueuedCommands.Add(op);
}
}
public bool Replay()
{
Init();
Execute();
Flush();
return true;
}
protected void ClosePipeline()
{
RedisClient.EndPipeline();
}
public void Dispose()
{
ClosePipeline();
}
}
}