File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ Supported Commands
136136- ` HINCR <HASHMAP> <key> [<by>] `
137137- ` HTTL <HASHMAP> <key> ` , the same as ` TTL ` but for ` HASHMAP `
138138- ` HKEYS <HASHMAP> `
139+ - ` HLEN <HASHMAP> `
139140
140141## # LIST
141142> I applied a new concept, you can push or push-unique values into the list,
Original file line number Diff line number Diff line change @@ -225,6 +225,34 @@ func hexistsCommand(c Context) {
225225 c .WriteInt (found )
226226}
227227
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+
228256// hincrCommand - HINCR <hash> <key> [<number>]
229257func hincrCommand (c Context ) {
230258 if len (c .args ) < 2 {
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ func (ldb *LevelDB) Scan(scannerOpt kvstore.ScannerOptions) error {
213213 for iter .Next () {
214214 key := iter .Key ()
215215 val := strings .SplitN (string (iter .Value ()), ";" , 2 )[1 ]
216- if valid (key ) && ! scannerOpt .Handler (string (key ), string (val )) {
216+ if ! valid (key ) || ! scannerOpt .Handler (string (key ), string (val )) {
217217 break
218218 }
219219 }
Original file line number Diff line number Diff line change 7777 "hexists" : hexistsCommand ,
7878 "hincr" : hincrCommand ,
7979 "httl" : httlCommand ,
80+ "hlen" : hlenCommand ,
8081
8182 // pubsub
8283 "publish" : publishCommand ,
You can’t perform that action at this time.
0 commit comments