Repository navigation
Expand file tree
/
Copy pathTopKCommandBuilder.cs
More file actions
66 lines (53 loc) · 2.16 KB
/
Copy pathTopKCommandBuilder.cs
File metadata and controls
66 lines (53 loc) · 2.16 KB
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
using NRedisStack.TopK.Literals;
using StackExchange.Redis;
using NRedisStack.RedisStackCommands;
namespace NRedisStack;
public static class TopKCommandBuilder
{
public static SerializedCommand Add(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));
var args = Auxiliary.MergeArgs(key, items);
return new(CommandCategories.WriteAccumulating, TOPK.ADD, args);
}
public static SerializedCommand Count(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));
var args = Auxiliary.MergeArgs(key, items);
return new(CommandCategories.ReadOnly, TOPK.COUNT, args);
}
public static SerializedCommand IncrBy(RedisKey key, params Tuple<RedisValue, long>[] itemIncrements)
{
if (itemIncrements.Length < 1)
throw new ArgumentOutOfRangeException(nameof(itemIncrements));
List<object> args = [key];
foreach (var pair in itemIncrements)
{
args.Add(pair.Item1);
args.Add(pair.Item2);
}
return new(CommandCategories.WriteAccumulating, TOPK.INCRBY, args);
}
public static SerializedCommand Info(RedisKey key)
{
return new(CommandCategories.ReadOnly, TOPK.INFO, key);
}
public static SerializedCommand List(RedisKey key, bool withcount = false)
{
return (withcount) ? new(CommandCategories.ReadOnly, TOPK.LIST, key, "WITHCOUNT")
: new SerializedCommand(CommandCategories.ReadOnly, TOPK.LIST, key);
}
public static SerializedCommand Query(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));
var args = Auxiliary.MergeArgs(key, items);
return new(CommandCategories.ReadOnly, TOPK.QUERY, args);
}
public static SerializedCommand Reserve(RedisKey key, long topk, long width = 7, long depth = 8, double decay = 0.9)
{
return new(CommandCategories.WriteAccumulating, TOPK.RESERVE, key, topk, width, depth, decay);
}
}