Browse Source

Add HFIND command

tags/v0.18.1
Alex Williams 11 months ago
parent
commit
b7d74a0dd6
Signed by: aw GPG Key ID: 19EE4AAA361A7E2C
  1. 6
      CHANGELOG.md
  2. 1
      COMMANDS.md
  3. 1
      README.md
  4. 1
      client.l
  5. 5
      libkv.l
  6. 2
      module.l
  7. 12
      test/test_kv_hashes.l

6
CHANGELOG.md

@ -1,5 +1,11 @@
# Changelog
## 0.18.1 (2020-11-12)
### New features
* [commands] Add the following Hash COMMAND: `HFIND`
## 0.18.0 (2020-11-10)
### New features

1
COMMANDS.md

@ -17,6 +17,7 @@ Most `COMMANDS` take the exact same arguments, and return the same type of value
| [GETSET](#getset) key value | Set the string value of a key and return its old value |
| [HDEL](#hdel) key field [field ..] | Delete one or more hash fields |
| [HEXISTS](#hexists) key field | Determine if a hash field exists |
| [HFIND](#hfind) key substring | Find a substring in a hash key's field |
| [HGET](#hget) key field | Get the value of a hash field |
| [HGETALL](#hgetall) key | Get all the fields and values in a hash |
| [HKEYS](#hkeys) key | Get all the fields in a hash |

1
README.md

@ -154,6 +154,7 @@ COMMAND LIST Commands are case-insensitive and don't always require
GETSET key value Set the string value of a key and return its old value
HDEL key field [field ..] Delete one or more hash fields
HEXISTS key field Determine if a hash field exists
HFIND key substring Find a substring in a hash key's field
HGET key field Get the value of a hash field
HGETALL key Get all the fields and values in a hash
HKEYS key Get all the fields in a hash

1
client.l

@ -36,6 +36,7 @@
("GETSET key value" "^I^ISet the string value of a key and return its old value")
("HDEL key field [field ..]" "^I^IDelete one or more hash fields")
("HEXISTS key field" "^I^IDetermine if a hash field exists")
("HFIND key substring" "^I^IFind a substring in a hash key's field")
("HGET key field" "^I^IGet the value of a hash field")
("HGETALL key" "^I^IGet all the fields and values in a hash")
("HKEYS key" "^I^IGet all the fields in a hash")

5
libkv.l

@ -63,6 +63,7 @@
["GETSET" (kv-cmd-getset Key Value) ]
["HDEL" (kv-cmd-hdel Key (cdadr Request) ]
["HEXISTS" (kv-cmd-hexists Key Value) ]
["HFIND" (kv-cmd-hfind Key Value) ]
["HGET" (kv-cmd-hget Key Value) ]
["HGETALL" (kv-cmd-hgetall Key) ]
["HKEYS" (kv-cmd-hkeys Key) ]
@ -155,6 +156,10 @@
1
0 ]
[de kv-cmd-hfind (Key Substring)
(when (and Substring (kv-check-key Key 'lst))
(extract '((N) (car (sub? Substring (car N)))) (kv-value Key)) ]
[de kv-cmd-hget (Key Field)
(cdr (assoc Field (kv-value Key) ]

2
module.l

@ -1,6 +1,6 @@
[de APP_INFO
("name" "picolisp-kv")
("version" "0.18.0")
("version" "0.18.1")
("summary" "Redis-inspired in-memory key/value store written in PicoLisp")
("source" "https://github.com/aw/picolisp-kv")
("author" "Alexander Williams")

12
test/test_kv_hashes.l

@ -23,6 +23,17 @@
(assert-equal 1 (kv-cmd-hexists "hashexistskey" "one") "[HEXISTS] Should return 1 if the key and field exists")
]
[de test-commands-hfind ()
(kv-cmd-hset "hfindkey" '("one" "1" "two" "2"))
(kv-cmd-set "hashfindkeyz" "string")
(assert-nil (kv-cmd-hfind) "[HFIND] Should return NIL if no key is provided")
(assert-nil (kv-cmd-hfind "hfindkey") "[HFIND] Should return NIL if no substring is provided")
(assert-nil (kv-cmd-hget "hashfindkeyz") "[HFIND] Should return NIL if key is not a list")
(assert-nil (kv-cmd-hfind "hashkeyzmissing") "[HFIND] Should return NIL if the key doesn't exist")
(assert-nil (kv-cmd-hfind "hfindkey" "three") "[HFIND] Should return 0 if the substring doesn't exist")
(assert-equal '("one") (kv-cmd-hfind "hfindkey" "one") "[HFIND] Should return 'one' if the key and substring exists")
]
[de test-commands-hget ()
(kv-cmd-hset "hashgetkey" '("one" "1" "two" "2"))
(kv-cmd-set "hashkeyz" "string")
@ -103,6 +114,7 @@
[execute
'(test-commands-hdel)
'(test-commands-hexists)
'(test-commands-hfind)
'(test-commands-hget)
'(test-commands-hgetall)
'(test-commands-hkeys)

Loading…
Cancel
Save