本文整理汇总了Golang中github.com/jmhodges/levigo.WriteBatch类的典型用法代码示例。如果您正苦于以下问题:Golang WriteBatch类的具体用法?Golang WriteBatch怎么用?Golang WriteBatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WriteBatch类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Sadd
func Sadd(args [][]byte, wb *levigo.WriteBatch) interface{} {
var newMembers uint32
key := NewKeyBuffer(SetKey, args[0], len(args[1]))
mk := metaKey(args[0])
card, err := scard(mk, nil)
if err != nil {
return err
}
for _, member := range args[1:] {
key.SetSuffix(member)
if card > 0 {
res, err := DB.Get(DefaultReadOptions, key.Key())
if err != nil {
return err
}
if res != nil {
continue
}
}
wb.Put(key.Key(), []byte{})
newMembers++
}
if newMembers > 0 {
setCard(mk, card+newMembers, wb)
}
return newMembers
}
开发者ID:scozss,项目名称:setdb,代码行数:28,代码来源:set.go
示例2: Hincrby
func Hincrby(args [][]byte, wb *levigo.WriteBatch) interface{} {
mk := metaKey(args[0])
length, err := hlen(mk, nil)
if err != nil {
return err
}
key := NewKeyBufferWithSuffix(HashKey, args[0], args[1]).Key()
res, err := DB.Get(DefaultReadOptions, key)
if err != nil {
return err
}
var current int64
if res != nil {
current, err = bconv.ParseInt(res, 10, 64)
if err != nil {
return InvalidIntError
}
}
increment, err := bconv.ParseInt(args[2], 10, 64)
if err != nil {
return InvalidIntError
}
result := strconv.AppendInt(nil, current+increment, 10)
wb.Put(key, result)
// if is a new key, increment the hash length
if res == nil {
setHlen(mk, length+1, wb)
}
return result
}
开发者ID:scozss,项目名称:setdb,代码行数:32,代码来源:hash.go
示例3: Hdel
func Hdel(args [][]byte, wb *levigo.WriteBatch) interface{} {
mk := metaKey(args[0])
length, err := hlen(mk, nil)
if err != nil {
return err
}
if length == 0 {
return 0
}
var deleted uint32
key := NewKeyBuffer(HashKey, args[0], len(args[1]))
for _, field := range args[1:] {
key.SetSuffix(field)
res, err := DB.Get(ReadWithoutCacheFill, key.Key())
if err != nil {
return err
}
if res == nil {
continue
}
wb.Delete(key.Key())
deleted++
}
if deleted == length {
wb.Delete(mk)
} else if deleted > 0 {
setHlen(mk, length-deleted, wb)
}
return deleted
}
开发者ID:scozss,项目名称:setdb,代码行数:31,代码来源:hash.go
示例4: Hincrbyfloat
func Hincrbyfloat(args [][]byte, wb *levigo.WriteBatch) interface{} {
mk := metaKey(args[0])
length, err := hlen(mk, nil)
if err != nil {
return err
}
key := NewKeyBufferWithSuffix(HashKey, args[0], args[1]).Key()
res, err := DB.Get(DefaultReadOptions, key)
if err != nil {
return err
}
var current float64
if res != nil {
current, err = bconv.ParseFloat(res, 64)
if err != nil {
return fmt.Errorf("hash value is not a valid float")
}
}
increment, err := bconv.ParseFloat(args[2], 64)
if err != nil {
return fmt.Errorf("value is not a valid float")
}
result := strconv.AppendFloat(nil, current+increment, 'f', -1, 64)
wb.Put(key, result)
// if is a new key, increment the hash length
if res == nil {
setHlen(mk, length+1, wb)
}
return result
}
开发者ID:scozss,项目名称:setdb,代码行数:32,代码来源:hash.go
示例5: Hmset
func Hmset(args [][]byte, wb *levigo.WriteBatch) interface{} {
if (len(args)-1)%2 != 0 {
return fmt.Errorf("wrong number of arguments for 'hmset' command")
}
mk := metaKey(args[0])
length, err := hlen(mk, nil)
if err != nil {
return err
}
var added uint32
key := NewKeyBuffer(HashKey, args[0], len(args[1]))
for i := 1; i < len(args); i += 2 {
key.SetSuffix(args[i])
var res []byte
if length > 0 {
res, err = DB.Get(DefaultReadOptions, key.Key())
if err != nil {
return err
}
}
if res == nil {
added++
}
wb.Put(key.Key(), args[i+1])
}
if added > 0 {
setHlen(mk, length+added, wb)
}
return ReplyOK
}
开发者ID:scozss,项目名称:setdb,代码行数:32,代码来源:hash.go
示例6: Srem
func Srem(args [][]byte, wb *levigo.WriteBatch) interface{} {
mk := metaKey(args[0])
card, err := scard(mk, nil)
if err != nil {
return err
}
if card == 0 {
return card
}
var deleted uint32
key := NewKeyBuffer(SetKey, args[0], len(args[1]))
for _, member := range args[1:] {
key.SetSuffix(member)
res, err := DB.Get(ReadWithoutCacheFill, key.Key())
if err != nil {
return err
}
if res == nil {
continue
}
wb.Delete(key.Key())
deleted++
}
if deleted == card {
wb.Delete(mk)
} else if deleted > 0 { // decrement the cardinality
setCard(mk, card-deleted, wb)
}
return deleted
}
开发者ID:scozss,项目名称:setdb,代码行数:30,代码来源:set.go
示例7: lpush
func lpush(args [][]byte, left bool, create bool, wb *levigo.WriteBatch) (interface{}, error) {
mk := metaKey(args[0])
l, err := llen(mk, nil)
if err != nil {
return nil, err
}
if create || l.length > 0 {
key := NewKeyBuffer(ListKey, args[0], 8)
for _, value := range args[1:] {
l.length++
var seq int64
if left {
seq = l.left
l.left--
} else {
seq = l.right
l.right++
}
// To sort negative ints in order before positive, we subtract math.MinInt64
// which wraps the numbers around and sorts correctly
binary.BigEndian.PutUint64(key.SuffixForRead(8), uint64(seq-math.MinInt64))
wb.Put(key.Key(), value)
}
setLlen(mk, l, wb)
}
return l.length, nil
}
开发者ID:scozss,项目名称:setdb,代码行数:27,代码来源:list.go
示例8: setLlen
func setLlen(key []byte, l *listDetails, wb *levigo.WriteBatch) {
data := make([]byte, 22)
data[0] = ListLengthValue
binary.BigEndian.PutUint32(data[1:], l.length)
data[5] = l.flags
binary.BigEndian.PutUint64(data[6:], uint64(l.left))
binary.BigEndian.PutUint64(data[14:], uint64(l.right))
wb.Put(key, data)
}
开发者ID:scozss,项目名称:setdb,代码行数:9,代码来源:list.go
示例9: AddIndex
func AddIndex(index [2]string, key []byte, indexDb *levigo.DB, wb *levigo.WriteBatch) error {
searchKey := []byte(index[0] + "~" + index[1])
keys, err := indexDb.Get(LReadOptions, searchKey)
if err != nil {
return err
}
keys = appendDataKey(keys, key)
wb.Put(searchKey, keys)
return nil
}
开发者ID:shyrobbiani,项目名称:levelupdb,代码行数:10,代码来源:index.go
示例10: combineSet
func combineSet(keys [][]byte, op int, wb *levigo.WriteBatch) interface{} {
var count uint32
res := []interface{}{}
members := make(chan *iterSetMember)
var storeKey *KeyBuffer
var mk []byte
if wb != nil {
mk = metaKey(keys[0])
_, err := delKey(mk, wb)
if err != nil {
return err
}
storeKey = NewKeyBuffer(SetKey, keys[0], 0)
keys = keys[1:]
}
go multiSetIter(keys, members, op != setUnion)
combine:
for m := range members {
switch op {
case setInter:
for _, k := range m.exists {
if !k {
continue combine
}
}
case setDiff:
for i, k := range m.exists {
if i == 0 && !k || i > 0 && k {
continue combine
}
}
}
if wb != nil {
storeKey.SetSuffix(m.member)
wb.Put(storeKey.Key(), []byte{})
count++
} else {
res = append(res, m.member)
}
}
if wb != nil {
if count > 0 {
setCard(mk, count, wb)
}
return count
}
return res
}
开发者ID:scozss,项目名称:setdb,代码行数:53,代码来源:set.go
示例11: DelHash
func DelHash(key []byte, wb *levigo.WriteBatch) {
it := DB.NewIterator(ReadWithoutCacheFill)
defer it.Close()
iterKey := NewKeyBuffer(HashKey, key, 0)
for it.Seek(iterKey.Key()); it.Valid(); it.Next() {
k := it.Key()
if !iterKey.IsPrefixOf(k) {
break
}
wb.Delete(k)
}
}
开发者ID:scozss,项目名称:setdb,代码行数:12,代码来源:hash.go
示例12: RemoveIndex
// TODO: refactor with above.
func RemoveIndex(index [2]string, key []byte, indexDb *levigo.DB, wb *levigo.WriteBatch) error {
searchKey := []byte(index[0] + "~" + index[1])
keys, err := indexDb.Get(LReadOptions, searchKey)
if err != nil {
return err
}
keys = removeDataKey(keys, key)
if len(keys) > 0 {
wb.Put(searchKey, keys)
} else {
wb.Delete(searchKey)
}
return nil
}
开发者ID:shyrobbiani,项目名称:levelupdb,代码行数:15,代码来源:index.go
示例13: DelSet
func DelSet(key []byte, wb *levigo.WriteBatch) {
it := DB.NewIterator(ReadWithoutCacheFill)
defer it.Close()
iterKey := NewKeyBuffer(SetKey, key, 0)
for it.Seek(iterKey.Key()); it.Valid(); it.Next() {
k := it.Key()
// If the prefix of the current key doesn't match the iteration key,
// we have reached the end of the set
if !iterKey.IsPrefixOf(k) {
break
}
wb.Delete(k)
}
}
开发者ID:scozss,项目名称:setdb,代码行数:14,代码来源:set.go
示例14: delKey
func delKey(key []byte, wb *levigo.WriteBatch) (deleted bool, err error) {
res, err := DB.Get(ReadWithoutCacheFill, key)
if err != nil {
return
}
if res == nil {
return
}
if len(res) < 1 {
return false, InvalidDataError
}
del(key[1:], res[0], wb)
wb.Delete(key)
return true, nil
}
开发者ID:scozss,项目名称:setdb,代码行数:15,代码来源:commands.go
示例15: lpop
func lpop(key []byte, left bool, wb *levigo.WriteBatch) (interface{}, error) {
mk := metaKey(key)
l, err := llen(mk, nil)
if err != nil {
return nil, err
}
if l.length == 0 {
return nil, nil
}
iterKey := NewKeyBuffer(ListKey, key, 0)
it := DB.NewIterator(ReadWithoutCacheFill)
defer it.Close()
if !left {
iterKey.ReverseIterKey()
}
it.Seek(iterKey.Key())
if !left {
it.Prev()
}
if !it.Valid() {
return nil, nil
}
k := it.Key()
if !iterKey.IsPrefixOf(k) {
return nil, nil
}
res := it.Value()
wb.Delete(k)
l.length--
if l.length == 0 {
wb.Delete(mk)
} else {
// decode the sequence number from the list item key
seq := int64(binary.BigEndian.Uint64(k[len(key)+5:])) + math.MinInt64
if left {
l.left = seq
} else {
l.right = seq
}
setLlen(mk, l, wb)
}
return res, nil
}
开发者ID:scozss,项目名称:setdb,代码行数:46,代码来源:list.go
示例16: set
func set(k []byte, v []byte, wb *levigo.WriteBatch) error {
mk := metaKey(k)
res, err := DB.Get(DefaultReadOptions, mk)
if err != nil {
return err
}
// If there is a non-string key here, let's delete it first
if len(res) > 0 && res[0] != StringLengthValue {
del(k, res[0], wb)
}
setStringLen(mk, len(v), wb)
wb.Put(stringKey(k), v)
return nil
}
开发者ID:scozss,项目名称:setdb,代码行数:17,代码来源:string.go
示例17: DelZset
func DelZset(key []byte, wb *levigo.WriteBatch) {
// TODO: count keys to verify everything works as expected?
it := DB.NewIterator(ReadWithoutCacheFill)
defer it.Close()
iterKey := NewKeyBuffer(ZSetKey, key, 0)
scoreKey := NewKeyBuffer(ZScoreKey, key, 0)
for it.Seek(iterKey.Key()); it.Valid(); it.Next() {
k := it.Key()
// If the prefix of the current key doesn't match the iteration key,
// we have reached the end of the zset
if !iterKey.IsPrefixOf(k) {
break
}
wb.Delete(k)
setZScoreKeyMember(scoreKey, k[len(iterKey.Key()):])
setZScoreKeyScore(scoreKey, btof(it.Value()))
wb.Delete(scoreKey.Key())
}
}
开发者ID:scozss,项目名称:setdb,代码行数:20,代码来源:zset.go
示例18: TestCommands
func (s CommandSuite) TestCommands(c *C) {
for _, t := range tests {
cmd := commands[t.command]
var wb *levigo.WriteBatch
if cmd.writes {
wb = levigo.NewWriteBatch()
}
var args [][]byte
if t.args != "" {
if cmd.arity > 0 {
args = bytes.SplitN([]byte(t.args), []byte(" "), cmd.arity)
} else {
args = bytes.Split([]byte(t.args), []byte(" "))
}
}
cmd.lockKeys(args)
res := cmd.function(args, wb)
if cmd.writes {
err := DB.Write(DefaultWriteOptions, wb)
c.Assert(err, IsNil)
wb.Close()
}
cmd.unlockKeys(args)
if stream, ok := res.(*cmdReplyStream); ok {
items := make([]interface{}, 0, int(stream.size))
for item := range stream.items {
items = append(items, item)
}
res = items
}
if reply, ok := res.(rawReply); ok {
if reply[0] == '+' {
res = string(reply[1 : len(reply)-2])
}
}
c.Assert(res, DeepEquals, t.response, Commentf("%s %s, obtained=%s expected=%s", t.command, t.args, res, t.response))
}
}
开发者ID:scozss,项目名称:setdb,代码行数:38,代码来源:command_test.go
示例19: hset
func hset(args [][]byte, overwrite bool, wb *levigo.WriteBatch) interface{} {
mk := metaKey(args[0])
length, err := hlen(mk, nil)
if err != nil {
return err
}
var res []byte
key := NewKeyBufferWithSuffix(HashKey, args[0], args[1]).Key()
if length > 0 {
res, err = DB.Get(DefaultReadOptions, key)
if err != nil {
return err
}
}
if overwrite || res == nil {
wb.Put(key, args[2])
}
if res == nil {
setHlen(mk, length+1, wb)
return 1
}
return 0
}
开发者ID:scozss,项目名称:setdb,代码行数:23,代码来源:hash.go
示例20: Spop
func Spop(args [][]byte, wb *levigo.WriteBatch) interface{} {
mk := metaKey(args[0])
card, err := scard(mk, nil)
if err != nil {
return err
}
if card == 0 {
return nil
}
key := NewKeyBuffer(SetKey, args[0], 1)
member := srand(key)
if member == nil {
return nil
}
key.SetSuffix(member)
wb.Delete(key.Key())
if card == 1 { // we're removing the last remaining member
wb.Delete(mk)
} else {
setCard(mk, card-1, wb)
}
return member
}
开发者ID:scozss,项目名称:setdb,代码行数:23,代码来源:set.go
注:本文中的github.com/jmhodges/levigo.WriteBatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论