-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathcommand_meta.h
More file actions
115 lines (103 loc) · 3.36 KB
/
command_meta.h
File metadata and controls
115 lines (103 loc) · 3.36 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (C) 2011-2026 Redis Labs Ltd.
*
* This file is part of memtier_benchmark.
*
* memtier_benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* memtier_benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with memtier_benchmark. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstddef>
#include <cstdint>
namespace memtier
{
namespace command_meta
{
enum class BeginSearchType : uint8_t
{
Unknown,
Index,
Keyword
};
enum class FindKeysType : uint8_t
{
Unknown,
Range,
Keynum
};
enum class ReplyShape : uint8_t
{
NotMissable, // SET, DEL, INCR ... no miss concept.
SingleNullBulk, // GET, HGET, ZSCORE ... null reply iff key/field absent.
ArrayPerElementNulls, // MGET, HMGET, ZMSCORE ... per-position nulls.
EmptyCollection, // SMEMBERS, LRANGE, HGETALL ... empty array iff missing (heuristic).
IntegerMembership, // EXISTS, SISMEMBER, HEXISTS ... integer = number of hits.
Unknown, // No reply_schema and not in override table.
};
struct BeginSearch
{
BeginSearchType type;
int32_t pos; // Index.pos (1-based; 0 if unused).
const char *keyword; // Keyword.keyword (nullptr unless type == Keyword).
int32_t startfrom; // Keyword.startfrom.
};
struct FindKeys
{
FindKeysType type;
int32_t lastkey; // Range.lastkey (relative to begin; -1 == to end of argv).
int32_t step; // Range.step.
int32_t limit; // Range.limit (0 == no limit).
int32_t keynumidx; // Keynum.keynumidx.
int32_t firstkey; // Keynum.firstkey.
int32_t keynum_step; // Keynum.step (separate field to keep the layout flat).
};
struct KeySpec
{
BeginSearch begin;
FindKeys find;
};
struct CommandSpec
{
const char *name; // Uppercase. Subcommands are space-separated, e.g. "XGROUP CREATE".
int32_t arity; // Negative arity == variadic minimum.
bool movable_keys; // True if command_flags contains MOVABLEKEYS.
uint8_t num_key_specs; // Length of key_specs array.
const KeySpec *key_specs;
ReplyShape reply_shape;
};
// Case-insensitive lookup over the static command table. Returns nullptr if
// the name is not registered. For subcommands, pass the canonical
// "CONTAINER SUB" form (e.g. "XGROUP CREATE").
const CommandSpec *lookup(const char *name);
// Number of commands compiled into the static table.
size_t count();
inline const char *reply_shape_name(ReplyShape shape)
{
switch (shape) {
case ReplyShape::NotMissable:
return "NotMissable";
case ReplyShape::SingleNullBulk:
return "SingleNullBulk";
case ReplyShape::ArrayPerElementNulls:
return "ArrayPerElementNulls";
case ReplyShape::EmptyCollection:
return "EmptyCollection";
case ReplyShape::IntegerMembership:
return "IntegerMembership";
case ReplyShape::Unknown:
return "Unknown";
default:
return "?";
}
}
} // namespace command_meta
} // namespace memtier