commandinfo.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2014 Gary Burd
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package redis
  15. import (
  16. "strings"
  17. )
  18. const (
  19. watchState = 1 << iota
  20. multiState
  21. subscribeState
  22. monitorState
  23. )
  24. type commandInfo struct {
  25. set, clear int
  26. }
  27. var commandInfos = map[string]commandInfo{
  28. "WATCH": {set: watchState},
  29. "UNWATCH": {clear: watchState},
  30. "MULTI": {set: multiState},
  31. "EXEC": {clear: watchState | multiState},
  32. "DISCARD": {clear: watchState | multiState},
  33. "PSUBSCRIBE": {set: subscribeState},
  34. "SUBSCRIBE": {set: subscribeState},
  35. "MONITOR": {set: monitorState},
  36. }
  37. func lookupCommandInfo(commandName string) commandInfo {
  38. return commandInfos[strings.ToUpper(commandName)]
  39. }