commandinfo.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. connectionWatchState = 1 << iota
  20. connectionMultiState
  21. connectionSubscribeState
  22. connectionMonitorState
  23. )
  24. type commandInfo struct {
  25. // Set or Clear these states on connection.
  26. Set, Clear int
  27. }
  28. var commandInfos = map[string]commandInfo{
  29. "WATCH": {Set: connectionWatchState},
  30. "UNWATCH": {Clear: connectionWatchState},
  31. "MULTI": {Set: connectionMultiState},
  32. "EXEC": {Clear: connectionWatchState | connectionMultiState},
  33. "DISCARD": {Clear: connectionWatchState | connectionMultiState},
  34. "PSUBSCRIBE": {Set: connectionSubscribeState},
  35. "SUBSCRIBE": {Set: connectionSubscribeState},
  36. "MONITOR": {Set: connectionMonitorState},
  37. }
  38. func init() {
  39. for n, ci := range commandInfos {
  40. commandInfos[strings.ToLower(n)] = ci
  41. }
  42. }
  43. func lookupCommandInfo(commandName string) commandInfo {
  44. if ci, ok := commandInfos[commandName]; ok {
  45. return ci
  46. }
  47. return commandInfos[strings.ToUpper(commandName)]
  48. }