Created
March 8, 2019 10:47
-
-
Save genedna/a6c72fedc7b96b2401921ab808b917e4 to your computer and use it in GitHub Desktop.
go-redis pub sub example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/go-redis/redis" | |
) | |
var ( | |
RedisClient *redis.Client | |
) | |
func main() { | |
RedisClient = redis.NewClient(&redis.Options{ | |
Addr: Env.Redis.Host + ":" + Env.Redis.Port, | |
Password: Env.Redis.Password, | |
DB: Env.Redis.Db, | |
}) | |
// MULTIPLES REPETITION STRUCTURES INSIDE GO ROUTINES | |
go func(){ | |
psNewMessage := RedisClient.Subscribe("channel1") | |
for { | |
msg, _ := psNewMessage.ReceiveMessage() | |
go func() { | |
// DO SOMETHING WITH msg | |
}() | |
} | |
}() | |
go func(){ | |
psCallInPulse := RedisClient.Subscribe("channel2") | |
for { | |
msg, _ := psCallInPulse.ReceiveMessage() | |
go func() { | |
// DO SOMETHING WITH msg | |
}() | |
} | |
}() | |
// MORE 7 GO ROUTINES | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment