mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 01:07:06 +08:00
add scan command
This commit is contained in:
@@ -465,7 +465,7 @@ func TestConcurrentRemoveWithLock(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
//change t.Error remove->forEach
|
||||
// change t.Error remove->forEach
|
||||
func TestConcurrentForEach(t *testing.T) {
|
||||
d := MakeConcurrent(0)
|
||||
size := 100
|
||||
@@ -524,3 +524,51 @@ func TestConcurrentDict_Keys(t *testing.T) {
|
||||
t.Errorf("expect %d keys, actual: %d", size, len(d.Keys()))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDictScan(t *testing.T) {
|
||||
d := MakeConcurrent(0)
|
||||
count := 100
|
||||
for i := 0; i < count; i++ {
|
||||
key := "kkk" + strconv.Itoa(i)
|
||||
d.Put(key, i)
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
key := "key" + strconv.Itoa(i)
|
||||
d.Put(key, i)
|
||||
}
|
||||
cursor := 0
|
||||
matchKey := "*"
|
||||
c := 20
|
||||
result := make([][]byte, 0)
|
||||
var returnKeys [][]byte
|
||||
for {
|
||||
returnKeys, cursor = d.DictScan(cursor, c, matchKey)
|
||||
result = append(result, returnKeys...)
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
result = utils.RemoveDuplicates(result)
|
||||
if len(result) != count*2 {
|
||||
t.Errorf("scan command result number error: %d, should be %d ", len(result), count*2)
|
||||
}
|
||||
matchKey = "key*"
|
||||
cursor = 0
|
||||
mresult := make([][]byte, 0)
|
||||
for {
|
||||
returnKeys, cursor = d.DictScan(cursor, c, matchKey)
|
||||
mresult = append(mresult, returnKeys...)
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
mresult = utils.RemoveDuplicates(mresult)
|
||||
if len(mresult) != count {
|
||||
t.Errorf("scan command result number error: %d, should be %d ", len(mresult), count)
|
||||
}
|
||||
matchKey = "no*"
|
||||
returnKeys, _ = d.DictScan(cursor, c, matchKey)
|
||||
if len(returnKeys) != 0 {
|
||||
t.Errorf("returnKeys should be empty")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user