Comments (3)
This is currently the way to use subscriptions with gosexy/redis
:
rec := make(chan []string)
go func() {
select {
case ls = <-rec:
t.Logf("Got: %v\n", ls)
}
}()
go consumer.Subscribe(rec, "channel")
The problem I tried to solve was setting up the select before attempting to subscribe (subscribe is a blocking function) and that was the way that seemed right at the time. Obviously I'm no expert and I'm sure things could be better, what do you think of this? (untested).
var rec chan []string
var err error
if rec, err = consumer.SubscribeNonBlocking("channel"); err != nil {
t.Logf("Failed: %q", err)
}
go func() {
select {
case ls = <-rec:
t.Logf("Got: %v\n", ls)
}
}()
Do you have any suggestions?
from redis.
I just started learning Go and this question appeared, because I didn't see any point in passing this channel instead of returning new instance from subscribe function. But I'm very new to Go, so I don't know how things here should be done.
Best regards, Vyacheslav
On Mon, Jun 9, 2014 at 5:21 PM, Carlos Nieto [email protected]
wrote:
This is currently the way to use subscriptions with
gosexy/redis
:rec := make(chan []string) go func() { select { case ls = <-rec: t.Logf("Got: %v\n", ls) } }() go consumer.Subscribe(rec, "channel")The problem I tried to solve was setting up the select before attempting to subscribe (subscribe is a blocking function) and that was the way that seemed right at the time. Obviously I'm no expert and I'm sure things could be better, what do you think of this? (untested).
var rec chan []string var err error if rec, err = consumer.SubscribeNonBlocking("channel"); err != nil { t.Logf("Failed: %q", err) } go func() { select { case ls = <-rec: t.Logf("Got: %v\n", ls) } }()
Do you have any suggestions?
Reply to this email directly or view it on GitHub:
#28 (comment)
from redis.
@Termina1 Here is a simple use case : you might want to use that channel for multiple subscribers.
from redis.
Related Issues (20)
- Info command doesn't work HOT 2
- I got an error SIGSEGV: segmentation violation HOT 2
- Info command output should be parsed into a struct - enhancement request
- Support for Sentinel commands
- Installation failed on FreeBSD 10 HOT 1
- Using Scan: "Unsupported conversion: redis array to string" HOT 2
- SetEx bug:resp: Unsupported conversion: status to int HOT 1
- Is there a namespace
- gofmt check error
- resp: Unsupported conversion: error to int64
- Bug: ConfigGet should return ([]string, error) instead of (string, error) HOT 1
- GET return unorder bytes HOT 2
- LRANGE fails on size 999 HOT 1
- how to HOT 1
- Problem handling multiple request: Received a nil response.
- Getting "write: broken pipe" in logs. Possible reasons?
- Dbsize return: Unsupported conversion: integer to uint64
- All methods between Multi() and Exec() return panic
- Website down, not working. Can't do go get
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redis.