bug fix: Set size

This commit is contained in:
holys 2014-08-16 14:34:15 +08:00
parent d6c60c60fe
commit e8187843e4
2 changed files with 10 additions and 10 deletions

View File

@ -490,7 +490,6 @@ func (db *DB) sStoreGeneric(dstKey []byte, optType byte, keys ...[]byte) (int64,
var err error var err error
var ek []byte var ek []byte
var num int64 = 0
var v [][]byte var v [][]byte
switch optType { switch optType {
@ -513,22 +512,21 @@ func (db *DB) sStoreGeneric(dstKey []byte, optType byte, keys ...[]byte) (int64,
ek = db.sEncodeSetKey(dstKey, m) ek = db.sEncodeSetKey(dstKey, m)
if v, err := db.db.Get(ek); err != nil { if _, err := db.db.Get(ek); err != nil {
return 0, err return 0, err
} else if v == nil {
num++
} }
t.Put(ek, nil) t.Put(ek, nil)
} }
if _, err = db.sIncrSize(dstKey, num); err != nil { var num = int64(len(v))
sk := db.sEncodeSizeKey(dstKey)
t.Put(sk, PutInt64(num))
if err = t.Commit(); err != nil {
return 0, err return 0, err
} }
return num, nil
err = t.Commit()
return num, err
} }
func (db *DB) SClear(key []byte) (int64, error) { func (db *DB) SClear(key []byte) (int64, error) {

View File

@ -147,7 +147,7 @@ func testUnion(db *DB, t *testing.T) {
m2 := []byte("m2") m2 := []byte("m2")
m3 := []byte("m3") m3 := []byte("m3")
db.SAdd(key, m1, m2) db.SAdd(key, m1, m2)
db.SAdd(key1, m1, m3) db.SAdd(key1, m1, m2, m3)
db.SAdd(key2, m2, m3) db.SAdd(key2, m2, m3)
if _, err := db.sUnionGeneric(key, key2); err != nil { if _, err := db.sUnionGeneric(key, key2); err != nil {
t.Fatal(err) t.Fatal(err)
@ -158,11 +158,13 @@ func testUnion(db *DB, t *testing.T) {
} }
dstkey := []byte("union_dsk") dstkey := []byte("union_dsk")
db.SAdd(dstkey, []byte("x"))
if num, err := db.SUnionStore(dstkey, key1, key2); err != nil { if num, err := db.SUnionStore(dstkey, key1, key2); err != nil {
t.Fatal(err) t.Fatal(err)
} else if num != 3 { } else if num != 3 {
t.Fatal(num) t.Fatal(num)
} }
if _, err := db.SMembers(dstkey); err != nil { if _, err := db.SMembers(dstkey); err != nil {
t.Fatal(err) t.Fatal(err)
} }