Add sscan, hscan, zscan

This commit is contained in:
lhpqaq
2024-07-23 21:48:31 +08:00
committed by finley
parent c1dd65d84f
commit 75030407cb
13 changed files with 432 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
package set
import (
"github.com/hdt3213/godis/lib/utils"
"strconv"
"testing"
)
@@ -30,3 +31,30 @@ func TestSet(t *testing.T) {
}
}
}
func TestSetScan(t *testing.T) {
set := Make()
size := 10
for i := 0; i < size; i++ {
str := "a" + utils.RandString(5)
set.Add(str)
}
keys, nextCursor := set.SetScan(0, size, "*")
if len(keys) != size {
t.Errorf("expect %d keys, actual: %d", size, len(keys))
return
}
if nextCursor != 0 {
t.Errorf("expect 0, actual: %d", nextCursor)
return
}
for i := 0; i < size; i++ {
str := "b" + utils.RandString(5)
set.Add(str)
}
keys, _ = set.SetScan(0, size*2, "a*")
if len(keys) != size {
t.Errorf("expect %d keys, actual: %d", size, len(keys))
return
}
}