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

@@ -2,6 +2,7 @@ package set
import (
"github.com/hdt3213/godis/datastruct/dict"
"github.com/hdt3213/godis/lib/wildcard"
)
// Set is a set of elements based on hash table
@@ -149,3 +150,20 @@ func (set *Set) RandomMembers(limit int) []string {
func (set *Set) RandomDistinctMembers(limit int) []string {
return set.dict.RandomDistinctKeys(limit)
}
// Scan set with cursor and pattern
func (set *Set) SetScan(cursor int, count int, pattern string) ([][]byte, int) {
result := make([][]byte, 0)
matchKey, err := wildcard.CompilePattern(pattern)
if err != nil {
return result, -1
}
set.ForEach(func(member string) bool {
if pattern == "*" || matchKey.IsMatch(member) {
result = append(result, []byte(member))
}
return true
})
return result, 0
}