3 Star 0 Fork 0

GiteeStudio / codis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
resp.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
spinlock 提交于 2016-10-20 17:19 . redis: remove RespAlloc
// Copyright 2016 CodisLabs. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.
package redis
import "fmt"
type RespType byte
const (
TypeString RespType = '+'
TypeError RespType = '-'
TypeInt RespType = ':'
TypeBulkBytes RespType = '$'
TypeArray RespType = '*'
)
func (t RespType) String() string {
switch t {
case TypeString:
return "<string>"
case TypeError:
return "<error>"
case TypeInt:
return "<int>"
case TypeBulkBytes:
return "<bulkbytes>"
case TypeArray:
return "<array>"
default:
return fmt.Sprintf("<unknown-0x%02x>", byte(t))
}
}
type Resp struct {
Type RespType
Value []byte
Array []*Resp
}
func (r *Resp) IsString() bool {
return r.Type == TypeString
}
func (r *Resp) IsError() bool {
return r.Type == TypeError
}
func (r *Resp) IsInt() bool {
return r.Type == TypeInt
}
func (r *Resp) IsBulkBytes() bool {
return r.Type == TypeBulkBytes
}
func (r *Resp) IsArray() bool {
return r.Type == TypeArray
}
func NewString(value []byte) *Resp {
r := &Resp{}
r.Type = TypeString
r.Value = value
return r
}
func NewError(value []byte) *Resp {
r := &Resp{}
r.Type = TypeError
r.Value = value
return r
}
func NewErrorf(format string, args ...interface{}) *Resp {
return NewError([]byte(fmt.Sprintf(format, args...)))
}
func NewInt(value []byte) *Resp {
r := &Resp{}
r.Type = TypeInt
r.Value = value
return r
}
func NewBulkBytes(value []byte) *Resp {
r := &Resp{}
r.Type = TypeBulkBytes
r.Value = value
return r
}
func NewArray(array []*Resp) *Resp {
r := &Resp{}
r.Type = TypeArray
r.Array = array
return r
}
1
https://gitee.com/oscstudio/codis.git
git@gitee.com:oscstudio/codis.git
oscstudio
codis
codis
3d19640b1d13

搜索帮助