nim-lang / redis

Official redis wrapper for Nim.
Other
128 stars 35 forks source link

Allow for subscribing to multiple channels #28

Closed ThomasTJdev closed 2 years ago

ThomasTJdev commented 2 years ago

Currently we can only subscribe to a single channel with the subscribe(). This PR allows the user to subscribe to multiple channels - just like https://redis.io/commands/subscribe.

import redis, asyncdispatch

var isSub: bool
var c: AsyncRedis

proc dd() {.async.} =

  while true:
    if not isSub:
      c = await openAsync()
      await c.subscribe(@["files", "users"])
      isSub = true

    let data = await c.nextMessage()
    echo $data

when isMainModule:
  asyncCheck dd()
  runForever()
$ redis-cli
#Received
publish files newFile
#Not received
publish ula bla
#Received
publish users John