mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-10 03:00:29 +08:00
Add sscan, hscan, zscan
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user