Skip to content

Commit e0697d9

Browse files
committed
Merge branch 'master' of https://github.com/alash3al/redix
2 parents e833d03 + c8f5ccb commit e0697d9

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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,

commands_hash.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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>]
229257
func hincrCommand(c Context) {
230258
if len(c.args) < 2 {

kvstore/leveldb/leveldb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

vars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var (
7777
"hexists": hexistsCommand,
7878
"hincr": hincrCommand,
7979
"httl": httlCommand,
80+
"hlen": hlenCommand,
8081

8182
// pubsub
8283
"publish": publishCommand,

0 commit comments

Comments
 (0)