Skip to content

Instantly share code, notes, and snippets.

@blmarket
Last active August 29, 2015 14:06
Show Gist options
  • Save blmarket/4b9525402529a061be3f to your computer and use it in GitHub Desktop.
Save blmarket/4b9525402529a061be3f to your computer and use it in GitHub Desktop.
Scala implementation of redis subscribe
import com.redis.RedisClient
import rx.lang.scala._
import rx.lang.scala.schedulers._
object Main {
def main(args: Array[String]): Unit = {
val o = Observable.create(func)
o.subscribe(println(_))
o.toBlocking.last // block process to see it works.
}
def func(ob: Observer[String]): Subscription = {
val c = new RedisClient()
val worker: Worker = ComputationScheduler().createWorker
worker.schedule { // new thread
c.subscribe("test_channel")(x => {
ob.onNext(x.toString)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment