Repository navigation
Expand file tree
/
Copy pathCmsCommandBuilder.cs
More file actions
75 lines (59 loc) · 2.41 KB
/
Copy pathCmsCommandBuilder.cs
File metadata and controls
75 lines (59 loc) · 2.41 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
67
68
69
70
71
72
73
74
75
using NRedisStack.CountMinSketch.Literals;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
namespace NRedisStack;
[Obsolete("The command builders are superseded by the command groups (db.CountMinSketch); they will be removed in a future version.")]
public static class CmsCommandBuilder
{
public static SerializedCommand IncrBy(RedisKey key, RedisValue item, long increment)
{
return new(CommandCategories.WriteAccumulating, CMS.INCRBY, key, item, increment);
}
public static SerializedCommand IncrBy(RedisKey key, 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, CMS.INCRBY, args);
}
public static SerializedCommand Info(RedisKey key)
{
var info = new SerializedCommand(CommandCategories.ReadOnly, CMS.INFO, key);
return info;
}
public static SerializedCommand InitByDim(RedisKey key, long width, long depth)
{
return new(CommandCategories.WriteAccumulating, CMS.INITBYDIM, key, width, depth);
}
public static SerializedCommand InitByProb(RedisKey key, double error, double probability)
{
return new(CommandCategories.WriteAccumulating, CMS.INITBYPROB, key, error, probability);
}
public static SerializedCommand Merge(RedisValue destination, long numKeys, RedisValue[] source,
long[]? weight = null)
{
if (source.Length < 1)
throw new ArgumentOutOfRangeException(nameof(source));
List<object> args = [destination, numKeys];
foreach (var s in source) args.Add(s);
if (weight != null && weight.Length >= 1)
{
args.Add(CmsArgs.WEIGHTS);
foreach (var w in weight) args.Add(w);
}
return new(CommandCategories.WriteAccumulating, CMS.MERGE, args);
}
public static SerializedCommand Query(RedisKey key, params RedisValue[] items)
{
if (items.Length < 1)
throw new ArgumentOutOfRangeException(nameof(items));
List<object> args = [key];
foreach (var item in items) args.Add(item);
return new(CommandCategories.ReadOnly, CMS.QUERY, args);
}
}