-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.go
More file actions
437 lines (407 loc) · 15.5 KB
/
commands.go
File metadata and controls
437 lines (407 loc) · 15.5 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
package redkit
// CommandType represents Redis command names
type CommandType string
const (
// Connection Commands
PING CommandType = "PING" // Test server connectivity
ECHO CommandType = "ECHO" // Echo the given string
QUIT CommandType = "QUIT" // Close the connection
HELP CommandType = "HELP" // Show help information
// String Commands
APPEND CommandType = "APPEND"
DECR CommandType = "DECR"
DECRBY CommandType = "DECRBY"
DELEX CommandType = "DELEX"
DIGEST CommandType = "DIGEST"
GET CommandType = "GET"
GETDEL CommandType = "GETDEL"
GETEX CommandType = "GETEX"
GETRANGE CommandType = "GETRANGE"
GETSET CommandType = "GETSET"
INCR CommandType = "INCR"
INCRBY CommandType = "INCRBY"
INCRBYFLOAT CommandType = "INCRBYFLOAT"
LCS CommandType = "LCS"
MGET CommandType = "MGET"
MSET CommandType = "MSET"
MSETEX CommandType = "MSETEX"
MSETNX CommandType = "MSETNX"
PSETEX CommandType = "PSETEX"
SET CommandType = "SET"
SETEX CommandType = "SETEX"
SETNX CommandType = "SETNX"
SETRANGE CommandType = "SETRANGE"
STRLEN CommandType = "STRLEN"
SUBSTR CommandType = "SUBSTR"
//Hash Commands
HDEL CommandType = "HDEL"
HEXISTS CommandType = "HEXISTS"
HEXPIRE CommandType = "HEXPIRE"
HEXPIREAT CommandType = "HEXPIREAT"
HEXPIRETIME CommandType = "HEXPIRETIME"
HGET CommandType = "HGET"
HGETALL CommandType = "HGETALL"
HGETDEL CommandType = "HGETDEL"
HGETEX CommandType = "HGETEX"
HINCRBY CommandType = "HINCRBY"
HINCRBYFLOAT CommandType = "HINCRBYFLOAT"
HKEYS CommandType = "HKEYS"
HLEN CommandType = "HLEN"
HMGET CommandType = "HMGET"
HMSET CommandType = "HMSET"
HPERSIST CommandType = "HPERSIST"
HPEXPIRE CommandType = "HPEXPIRE"
HPEXPIREAT CommandType = "HPEXPIREAT"
HPEXPIRETIME CommandType = "HPEXPIRETIME"
HPTTL CommandType = "HPTTL"
HRANDFIELD CommandType = "HRANDFIELD"
HSCAN CommandType = "HSCAN"
HSET CommandType = "HSET"
HSETEX CommandType = "HSETEX"
HSETNX CommandType = "HSETNX"
HSTRLEN CommandType = "HSTRLEN"
HTTL CommandType = "HTTL"
HVALS CommandType = "HVALS"
//List Commands
BLMOVE CommandType = "BLMOVE"
BLMPOP CommandType = "BLMPOP"
BLPOP CommandType = "BLPOP"
BRPOP CommandType = "BRPOP"
BRPOPLPUSH CommandType = "BRPOPLPUSH"
LINDEX CommandType = "LINDEX"
LINSERT CommandType = "LINSERT"
LLEN CommandType = "LLEN"
LMOVE CommandType = "LMOVE"
LMPOP CommandType = "LMPOP"
LPOP CommandType = "LPOP"
LPOS CommandType = "LPOS"
LPUSH CommandType = "LPUSH"
LPUSHX CommandType = "LPUSHX"
LRANGE CommandType = "LRANGE"
LREM CommandType = "LREM"
LSET CommandType = "LSET"
LTRIM CommandType = "LTRIM"
RPOP CommandType = "RPOP"
RPOPLPUSH CommandType = "RPOPLPUSH"
RPUSH CommandType = "RPUSH"
RPUSHX CommandType = "RPUSHX"
//Set Commands
SADD CommandType = "SADD"
SCARD CommandType = "SCARD"
SDIFF CommandType = "SDIFF"
SDIFFSTORE CommandType = "SDIFFSTORE"
SINTER CommandType = "SINTER"
SINTERCARD CommandType = "SINTERCARD"
SINTERSTORE CommandType = "SINTERSTORE"
SISMEMBER CommandType = "SISMEMBER"
SMEMBERS CommandType = "SMEMBERS"
SMISMEMBER CommandType = "SMISMEMBER"
SMOVE CommandType = "SMOVE"
SPOP CommandType = "SPOP"
SRANDMEMBER CommandType = "SRANDMEMBER"
SREM CommandType = "SREM"
SSCAN CommandType = "SSCAN"
SUNION CommandType = "SUNION"
SUNIONSTORE CommandType = "SUNIONSTORE"
//Sorted Set Commands
BZMPOP CommandType = "BZMPOP"
BZPOPMAX CommandType = "BZPOPMAX"
BZPOPMIN CommandType = "BZPOPMIN"
ZADD CommandType = "ZADD"
ZCARD CommandType = "ZCARD"
ZCOUNT CommandType = "ZCOUNT"
ZDIFF CommandType = "ZDIFF"
ZDIFFSTORE CommandType = "ZDIFFSTORE"
ZINCRBY CommandType = "ZINCRBY"
ZINTER CommandType = "ZINTER"
ZINTERCARD CommandType = "ZINTERCARD"
ZINTERSTORE CommandType = "ZINTERSTORE"
ZLEXCOUNT CommandType = "ZLEXCOUNT"
ZMPOP CommandType = "ZMPOP"
ZMSCORE CommandType = "ZMSCORE"
ZPOPMAX CommandType = "ZPOPMAX"
ZPOPMIN CommandType = "ZPOPMIN"
ZRANDMEMBER CommandType = "ZRANDMEMBER"
ZRANGE CommandType = "ZRANGE"
ZRANGEBYLEX CommandType = "ZRANGEBYLEX"
ZRANGEBYSCORE CommandType = "ZRANGEBYSCORE"
ZRANGESTORE CommandType = "ZRANGESTORE"
ZRANK CommandType = "ZRANK"
ZREM CommandType = "ZREM"
ZREMRANGEBYLEX CommandType = "ZREMRANGEBYLEX"
ZREMRANGEBYRANK CommandType = "ZREMRANGEBYRANK"
ZREMRANGEBYSCORE CommandType = "ZREMRANGEBYSCORE"
ZREVRANGE CommandType = "ZREVRANGE"
ZREVRANGEBYLEX CommandType = "ZREVRANGEBYLEX"
ZREVRANGEBYSCORE CommandType = "ZREVRANGEBYSCORE"
ZREVRANK CommandType = "ZREVRANK"
ZSCAN CommandType = "ZSCAN"
ZSCORE CommandType = "ZSCORE"
ZUNION CommandType = "ZUNION"
ZUNIONSTORE CommandType = "ZUNIONSTORE"
//Stream Commands
XACK CommandType = "XACK"
XACKDEL CommandType = "XACKDEL"
XADD CommandType = "XADD"
XAUTOCLAIM CommandType = "XAUTOCLAIM"
XCLAIM CommandType = "XCLAIM"
XDEL CommandType = "XDEL"
XDELEX CommandType = "XDELEX"
XGROUP CommandType = "XGROUP"
XINFO CommandType = "XINFO"
XLEN CommandType = "XLEN"
XPENDING CommandType = "XPENDING"
XRANGE CommandType = "XRANGE"
XREAD CommandType = "XREAD"
XREADGROUP CommandType = "XREADGROUP"
XREVRANGE CommandType = "XREVRANGE"
XSETID CommandType = "XSETID"
XTRIM CommandType = "XTRIM"
//Bitmap Commands
BITCOUNT CommandType = "BITCOUNT"
BITFIELD CommandType = "BITFIELD"
BITFIELD_RO CommandType = "BITFIELD_RO"
BITOP CommandType = "BITOP"
BITPOS CommandType = "BITPOS"
GETBIT CommandType = "GETBIT"
SETBIT CommandType = "SETBIT"
//HyperLogLog Commands
PFADD CommandType = "PFADD"
PFCOUNT CommandType = "PFCOUNT"
PFDEBUG CommandType = "PFDEBUG"
PFMERGE CommandType = "PFMERGE"
PFSELFTEST CommandType = "PFSELFTEST"
//Geospatial Commands
GEOADD CommandType = "GEOADD"
GEODIST CommandType = "GEODIST"
GEOHASH CommandType = "GEOHASH"
GEOPOS CommandType = "GEOPOS"
GEORADIUS CommandType = "GEORADIUS"
GEORADIUSBYMEMBER CommandType = "GEORADIUSBYMEMBER"
GEORADIUSBYMEMBER_RO CommandType = "GEORADIUSBYMEMBER_RO"
GEORADIUS_RO CommandType = "GEORADIUS_RO"
GEOSEARCH CommandType = "GEOSEARCH"
GEOSEARCHSTORE CommandType = "GEOSEARCHSTORE"
//JSON Commands
JSON_ARRAPPEND CommandType = "JSON.ARRAPPEND"
JSON_ARRINDEX CommandType = "JSON.ARRINDEX"
JSON_ARRINSERT CommandType = "JSON.ARRINSERT"
JSON_ARRLEN CommandType = "JSON.ARRLEN"
JSON_ARRPOP CommandType = "JSON.ARRPOP"
JSON_ARRTRIM CommandType = "JSON.ARRTRIM"
JSON_CLEAR CommandType = "JSON.CLEAR"
JSON_DEBUG CommandType = "JSON.DEBUG"
JSON_DEL CommandType = "JSON.DEL"
JSON_FORGET CommandType = "JSON.FORGET"
JSON_GET CommandType = "JSON.GET"
JSON_MERGE CommandType = "JSON.MERGE"
JSON_MGET CommandType = "JSON.MGET"
JSON_MSET CommandType = "JSON.MSET"
JSON_NUMINCRBY CommandType = "JSON.NUMINCRBY"
JSON_NUMMULTBY CommandType = "JSON.NUMMULTBY"
JSON_OBJKEYS CommandType = "JSON.OBJKEYS"
JSON_OBJLEN CommandType = "JSON.OBJLEN"
JSON_RESP CommandType = "JSON.RESP"
JSON_SET CommandType = "JSON.SET"
JSON_STRAPPEND CommandType = "JSON.STRAPPEND"
JSON_STRLEN CommandType = "JSON.STRLEN"
JSON_TOGGLE CommandType = "JSON.TOGGLE"
JSON_TYPE CommandType = "JSON.TYPE"
//Search Commands
FT_AGGREGATE CommandType = "FT.AGGREGATE"
FT_ALIASADD CommandType = "FT.ALIASADD"
FT_ALIASDEL CommandType = "FT.ALIASDEL"
FT_ALIASUPDATE CommandType = "FT.ALIASUPDATE"
FT_ALTER CommandType = "FT.ALTER"
FT_CONFIG CommandType = "FT.CONFIG"
FT_CREATE CommandType = "FT.CREATE"
FT_CURSOR CommandType = "FT.CURSOR"
FT_DICTADD CommandType = "FT.DICTADD"
FT_DICTDEL CommandType = "FT.DICTDEL"
FT_DICTDUMP CommandType = "FT.DICTDUMP"
FT_DROPINDEX CommandType = "FT.DROPINDEX"
FT_EXPLAIN CommandType = "FT.EXPLAIN"
FT_EXPLAINCLI CommandType = "FT.EXPLAINCLI"
FT_HYBRID CommandType = "FT.HYBRID"
FT_INFO CommandType = "FT.INFO"
FT_PROFILE CommandType = "FT.PROFILE"
FT_SEARCH CommandType = "FT.SEARCH"
FT_SPELLCHECK CommandType = "FT.SPELLCHECK"
FT_SYNDUMP CommandType = "FT.SYNDUMP"
FT_SYNUPDATE CommandType = "FT.SYNUPDATE"
FT_TAGVALS CommandType = "FT.TAGVALS"
FT_LIST CommandType = "FT._LIST"
//Time Series Commands
TS_ADD CommandType = "TS.ADD"
TS_ALTER CommandType = "TS.ALTER"
TS_CREATE CommandType = "TS.CREATE"
TS_CREATERULE CommandType = "TS.CREATERULE"
TS_DECRBY CommandType = "TS.DECRBY"
TS_DEL CommandType = "TS.DEL"
TS_DELETERULE CommandType = "TS.DELETERULE"
TS_GET CommandType = "TS.GET"
TS_INCRBY CommandType = "TS.INCRBY"
TS_INFO CommandType = "TS.INFO"
TS_MADD CommandType = "TS.MADD"
TS_MGET CommandType = "TS.MGET"
TS_MRANGE CommandType = "TS.MRANGE"
TS_MREVRANGE CommandType = "TS.MREVRANGE"
TS_QUERYINDEX CommandType = "TS.QUERYINDEX"
TS_RANGE CommandType = "TS.RANGE"
TS_REVRANGE CommandType = "TS.REVRANGE"
//Vector Set Commands
VADD CommandType = "VADD"
VCARD CommandType = "VCARD"
VDIM CommandType = "VDIM"
VEMB CommandType = "VEMB"
VGETATTR CommandType = "VGETATTR"
VINFO CommandType = "VINFO"
VISMEMBER CommandType = "VISMEMBER"
VLINKS CommandType = "VLINKS"
VRANDMEMBER CommandType = "VRANDMEMBER"
VRANGE CommandType = "VRANGE"
VREM CommandType = "VREM"
VSETATTR CommandType = "VSETATTR"
VSIM CommandType = "VSIM"
//Pub/Sub Commands
PSUBSCRIBE CommandType = "PSUBSCRIBE"
PUBLISH CommandType = "PUBLISH"
PUBSUB CommandType = "PUBSUB"
PUNSUBSCRIBE CommandType = "PUNSUBSCRIBE"
SPUBLISH CommandType = "SPUBLISH"
SSUBSCRIBE CommandType = "SSUBSCRIBE"
SUBSCRIBE CommandType = "SUBSCRIBE"
SUNSUBSCRIBE CommandType = "SUNSUBSCRIBE"
UNSUBSCRIBE CommandType = "UNSUBSCRIBE"
//Transaction Commands
DISCARD CommandType = "DISCARD"
EXEC CommandType = "EXEC"
MULTI CommandType = "MULTI"
UNWATCH CommandType = "UNWATCH"
WATCH CommandType = "WATCH"
//Scripting Commands
EVAL CommandType = "EVAL"
EVALSHA CommandType = "EVALSHA"
EVALSHA_RO CommandType = "EVALSHA_RO"
EVAL_RO CommandType = "EVAL_RO"
FCALL CommandType = "FCALL"
FCALL_RO CommandType = "FCALL_RO"
FUNCTION CommandType = "FUNCTION"
SCRIPT CommandType = "SCRIPT"
//Connection Commands
AUTH CommandType = "AUTH"
CLIENT CommandType = "CLIENT"
HELLO CommandType = "HELLO"
RESET CommandType = "RESET"
//Server Commands
ACL CommandType = "ACL"
BGREWRITEAOF CommandType = "BGREWRITEAOF"
BGSAVE CommandType = "BGSAVE"
COMMAND CommandType = "COMMAND"
CONFIG CommandType = "CONFIG"
DBSIZE CommandType = "DBSIZE"
FAILOVER CommandType = "FAILOVER"
FLUSHALL CommandType = "FLUSHALL"
FLUSHDB CommandType = "FLUSHDB"
INFO CommandType = "INFO"
LASTSAVE CommandType = "LASTSAVE"
LATENCY CommandType = "LATENCY"
LOLWUT CommandType = "LOLWUT"
MEMORY CommandType = "MEMORY"
MODULE CommandType = "MODULE"
MONITOR CommandType = "MONITOR"
PSYNC CommandType = "PSYNC"
REPLCONF CommandType = "REPLCONF"
REPLICAOF CommandType = "REPLICAOF"
RESTORE_ASKING CommandType = "RESTORE-ASKING"
ROLE CommandType = "ROLE"
SAVE CommandType = "SAVE"
SHUTDOWN CommandType = "SHUTDOWN"
SLAVEOF CommandType = "SLAVEOF"
SLOWLOG CommandType = "SLOWLOG"
SWAPDB CommandType = "SWAPDB"
SYNC CommandType = "SYNC"
TIME CommandType = "TIME"
//Cluster Commands
ASKING CommandType = "ASKING"
CLUSTER CommandType = "CLUSTER"
READONLY CommandType = "READONLY"
READWRITE CommandType = "READWRITE"
//Generic Commands
COPY CommandType = "COPY"
DEL CommandType = "DEL"
DUMP CommandType = "DUMP"
EXISTS CommandType = "EXISTS"
EXPIRE CommandType = "EXPIRE"
EXPIREAT CommandType = "EXPIREAT"
EXPIRETIME CommandType = "EXPIRETIME"
KEYS CommandType = "KEYS"
MIGRATE CommandType = "MIGRATE"
MOVE CommandType = "MOVE"
OBJECT CommandType = "OBJECT"
PERSIST CommandType = "PERSIST"
PEXPIRE CommandType = "PEXPIRE"
PEXPIREAT CommandType = "PEXPIREAT"
PEXPIRETIME CommandType = "PEXPIRETIME"
PTTL CommandType = "PTTL"
RANDOMKEY CommandType = "RANDOMKEY"
RENAME CommandType = "RENAME"
RENAMENX CommandType = "RENAMENX"
RESTORE CommandType = "RESTORE"
SCAN CommandType = "SCAN"
SORT CommandType = "SORT"
SORT_RO CommandType = "SORT_RO"
TOUCH CommandType = "TOUCH"
TTL CommandType = "TTL"
TYPE CommandType = "TYPE"
UNLINK CommandType = "UNLINK"
WAIT CommandType = "WAIT"
WAITAOF CommandType = "WAITAOF"
)
// registerDefaultHandlers registers the built-in Redis commands
func (s *Server) registerDefaultHandlers() {
// PING command
s.RegisterCommandFunc(string(PING), func(conn *Connection, cmd *Command) RedisValue {
if len(cmd.Args) == 0 {
return RedisValue{Type: SimpleString, Str: "PONG"}
}
return RedisValue{Type: BulkString, Bulk: []byte(cmd.Args[0])}
})
// ECHO command
s.RegisterCommandFunc(string(ECHO), func(conn *Connection, cmd *Command) RedisValue {
if len(cmd.Args) != 1 {
return RedisValue{Type: ErrorReply, Str: "ERR wrong number of arguments for 'echo' command"}
}
return RedisValue{Type: BulkString, Bulk: []byte(cmd.Args[0])}
})
s.RegisterCommandFunc(string(HELP), func(conn *Connection, cmd *Command) RedisValue {
helpText := "RedKit Redis Server - Supported commands:\n" +
"PING [message] - Returns PONG or the provided message\n" +
"ECHO message - Echoes the provided message\n" +
"QUIT - Closes the connection\n" +
"(Other commands may be supported depending on the server configuration)"
return RedisValue{Type: BulkString, Bulk: []byte(helpText)}
})
// QUIT command - mark connection for closing, response will be sent first
s.RegisterCommandFunc(string(QUIT), func(conn *Connection, cmd *Command) RedisValue {
// Mark connection to be closed after response is sent
conn.MarkForClose()
return RedisValue{Type: SimpleString, Str: "OK"}
})
}
// registerPingHandler registers a custom handler for the PING command
func (s *Server) registerPingHandler(f func(conn *Connection, cmd *Command) RedisValue) {
s.RegisterCommandFunc(string(PING), f)
}
// registerEchoHandler registers a custom handler for the ECHO command
func (s *Server) registerEchoHandler(f func(conn *Connection, cmd *Command) RedisValue) {
s.RegisterCommandFunc(string(ECHO), f)
}
// registerQuitHandler registers a custom handler for the QUIT command
func (s *Server) registerQuitHandler(f func(conn *Connection, cmd *Command) RedisValue) {
s.RegisterCommandFunc(string(QUIT), f)
}
// registerHelpHandler registers a custom handler for the HELP command
func (s *Server) registerHelpHandler(f func(conn *Connection, cmd *Command) RedisValue) {
s.RegisterCommandFunc(string(HELP), f)
}