本文整理汇总了Golang中github.com/rod6/rodis/resp.Integer函数的典型用法代码示例。如果您正苦于以下问题:Golang Integer函数的具体用法?Golang Integer怎么用?Golang Integer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Integer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getbit
func getbit(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
val, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
if err == leveldb.ErrNotFound {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
offset, err := strconv.Atoi(string(v[1]))
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
if offset >= 8*len(val) {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
byten := offset / 8
pos := offset % 8
k := val[byten] >> uint32(7-pos) & 0x01
return resp.Integer(k).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:27,代码来源:strings.go
示例2: hincrby
func hincrby(v resp.CommandArgs, ex *CommandExtras) error {
by, err := strconv.ParseInt(v[2].String(), 10, 64)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
keyExists, tipe, expireAt := ex.DB.Has(v[0])
if keyExists && tipe != storage.Hash {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
hash := ex.DB.GetHashFields(v[0], [][]byte{v[1]})
newVal := int64(0)
if hash[string(v[1])] == nil {
newVal += by
} else {
i, err := strconv.ParseInt(string(hash[string(v[1])]), 10, 64)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
newVal = i + by
}
hash[string(v[1])] = []byte(strconv.FormatInt(newVal, 10))
ex.DB.PutHash(v[0], hash, expireAt)
return resp.Integer(newVal).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:31,代码来源:hashes.go
示例3: setrange
func setrange(v resp.CommandArgs, ex *CommandExtras) error {
i64, err := strconv.ParseInt(string(v[1]), 10, 32)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
offset := int(i64)
if offset < 0 {
return resp.NewError(ErrOffsetOutRange).WriteTo(ex.Buffer)
}
if offset+len(v[2]) > 536870912 { // 512M is the limit length
return resp.NewError(ErrStringExccedLimit).WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
val, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
if len(val) < offset+len(v[2]) {
val = append(val, make([]byte, len(v[2])+offset-len(val))...)
}
copy(val[offset:], v[2])
if err = ex.DB.Put(v[0], val); err != nil {
return err
}
return resp.Integer(len(val)).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:30,代码来源:strings.go
示例4: hdel
func hdel(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) < 2 {
return resp.NewError(ErrFmtWrongNumberArgument, "hdel").WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
keyExists, tipe, _ := ex.DB.Has(v[0])
if !keyExists {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
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)
count := 0
for _, value := range hash {
if value != nil {
count++
}
}
ex.DB.DeleteHashFields(v[0], fields)
return resp.Integer(count).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:31,代码来源:hashes.go
示例5: setrange
func setrange(v resp.CommandArgs, ex *CommandExtras) error {
i64, err := strconv.ParseInt(string(v[1]), 10, 32)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
offset := int(i64)
if offset < 0 {
return resp.NewError(ErrOffsetOutRange).WriteTo(ex.Buffer)
}
if offset+len(v[2]) > 536870912 { // 512M is the limit length
return resp.NewError(ErrStringExccedLimit).WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
exists, tipe, expireAt := ex.DB.Has(v[0])
if exists && tipe != storage.String {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
val := []byte("")
if exists {
val = ex.DB.GetString(v[0])
}
if len(val) < offset+len(v[2]) {
val = append(val, make([]byte, len(v[2])+offset-len(val))...)
}
copy(val[offset:], v[2])
ex.DB.PutString(v[0], val, expireAt)
return resp.Integer(len(val)).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:34,代码来源:strings.go
示例6: getbit
func getbit(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
exists, tipe, _ := ex.DB.Has(v[0])
if !exists {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
if tipe != storage.String {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
val := ex.DB.GetString(v[0])
offset, err := strconv.Atoi(string(v[1]))
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
if offset >= 8*len(val) {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
byten := offset / 8
pos := offset % 8
k := val[byten] >> uint32(7-pos) & 0x01
return resp.Integer(k).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:29,代码来源:strings.go
示例7: del
func del(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) == 0 {
return resp.NewError(ErrFmtWrongNumberArgument, "del").WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
count := 0
for _, key := range v {
exists, tipe, _ := ex.DB.Has(key)
if !exists {
continue
}
switch tipe {
case storage.String:
ex.DB.DeleteString(key)
case storage.Hash:
ex.DB.DeleteHash(key)
}
count++
}
return resp.Integer(count).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:25,代码来源:keys.go
示例8: bitcount
func bitcount(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) == 0 {
return resp.NewError(ErrFmtWrongNumberArgument, "bitcount").WriteTo(ex.Buffer)
}
ex.DB.RLock()
defer ex.DB.RUnlock()
exists, tipe, _ := ex.DB.Has(v[0])
if !exists {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
if tipe != storage.String {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
if len(v) != 1 && len(v) != 3 {
return resp.NewError(ErrFmtSyntax).WriteTo(ex.Buffer)
}
val := ex.DB.GetString(v[0])
start := 0
end := len(val)
var err error
if len(v) == 3 {
start, err = strconv.Atoi(string(v[1]))
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
end, err = strconv.Atoi(string(v[2]))
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
start, end = calcRange(start, end, len(val))
}
if end <= start {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
sum := 0
for _, b := range val[start:end] {
sum += countSetBits[b]
}
return resp.Integer(sum).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:50,代码来源:strings.go
示例9: setbit
func setbit(v resp.CommandArgs, ex *CommandExtras) error {
i64, err := strconv.ParseInt(string(v[1]), 10, 32)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
offset := uint32(i64)
pos := offset % 8
byten := offset / 8
if int(byten)+1 > STRLIMIT {
return resp.NewError(ErrStringExccedLimit).WriteTo(ex.Buffer)
}
bit, err := strconv.Atoi(string(v[2]))
if err != nil || bit != 0 && bit != 1 {
return resp.NewError(ErrBitValueInvalid).WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
exists, tipe, expireAt := ex.DB.Has(v[0])
if exists && tipe != storage.String {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
val := []byte("")
if exists {
val = ex.DB.GetString(v[0])
}
if uint32(len(val)) < byten+1 {
val = append(val, make([]byte, int(byten)+1-len(val))...)
}
k := val[byten] >> uint32(7-pos) & 0x01
switch bit {
case 0:
clear := byte(^(0x01 << (7 - pos)))
val[byten] = val[byten] & clear
case 1:
set := byte(0x01 << (7 - pos))
val[byten] = val[byten] | set
}
ex.DB.PutString(v[0], val, expireAt)
return resp.Integer(k).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:49,代码来源:strings.go
示例10: hstrlen
func hstrlen(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
keyExists, tipe, _ := ex.DB.Has(v[0])
if !keyExists {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
if keyExists && tipe != storage.Hash {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
hash := ex.DB.GetHashFields(v[0], [][]byte{v[1]})
return resp.Integer(len(hash[string(v[1])])).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:15,代码来源:hashes.go
示例11: hlen
func hlen(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
keyExists, tipe, _ := ex.DB.Has(v[0])
if !keyExists {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
if keyExists && tipe != storage.Hash {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
fields := ex.DB.GetHashFieldNames(v[0])
return resp.Integer(len(fields)).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:15,代码来源:hashes.go
示例12: strlen
func strlen(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
exists, tipe, _ := ex.DB.Has(v[0])
if !exists {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
if tipe != storage.String {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
val := ex.DB.GetString(v[0])
return resp.Integer(len(val)).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:15,代码来源:strings.go
示例13: bitcount
func bitcount(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) == 0 {
return resp.NewError(ErrFmtWrongNumberArgument, "bitcount").WriteTo(ex.Buffer)
}
ex.DB.RLock()
defer ex.DB.RUnlock()
val, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
if err == leveldb.ErrNotFound {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
if len(v) != 1 && len(v) != 3 {
return resp.NewError(ErrFmtSyntax).WriteTo(ex.Buffer)
}
start := 0
end := len(val)
if len(v) == 3 {
start, err = strconv.Atoi(string(v[1]))
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
end, err = strconv.Atoi(string(v[2]))
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
start, end = calcRange(start, end, len(val))
}
if end <= start {
return resp.ZeroInteger.WriteTo(ex.Buffer)
}
sum := 0
for _, b := range val[start:end] {
sum += countSetBits[b]
}
return resp.Integer(sum).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:48,代码来源:strings.go
示例14: strlen
func strlen(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.RLock()
defer ex.DB.RUnlock()
s, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
val := int64(0)
if err == leveldb.ErrNotFound {
val = 0
} else {
val = int64(len(s))
}
return resp.Integer(val).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:17,代码来源:strings.go
示例15: exists
func exists(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) == 0 {
return resp.NewError(ErrFmtWrongNumberArgument, "exists").WriteTo(ex.Buffer)
}
ex.DB.RLock()
defer ex.DB.RUnlock()
count := 0
for _, key := range v {
exists, _, _ := ex.DB.Has(key)
if !exists {
continue
}
count++
}
return resp.Integer(count).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:18,代码来源:keys.go
示例16: appendx
// use appendx for append command, because append is a key word of golang
func appendx(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.Lock()
defer ex.DB.Unlock()
val, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
if err == leveldb.ErrNotFound {
val = []byte("")
}
val = append(val, v[1]...)
if err = ex.DB.Put(v[0], val); err != nil {
return err
}
return resp.Integer(len(val)).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:20,代码来源:strings.go
示例17: setbit
func setbit(v resp.CommandArgs, ex *CommandExtras) error {
i64, err := strconv.ParseInt(string(v[1]), 10, 32)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
offset := uint32(i64)
pos := offset % 8
byten := offset / 8
bit, err := strconv.Atoi(string(v[2]))
if err != nil || bit != 0 && bit != 1 {
return resp.NewError(ErrBitValueInvalid).WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
val, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
if uint32(len(val)) < byten+1 {
val = append(val, make([]byte, int(byten)+1-len(val))...)
}
k := val[byten] >> uint32(7-pos) & 0x01
switch bit {
case 0:
clear := byte(^(0x01 << (7 - pos)))
val[byten] = val[byten] & clear
case 1:
set := byte(0x01 << (7 - pos))
val[byten] = val[byten] | set
}
if err := ex.DB.Put(v[0], val); err != nil {
return err
}
return resp.Integer(k).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:41,代码来源:strings.go
示例18: appendx
// use appendx for append command, because append is a key word of golang
func appendx(v resp.CommandArgs, ex *CommandExtras) error {
ex.DB.Lock()
defer ex.DB.Unlock()
exists, tipe, expireAt := ex.DB.Has(v[0])
if exists && tipe != storage.String {
return resp.NewError(ErrWrongType).WriteTo(ex.Buffer)
}
val := []byte("")
if exists {
val = ex.DB.GetString(v[0])
}
if len(val)+len(v[1]) > STRLIMIT {
return resp.NewError(ErrStringExccedLimit).WriteTo(ex.Buffer)
}
val = append(val, v[1]...)
ex.DB.PutString(v[0], val, expireAt)
return resp.Integer(len(val)).WriteTo(ex.Buffer)
}
开发者ID:rod6,项目名称:rodis,代码行数:22,代码来源:strings.go
示例19: incrdecrHelper
func incrdecrHelper(v resp.CommandArgs, ex *CommandExtras, by int64) error {
ex.DB.Lock()
defer ex.DB.Unlock()
s, err := ex.DB.Get(v[0])
if err != nil && err != leveldb.ErrNotFound {
return err
}
val := int64(0)
if err != nil && err == leveldb.ErrNotFound {
val += by
} else {
val, err = strconv.ParseInt(string(s), 10, 64)
if err != nil {
return resp.NewError(ErrNotValidInt).WriteTo(ex.Buffer)
}
val += by
}
if err = ex.DB.Put(v[0], []byte(strconv.FormatInt(val, 10))); err != nil {
return err
}
return resp.Integer(val).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:24,代码来源:strings.go
示例20: del
func del(v resp.CommandArgs, ex *CommandExtras) error {
if len(v) == 0 {
return resp.NewError(ErrFmtWrongNumberArgument, "del").WriteTo(ex.Buffer)
}
ex.DB.Lock()
defer ex.DB.Unlock()
count := 0
for _, key := range v {
_, err := ex.DB.Get(key)
if err != nil && err != leveldb.ErrNotFound {
return err
}
if err == leveldb.ErrNotFound {
continue
}
if err := ex.DB.Delete(key); err != nil {
return err
}
count++
}
return resp.Integer(count).WriteTo(ex.Buffer)
}
开发者ID:zhangshun2014,项目名称:rodis,代码行数:24,代码来源:keys.go
注:本文中的github.com/rod6/rodis/resp.Integer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论