예제 #1
0
파일: t_ss.go 프로젝트: lessos/lessdb
func (db *DB) SsPut(key, member []byte, score uint64) *skv.Reply {

	batch := new(leveldb.Batch)

	//
	if prev := db.SsGet(key, member); prev.Status == skv.ReplyOK && prev.Uint64() != score {

		batch.Delete(skv.SortSetsNsScoreKey(key, member, prev.Uint64()))

	} else if prev.Status == skv.ReplyNotFound {
		db.RawIncrby(skv.SortSetsNsLengthKey(key), 1)
	}

	//
	batch.Put(skv.SortSetsNsScoreKey(key, member, score), []byte{})

	//
	batch.Put(skv.SortSetsNsEntryKey(key, member), []byte(strconv.FormatUint(score, 10)))

	rpl := skv.NewReply("")

	if err := db.ldb.Write(batch, nil); err != nil {
		rpl.Status = err.Error()
	}

	return rpl
}
예제 #2
0
파일: t_ss.go 프로젝트: lessos/lessdb
func (db *DB) SsDel(key, member []byte) *skv.Reply {

	batch := new(leveldb.Batch)

	batch.Delete(skv.SortSetsNsEntryKey(key, member))

	if prev := db.SsGet(key, member); prev.Status == skv.ReplyOK {
		db.RawIncrby(skv.SortSetsNsLengthKey(key), -1)
		batch.Delete(skv.SortSetsNsScoreKey(key, member, prev.Uint64()))
	}

	rpl := skv.NewReply("")

	if err := db.ldb.Write(batch, nil); err != nil {
		rpl.Status = err.Error()
	}

	return rpl
}