No matching definitions.

valkey/pubsub

src/valkey/pubsub.tur
defn

pubsub-subscribe

(pubsub-subscribe [c :int channel :cstr] :ptr<void>)

subscribe the connection to a channel.

cctx-ptr (ok-val from client-connect; dedicate this connection)
channelchannel name string

(ok 0) on success; (err 0) on failure.

(let [r (pubsub-subscribe c "events")]
    (if (ok? r) (println "subscribed") (println "subscribe failed")))

Since: VK0

defn

pubsub-unsubscribe

(pubsub-unsubscribe [c :int channel :cstr] :ptr<void>)

unsubscribe the connection from a channel.

cctx-ptr (ok-val from client-connect)
channelchannel name string

(ok 0) on success; (err 0) on failure.

(let [r (pubsub-unsubscribe c "events")]
    (if (ok? r) (println "unsubscribed") (println "unsubscribe failed")))

Since: VK0

defn

pubsub-publish

(pubsub-publish [c :int channel :cstr message :cstr] :ptr<void>)

publish a message to a channel.

cctx-ptr for a non-subscribe connection
channelchannel name string
messagemessage payload string

(ok count) where count is the number of subscribers that received the message; (err 0) on failure.

(let [r (pubsub-publish pub "events" "hello")]
    (if (ok? r) (println (ok-val r)) (println "publish failed")))

Since: VK0

defn

pubsub-recv

(pubsub-recv [c :int] :ptr<void>)

block until a message is received on a subscribed connection.

cctx-ptr (ok-val from client-connect; must have called pubsub-subscribe)

(ok msg-ptr) when a "message" push is received; msg-ptr is a heap-allocated message struct -- inspect with message-channel and message-payload. (ok 0) for non-message pushes (subscribe confirmations, etc.). (err 0) on connection error.

(let [r (pubsub-recv c)]
    (if (ok? r)
      (let [m (ok-val r)]
        (if (!= m 0)
          (println (message-payload m))
          (println "non-message push")))
      (println "recv error")))

Since: VK0

defn

message-channel

(message-channel [m :int] :cstr)

return the channel name from a received message struct.

mmsg-ptr (ok-val from pubsub-recv, must not be 0)

Channel name as :cstr; valid until the message struct is freed.

(message-channel m)  ; => "events"

Since: VK0

defn

message-payload

(message-payload [m :int] :cstr)

return the payload string from a received message struct.

mmsg-ptr (ok-val from pubsub-recv, must not be 0)

Payload string as :cstr; valid until the message struct is freed.

(message-payload m)  ; => "hello"

Since: VK0

Internal definitions
__ok-- create an ok result wrapping integer value v.
__err-- create an err result wrapping integer error value e.