valkey/cmd
cmd
(cmd [c :int command :cstr args :int] :ptr<void>)
send an arbitrary command with a cons list of string arguments.
| c | ctx-ptr (ok-val from client-connect) | |
| command | command name string (e.g. "SET") | |
| args | cons list of :cstr argument strings; use 0 for empty list |
(ok reply-ptr) on success; (err 0) on error or NULL reply. Call reply-free on the reply-ptr when done.
(let [r (cmd c "SET" (cons "mykey" (cons "myval" 0)))]
(if (ok? r) (reply-free (ok-val r)) (println "cmd failed")))
Since: VK0
cmd-get
(cmd-get [c :int key :cstr] :ptr<void>)
send GET key.
| c | ctx-ptr (ok-val from client-connect) | |
| key | key name string |
(ok reply-ptr) on success; (err 0) on error. Call reply-free on the reply-ptr when done.
(let [r (cmd-get c "mykey")]
(if (ok? r) (println (reply-string (ok-val r))) (println "get failed")))
Since: VK0
cmd-set
(cmd-set [c :int key :cstr val :cstr] :ptr<void>)
send SET key value.
| c | ctx-ptr (ok-val from client-connect) | |
| key | key name string | |
| val | value string |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-set c "mykey" "hello")]
(if (ok? r) (reply-free (ok-val r)) (println "set failed")))
Since: VK0
cmd-del
(cmd-del [c :int key :cstr] :ptr<void>)
send DEL key.
| c | ctx-ptr (ok-val from client-connect) | |
| key | key name string |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-del c "mykey")]
(if (ok? r) (reply-free (ok-val r)) (println "del failed")))
Since: VK0
cmd-incr
(cmd-incr [c :int key :cstr] :ptr<void>)
send INCR key.
| c | ctx-ptr (ok-val from client-connect) | |
| key | key name string |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-incr c "counter")]
(if (ok? r) (println (reply-int (ok-val r))) (println "incr failed")))
Since: VK0
cmd-expire
(cmd-expire [c :int key :cstr seconds :cstr] :ptr<void>)
send EXPIRE key seconds.
| c | ctx-ptr (ok-val from client-connect) | |
| key | key name string | |
| seconds | expiry duration as a decimal string (e.g. "60") |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-expire c "session" "3600")]
(if (ok? r) (reply-free (ok-val r)) (println "expire failed")))
Since: VK0
cmd-hset
(cmd-hset [c :int hash :cstr field :cstr val :cstr] :ptr<void>)
send HSET hash field value.
| c | ctx-ptr (ok-val from client-connect) | |
| hash | hash key name | |
| field | field name within the hash | |
| val | value string |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-hset c "user:1" "name" "Alice")]
(if (ok? r) (reply-free (ok-val r)) (println "hset failed")))
Since: VK0
cmd-hget
(cmd-hget [c :int hash :cstr field :cstr] :ptr<void>)
send HGET hash field.
| c | ctx-ptr (ok-val from client-connect) | |
| hash | hash key name | |
| field | field name within the hash |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-hget c "user:1" "name")]
(if (ok? r) (println (reply-string (ok-val r))) (println "hget failed")))
Since: VK0
cmd-lpush
(cmd-lpush [c :int list :cstr val :cstr] :ptr<void>)
send LPUSH list value.
| c | ctx-ptr (ok-val from client-connect) | |
| list | list key name | |
| val | value string to prepend |
(ok reply-ptr) on success; (err 0) on error.
(let [r (cmd-lpush c "mylist" "item")]
(if (ok? r) (reply-free (ok-val r)) (println "lpush failed")))
Since: VK0
cmd-lrange
(cmd-lrange [c :int list :cstr start :int stop :int] :ptr<void>)
send LRANGE list start stop.
| c | ctx-ptr (ok-val from client-connect) | |
| list | list key name | |
| start | 0-based start index (inclusive) | |
| stop | 0-based stop index (inclusive; -1 for last element) |
(ok reply-ptr) on success; (err 0) on error. Reply type is array; use reply-array-len and reply-array-get to iterate.
(let [r (cmd-lrange c "mylist" 0 -1)]
(if (ok? r) (let [rep (ok-val r)] ...) (println "lrange failed")))
Since: VK0
Internal definitions
__ok-- create an ok result wrapping integer value v.__err-- create an err result wrapping integer error value e.