File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,34 @@ func hexistsCommand(c Context) {
225
225
c .WriteInt (found )
226
226
}
227
227
228
+ func hlenCommand (c Context ) {
229
+ if len (c .args ) < 1 {
230
+ c .WriteError ("HLEN command requires at least one argument: HLEN <hashmap>" )
231
+ return
232
+ }
233
+
234
+ found := 0
235
+ prefix := c .args [0 ] + "/{HASH}/"
236
+
237
+ err := c .db .Scan (kvstore.ScannerOptions {
238
+ FetchValues : false ,
239
+ IncludeOffset : true ,
240
+ Prefix : prefix ,
241
+ Offset : prefix ,
242
+ Handler : func (_ , _ string ) bool {
243
+ found ++
244
+ return true
245
+ },
246
+ })
247
+
248
+ if err != nil {
249
+ c .WriteError (err .Error ())
250
+ return
251
+ }
252
+
253
+ c .WriteInt (found )
254
+ }
255
+
228
256
// hincrCommand - HINCR <hash> <key> [<number>]
229
257
func hincrCommand (c Context ) {
230
258
if len (c .args ) < 2 {
Original file line number Diff line number Diff line change 77
77
"hexists" : hexistsCommand ,
78
78
"hincr" : hincrCommand ,
79
79
"httl" : httlCommand ,
80
+ "hlen" : hlenCommand ,
80
81
81
82
// pubsub
82
83
"publish" : publishCommand ,
You can’t perform that action at this time.
0 commit comments