mirror of https://github.com/ledisdb/ledisdb.git
use tiny go package
This commit is contained in:
parent
5bccfd13dc
commit
b7de9e6354
|
@ -3,6 +3,7 @@ package ledis
|
|||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"github.com/siddontang/go/num"
|
||||
"github.com/siddontang/ledisdb/store"
|
||||
"time"
|
||||
)
|
||||
|
@ -332,7 +333,7 @@ func (db *DB) HIncrBy(key []byte, field []byte, delta int64) (int64, error) {
|
|||
|
||||
n += delta
|
||||
|
||||
_, err = db.hSetItem(key, field, StrPutInt64(n))
|
||||
_, err = db.hSetItem(key, field, num.FormatInt64ToSlice(n))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package ledis
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/siddontang/go/num"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -75,7 +76,7 @@ func (db *DB) incr(key []byte, delta int64) (int64, error) {
|
|||
|
||||
n += delta
|
||||
|
||||
t.Put(key, StrPutInt64(n))
|
||||
t.Put(key, num.FormatInt64ToSlice(n))
|
||||
|
||||
err = t.Commit()
|
||||
return n, err
|
||||
|
|
|
@ -509,14 +509,14 @@ func (db *DB) sStoreGeneric(dstKey []byte, optType byte, keys ...[]byte) (int64,
|
|||
t.Put(ek, nil)
|
||||
}
|
||||
|
||||
var num = int64(len(v))
|
||||
var n = int64(len(v))
|
||||
sk := db.sEncodeSizeKey(dstKey)
|
||||
t.Put(sk, PutInt64(num))
|
||||
t.Put(sk, PutInt64(n))
|
||||
|
||||
if err = t.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return num, nil
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (db *DB) SClear(key []byte) (int64, error) {
|
||||
|
|
|
@ -858,14 +858,14 @@ func (db *DB) ZUnionStore(destKey []byte, srcKeys [][]byte, weights []int64, agg
|
|||
}
|
||||
}
|
||||
|
||||
var num = int64(len(destMap))
|
||||
var n = int64(len(destMap))
|
||||
sk := db.zEncodeSizeKey(destKey)
|
||||
t.Put(sk, PutInt64(num))
|
||||
t.Put(sk, PutInt64(n))
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return num, nil
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (db *DB) ZInterStore(destKey []byte, srcKeys [][]byte, weights []int64, aggregate byte) (int64, error) {
|
||||
|
@ -926,14 +926,14 @@ func (db *DB) ZInterStore(destKey []byte, srcKeys [][]byte, weights []int64, agg
|
|||
}
|
||||
}
|
||||
|
||||
var num int64 = int64(len(destMap))
|
||||
var n int64 = int64(len(destMap))
|
||||
sk := db.zEncodeSizeKey(destKey)
|
||||
t.Put(sk, PutInt64(num))
|
||||
t.Put(sk, PutInt64(n))
|
||||
|
||||
if err := t.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return num, nil
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (db *DB) ZScan(key []byte, count int, inclusive bool, match string) ([][]byte, error) {
|
||||
|
|
|
@ -4,13 +4,16 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"github.com/siddontang/go/hack"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var errIntNumber = errors.New("invalid integer")
|
||||
|
||||
/*
|
||||
Below I forget why I use little endian to store int.
|
||||
Maybe I was foolish at that time.
|
||||
*/
|
||||
|
||||
func Int64(v []byte, err error) (int64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -36,11 +39,8 @@ func Uint64(v []byte, err error) (uint64, error) {
|
|||
}
|
||||
|
||||
func PutInt64(v int64) []byte {
|
||||
var b []byte
|
||||
pbytes := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
pbytes.Data = uintptr(unsafe.Pointer(&v))
|
||||
pbytes.Len = 8
|
||||
pbytes.Cap = 8
|
||||
b := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(b, uint64(v))
|
||||
return b
|
||||
}
|
||||
|
||||
|
@ -86,14 +86,6 @@ func StrInt8(v []byte, err error) (int8, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func StrPutInt64(v int64) []byte {
|
||||
return strconv.AppendInt(nil, v, 10)
|
||||
}
|
||||
|
||||
func StrPutUint64(v uint64) []byte {
|
||||
return strconv.AppendUint(nil, v, 10)
|
||||
}
|
||||
|
||||
func AsyncNotify(ch chan struct{}) {
|
||||
select {
|
||||
case ch <- struct{}{}:
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"github.com/siddontang/go/hack"
|
||||
"github.com/siddontang/go/log"
|
||||
"github.com/siddontang/go/num"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"io"
|
||||
"net"
|
||||
|
@ -171,7 +172,7 @@ func (w *respWriter) writeStatus(status string) {
|
|||
|
||||
func (w *respWriter) writeInteger(n int64) {
|
||||
w.buff.WriteByte(':')
|
||||
w.buff.Write(ledis.StrPutInt64(n))
|
||||
w.buff.Write(num.FormatInt64ToSlice(n))
|
||||
w.buff.Write(Delims)
|
||||
}
|
||||
|
||||
|
@ -266,7 +267,7 @@ func (w *respWriter) writeScorePairArray(lst []ledis.ScorePair, withScores bool)
|
|||
w.writeBulk(lst[i].Member)
|
||||
|
||||
if withScores {
|
||||
w.writeBulk(ledis.StrPutInt64(lst[i].Score))
|
||||
w.writeBulk(num.FormatInt64ToSlice(lst[i].Score))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package server
|
|||
import (
|
||||
"errors"
|
||||
"github.com/siddontang/go/hack"
|
||||
|
||||
"github.com/siddontang/go/num"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"math"
|
||||
"strconv"
|
||||
|
@ -75,7 +75,7 @@ func zscoreCommand(c *client) error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
c.resp.writeBulk(ledis.StrPutInt64(s))
|
||||
c.resp.writeBulk(num.FormatInt64ToSlice(s))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -112,7 +112,7 @@ func zincrbyCommand(c *client) error {
|
|||
v, err := c.db.ZIncrBy(key, delta, args[2])
|
||||
|
||||
if err == nil {
|
||||
c.resp.writeBulk(ledis.StrPutInt64(v))
|
||||
c.resp.writeBulk(num.FormatInt64ToSlice(v))
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/siddontang/go/hack"
|
||||
"github.com/siddontang/go/num"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"github.com/siddontang/ledisdb/lua"
|
||||
"io"
|
||||
|
@ -115,7 +116,7 @@ func (w *luaWriter) writeScorePairArray(lst []ledis.ScorePair, withScores bool)
|
|||
w.l.PushString(hack.String(v.Member))
|
||||
w.l.RawSeti(-2, 2*i+1)
|
||||
|
||||
w.l.PushString(hack.String(ledis.StrPutInt64(v.Score)))
|
||||
w.l.PushString(hack.String(num.FormatInt64ToSlice(v.Score)))
|
||||
w.l.RawSeti(-2, 2*i+2)
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue