@@ -2,6 +2,7 @@ package redis_test
2
2
3
3
import (
4
4
"fmt"
5
+ "slices"
5
6
6
7
. "github.com/bsm/ginkgo/v2"
7
8
. "github.com/bsm/gomega"
@@ -52,13 +53,20 @@ var _ = Describe("ScanIterator", func() {
52
53
Expect (client .Close ()).NotTo (HaveOccurred ())
53
54
})
54
55
55
- It ("should scan across empty DBs" , func () {
56
+ It ("should scan across empty DBs using Next " , func () {
56
57
iter := client .Scan (ctx , 0 , "" , 10 ).Iterator ()
57
58
Expect (iter .Next (ctx )).To (BeFalse ())
58
59
Expect (iter .Err ()).NotTo (HaveOccurred ())
59
60
})
60
61
61
- It ("should scan across one page" , func () {
62
+ It ("should scan across empty DBs using Vals" , func () {
63
+ iter := client .Scan (ctx , 0 , "" , 10 ).Iterator ()
64
+ vals := slices .Collect (iter .Vals (ctx ))
65
+ Expect (vals ).To (BeEmpty ())
66
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
67
+ })
68
+
69
+ It ("should scan across one page using Next" , func () {
62
70
Expect (seed (7 )).NotTo (HaveOccurred ())
63
71
64
72
var vals []string
@@ -70,7 +78,16 @@ var _ = Describe("ScanIterator", func() {
70
78
Expect (vals ).To (ConsistOf ([]string {"K01" , "K02" , "K03" , "K04" , "K05" , "K06" , "K07" }))
71
79
})
72
80
73
- It ("should scan across multiple pages" , func () {
81
+ It ("should scan across one page using Vals" , func () {
82
+ Expect (seed (7 )).NotTo (HaveOccurred ())
83
+
84
+ iter := client .Scan (ctx , 0 , "" , 0 ).Iterator ()
85
+ vals := slices .Collect (iter .Vals (ctx ))
86
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
87
+ Expect (vals ).To (ConsistOf ([]string {"K01" , "K02" , "K03" , "K04" , "K05" , "K06" , "K07" }))
88
+ })
89
+
90
+ It ("should scan across multiple pages using Next" , func () {
74
91
Expect (seed (71 )).NotTo (HaveOccurred ())
75
92
76
93
var vals []string
@@ -84,7 +101,18 @@ var _ = Describe("ScanIterator", func() {
84
101
Expect (vals ).To (ContainElement ("K71" ))
85
102
})
86
103
87
- It ("should hscan across multiple pages" , func () {
104
+ It ("should scan across multiple pages using Vals" , func () {
105
+ Expect (seed (71 )).NotTo (HaveOccurred ())
106
+
107
+ iter := client .Scan (ctx , 0 , "" , 10 ).Iterator ()
108
+ vals := slices .Collect (iter .Vals (ctx ))
109
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
110
+ Expect (vals ).To (HaveLen (71 ))
111
+ Expect (vals ).To (ContainElement ("K01" ))
112
+ Expect (vals ).To (ContainElement ("K71" ))
113
+ })
114
+
115
+ It ("should hscan across multiple pages using Next" , func () {
88
116
SkipBeforeRedisVersion (7.4 , "doesn't work with older redis stack images" )
89
117
Expect (hashSeed (71 )).NotTo (HaveOccurred ())
90
118
@@ -100,7 +128,20 @@ var _ = Describe("ScanIterator", func() {
100
128
Expect (vals ).To (ContainElement ("x" ))
101
129
})
102
130
103
- It ("should hscan without values across multiple pages" , Label ("NonRedisEnterprise" ), func () {
131
+ It ("should hscan across multiple pages using Vals" , func () {
132
+ SkipBeforeRedisVersion (7.4 , "doesn't work with older redis stack images" )
133
+ Expect (hashSeed (71 )).NotTo (HaveOccurred ())
134
+
135
+ iter := client .HScan (ctx , hashKey , 0 , "" , 10 ).Iterator ()
136
+ vals := slices .Collect (iter .Vals (ctx ))
137
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
138
+ Expect (vals ).To (HaveLen (71 * 2 ))
139
+ Expect (vals ).To (ContainElement ("K01" ))
140
+ Expect (vals ).To (ContainElement ("K71" ))
141
+ Expect (vals ).To (ContainElement ("x" ))
142
+ })
143
+
144
+ It ("should hscan without values across multiple pages using Next" , Label ("NonRedisEnterprise" ), func () {
104
145
SkipBeforeRedisVersion (7.4 , "doesn't work with older redis stack images" )
105
146
Expect (hashSeed (71 )).NotTo (HaveOccurred ())
106
147
@@ -116,7 +157,20 @@ var _ = Describe("ScanIterator", func() {
116
157
Expect (vals ).NotTo (ContainElement ("x" ))
117
158
})
118
159
119
- It ("should scan to page borders" , func () {
160
+ It ("should hscan without values across multiple pages using Vals" , Label ("NonRedisEnterprise" ), func () {
161
+ SkipBeforeRedisVersion (7.4 , "doesn't work with older redis stack images" )
162
+ Expect (hashSeed (71 )).NotTo (HaveOccurred ())
163
+
164
+ iter := client .HScanNoValues (ctx , hashKey , 0 , "" , 10 ).Iterator ()
165
+ vals := slices .Collect (iter .Vals (ctx ))
166
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
167
+ Expect (vals ).To (HaveLen (71 ))
168
+ Expect (vals ).To (ContainElement ("K01" ))
169
+ Expect (vals ).To (ContainElement ("K71" ))
170
+ Expect (vals ).NotTo (ContainElement ("x" ))
171
+ })
172
+
173
+ It ("should scan to page borders using Next" , func () {
120
174
Expect (seed (20 )).NotTo (HaveOccurred ())
121
175
122
176
var vals []string
@@ -128,7 +182,16 @@ var _ = Describe("ScanIterator", func() {
128
182
Expect (vals ).To (HaveLen (20 ))
129
183
})
130
184
131
- It ("should scan with match" , func () {
185
+ It ("should scan to page borders using Vals" , func () {
186
+ Expect (seed (20 )).NotTo (HaveOccurred ())
187
+
188
+ iter := client .Scan (ctx , 0 , "" , 10 ).Iterator ()
189
+ vals := slices .Collect (iter .Vals (ctx ))
190
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
191
+ Expect (vals ).To (HaveLen (20 ))
192
+ })
193
+
194
+ It ("should scan with match using Next" , func () {
132
195
Expect (seed (33 )).NotTo (HaveOccurred ())
133
196
134
197
var vals []string
@@ -140,7 +203,16 @@ var _ = Describe("ScanIterator", func() {
140
203
Expect (vals ).To (HaveLen (13 ))
141
204
})
142
205
143
- It ("should scan with match across empty pages" , func () {
206
+ It ("should scan with match using Vals" , func () {
207
+ Expect (seed (33 )).NotTo (HaveOccurred ())
208
+
209
+ iter := client .Scan (ctx , 0 , "K*2*" , 10 ).Iterator ()
210
+ vals := slices .Collect (iter .Vals (ctx ))
211
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
212
+ Expect (vals ).To (HaveLen (13 ))
213
+ })
214
+
215
+ It ("should scan with match across empty pages using Next" , func () {
144
216
Expect (extraSeed (2 , 10 )).NotTo (HaveOccurred ())
145
217
146
218
var vals []string
@@ -151,4 +223,13 @@ var _ = Describe("ScanIterator", func() {
151
223
Expect (iter .Err ()).NotTo (HaveOccurred ())
152
224
Expect (vals ).To (HaveLen (2 ))
153
225
})
226
+
227
+ It ("should scan with match across empty pages using Vals" , func () {
228
+ Expect (extraSeed (2 , 10 )).NotTo (HaveOccurred ())
229
+
230
+ iter := client .Scan (ctx , 0 , "K*" , 1 ).Iterator ()
231
+ vals := slices .Collect (iter .Vals (ctx ))
232
+ Expect (iter .Err ()).NotTo (HaveOccurred ())
233
+ Expect (vals ).To (HaveLen (2 ))
234
+ })
154
235
})
0 commit comments