No matching definitions.

valkey/pubsub

src/valkey/pubsub.tur
defopaque

Message

(Message)

opaque handle to a received pub/sub message.

Since: 0.3.0

defn

pubsub-subscribe

(pubsub-subscribe [^borrow c : Client channel : cstr] :)

subscribe the connection to a channel.

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

(Result int int) -- ok carries 0; err carries 0 on failure.

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

Since: VK0

defn

pubsub-unsubscribe

(pubsub-unsubscribe [^borrow c : Client channel : cstr] :)

unsubscribe the connection from a channel.

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

(Result int int) -- ok carries 0; err carries 0 on failure.

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

Since: VK0

defn

pubsub-publish

(pubsub-publish [^borrow c : Client channel : cstr message : cstr] :)

publish a message to a channel.

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

(Result int int) -- ok carries the subscriber count; err carries 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 [^borrow c : Client] :)

block until a message is received on a subscribed connection.

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

(Result Message int) -- ok carries the Message handle for a "message" push (heap-allocated; inspect with message-channel and message-payload), or 0 for non-message pushes (subscribe confirmations, etc.); err carries 0 on connection error.

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

Since: VK0

defn

message-channel

(message-channel [m : Message] :)

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 : Message] :)

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