R
R
riserise2019-09-22 03:32:17
go
riserise, 2019-09-22 03:32:17

How to make a permanent subscription to a channel in Redis in GO?

Hello everyone, actually a subject

package main

import (
    "fmt"
  "github.com/go-redis/redis"
)

func main() {

  client := redis.NewClient(&redis.Options{
    Addr: "localhost:6379",
    Password: "",
    DB: 0,
  })

        pubsub := client.Subscribe("test")
    	defer pubsub.Close()
    	msg, err := pubsub.ReceiveMessage()
    	if err != nil {
    		panic(err)
    	}
    	fmt.Println(msg.Channel, msg.Payload)
}

How to force this business to work constantly, instead of to come to the end after the first value placed in the channel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Papa, 2019-09-22
Stifflera @PapaStifflera

Use pubsub.Channel() and read from the channel in a loop. There is an example in the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question