Beispiel #1
0
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
}
Beispiel #2
0
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
}
Beispiel #3
0
func (db *DB) SsGet(key, member []byte) *skv.Reply {
	return db.RawGet(skv.SortSetsNsEntryKey(key, member))
}