tile38/vendor/github.com/gomodule/redigo/redis/commandinfo.go

56 lines
1.5 KiB
Go
Raw Permalink Normal View History

2016-12-02 19:14:34 +03:00
// Copyright 2014 Gary Burd
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
2018-10-29 15:00:54 +03:00
package redis
2016-12-02 19:14:34 +03:00
import (
"strings"
)
const (
2018-10-29 15:00:54 +03:00
connectionWatchState = 1 << iota
connectionMultiState
connectionSubscribeState
connectionMonitorState
2016-12-02 19:14:34 +03:00
)
2018-10-29 15:00:54 +03:00
type commandInfo struct {
// Set or Clear these states on connection.
2016-12-02 19:14:34 +03:00
Set, Clear int
}
2018-10-29 15:00:54 +03:00
var commandInfos = map[string]commandInfo{
"WATCH": {Set: connectionWatchState},
"UNWATCH": {Clear: connectionWatchState},
"MULTI": {Set: connectionMultiState},
"EXEC": {Clear: connectionWatchState | connectionMultiState},
"DISCARD": {Clear: connectionWatchState | connectionMultiState},
"PSUBSCRIBE": {Set: connectionSubscribeState},
"SUBSCRIBE": {Set: connectionSubscribeState},
"MONITOR": {Set: connectionMonitorState},
2016-12-02 19:14:34 +03:00
}
func init() {
for n, ci := range commandInfos {
commandInfos[strings.ToLower(n)] = ci
}
}
2018-10-29 15:00:54 +03:00
func lookupCommandInfo(commandName string) commandInfo {
2016-12-02 19:14:34 +03:00
if ci, ok := commandInfos[commandName]; ok {
return ci
}
return commandInfos[strings.ToUpper(commandName)]
}