示例#1
0
文件: engine.go 项目: l-k-/origins
func (t *Tx) Incr(p, k string) (uint64, error) {
	b, err := t.tx.CreateBucketIfNotExists([]byte(p))

	if err != nil {
		return 0, err
	}

	key := []byte(k)

	buf := b.Get(key)

	var id uint64

	if buf != nil {
		id = storage.DecodeCounter(buf)
	}

	id++

	if err = b.Put(key, storage.EncodeCounter(id)); err != nil {
		return 0, err
	}

	return id, err
}
示例#2
0
文件: engine.go 项目: l-k-/origins
func (t *Tx) Incr(p, k string) (uint64, error) {
	var (
		ok bool
		id uint64
		v  []byte
		b  map[string][]byte
	)

	if b, ok = t.e.parts[p]; !ok {
		b = make(map[string][]byte)
		t.e.parts[p] = b
	}

	if v, ok = b[k]; ok {
		id = storage.DecodeCounter(v)
	}

	id++

	b[k] = storage.EncodeCounter(id)

	return id, nil
}