...

Source file src/github.com/gomodule/redigo/internal/commandinfo.go

Documentation: github.com/gomodule/redigo/internal

     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  
    15  package internal // import "github.com/gomodule/redigo/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