1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-12 14:21:52 +03:00

Add ScanType command to Scan with 'type' option

As of version 6.0 you can use this 'type' option to ask SCAN to only
return objects that match a given type, allowing you to
iterate through the database looking for keys of a specific type.
This commit is contained in:
Leandro Forain
2021-01-08 16:36:20 -03:00
parent b3e0aa270a
commit c2351b491a
3 changed files with 57 additions and 0 deletions

View File

@ -770,6 +770,18 @@ var _ = Describe("Commands", func() {
Expect(cursor).NotTo(BeZero())
})
It("should ScanType", func() {
for i := 0; i < 1000; i++ {
set := client.Set(ctx, fmt.Sprintf("key%d", i), "hello", 0)
Expect(set.Err()).NotTo(HaveOccurred())
}
keys, cursor, err := client.ScanType(ctx, 0, "", 0, "string").Result()
Expect(err).NotTo(HaveOccurred())
Expect(keys).NotTo(BeEmpty())
Expect(cursor).NotTo(BeZero())
})
It("should SScan", func() {
for i := 0; i < 1000; i++ {
sadd := client.SAdd(ctx, "myset", fmt.Sprintf("member%d", i))