Created
July 16, 2011 14:49
-
-
Save derekjw/1086413 to your computer and use it in GitHub Desktop.
TODO: More functional fyrie-redis multiexec syntax
This file contains hidden or 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
def multi[T](cmd: RedisClientMulti => Queued[T]): T | |
r.multi { q => | |
for { | |
_ <- q.put("mykey", "myval") | |
x <- q.get("myotherkey").parse[String] | |
y <- q.get("important").parse[Int] | |
} yield (x, y) // Queued[(Future[Option[String]], Future[Option[Int]])] | |
} // (Future[Option[String]], Future[Option[Int]]) | |
r.multi { q => | |
for { | |
_ <- q.put("myotherkey", "myotherval") | |
_ <- q.put("important", 7) | |
} yield () // Queued[Unit] | |
} // Unit | |
//Old test: | |
it("should handle invalid requests") { | |
val p1, p2 = Promise[List[Option[String]]]() | |
r.multi{ rq => | |
rq.set("testkey1", "testvalue1") | |
rq.set("testkey2", "testvalue2") | |
p1 <-: rq.mget(List[String]()).parse[String] | |
p2 <-: rq.mget(List("testkey1", "testkey2")).parse[String] | |
} | |
evaluating { p1.get } should produce[RedisErrorException] | |
p2.get should be(List(Some("testvalue1"), Some("testvalue2"))) | |
} | |
// NewTest: | |
it("should handle invalid requests") { | |
val result = r.multi{ rq => | |
for { | |
_ <- rq.set("testkey1", "testvalue1") | |
_ <- rq.set("testkey2", "testvalue2") | |
p1 <- rq.mget(List[String]()).parse[String] | |
p2 <- rq.mget(List("testkey1", "testkey2")).parse[String] | |
} yield (p1, p2) | |
} | |
evaluating { result._1.get } should produce[RedisErrorException] | |
result._2.get should be(List(Some("testvalue1"), Some("testvalue2"))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment