...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package internal
16
17 import (
18 "strings"
19 )
20
21 const (
22 WatchState = 1 << iota
23 MultiState
24 SubscribeState
25 MonitorState
26 )
27
28 type CommandInfo struct {
29 Set, Clear int
30 }
31
32 var commandInfos = map[string]CommandInfo{
33 "WATCH": {Set: WatchState},
34 "UNWATCH": {Clear: WatchState},
35 "MULTI": {Set: MultiState},
36 "EXEC": {Clear: WatchState | MultiState},
37 "DISCARD": {Clear: WatchState | MultiState},
38 "PSUBSCRIBE": {Set: SubscribeState},
39 "SUBSCRIBE": {Set: SubscribeState},
40 "MONITOR": {Set: MonitorState},
41 }
42
43 func init() {
44 for n, ci := range commandInfos {
45 commandInfos[strings.ToLower(n)] = ci
46 }
47 }
48
49 func LookupCommandInfo(commandName string) CommandInfo {
50 if ci, ok := commandInfos[commandName]; ok {
51 return ci
52 }
53 return commandInfos[strings.ToUpper(commandName)]
54 }
55
View as plain text