本文整理匯總了Golang中github.com/rod6/rodis/resp.Array類的典型用法代碼示例。如果您正苦於以下問題:Golang Array類的具體用法?Golang Array怎麽用?Golang Array使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Array類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Handle
// Handle command
func Handle(v resp.Array, ex *CommandExtras) error {
ex.Buffer.Truncate(0) // Truncate all data in the buffer
if len(v) == 0 {
log6.Debug("Command handler, len of the input array is 0")
return resp.NewError(ErrFmtNoCommand).WriteTo(ex.Buffer)
}
args := v.ToArgs()
//log6.Debug("Command handling:%v", humanArgs(args))
cmd := strings.ToLower(args[0].String())
a, err := findCmdFunc(cmd)
if err != nil {
log6.Debug("Command handler, cannt found command: %v", cmd)
return resp.NewError(ErrFmtUnknownCommand, cmd).WriteTo(ex.Buffer)
}
if a.c != 0 && len(v) != a.c { //a.c = 0 means to check the number in f
return resp.NewError(ErrFmtWrongNumberArgument, cmd).WriteTo(ex.Buffer)
}
if !ex.IsConnAuthed && ex.Password != "" && cmd != "auth" {
return resp.NewError(ErrAuthed).WriteTo(ex.Buffer)
}
return a.f(args[1:], ex)
}
示例2: hmget
func hmget(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) < 2 {
return resp.NewError(ErrFmtWrongNumberArgument, "hmget").WriteTo(ex.Buffer)
}
ex.DB.RLock()
defer ex.DB.RUnlock()
keyExists, tipe, _ := ex.DB.Has(v[0])
if keyExists && tipe != storage.Hash {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
fields := [][]byte{}
for _, field := range v[1:] {
fields = append(fields, []byte(field))
}
hash := ex.DB.GetHashFields(v[0], fields)
arr := resp.Array{}
for _, value := range hash {
arr = append(arr, resp.BulkString(value))
}
return arr.WriteTo(ex.Buffer)
}
示例3: hgetall
func hgetall(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
keyExists, tipe, _ := ex.DB.Has(v[0])
if !keyExists {
return resp.EmptyArray.WriteTo(ex.Buffer)
}
if keyExists && tipe != storage.Hash {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
hash := ex.DB.GetHash(v[0])
arr := resp.Array{}
for field, value := range hash {
arr = append(arr, resp.BulkString([]byte(field)), resp.BulkString(value))
}
return arr.WriteTo(ex.Buffer)
}
示例4: hkeys
func hkeys(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
keyExists, tipe, _ := ex.DB.Has(v[0])
if !keyExists {
return resp.EmptyArray.WriteTo(ex.Buffer)
}
if keyExists && tipe != storage.Hash {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
fields := ex.DB.GetHashFieldNames(v[0])
arr := resp.Array{}
for _, field := range fields {
arr = append(arr, resp.BulkString(field))
}
return arr.WriteTo(ex.Buffer)
}