Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass deserialization errors to promise #235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/scala/redis/Operation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import scala.concurrent.Promise
import redis.protocol.{DecodeResult, RedisReply}
import akka.util.ByteString

import scala.util.Try

case class Operation[RedisReplyT <: RedisReply, T](redisCommand: RedisCommand[RedisReplyT, T], promise: Promise[T]) {
def decodeRedisReplyThenComplete(bs: ByteString): DecodeResult[Unit] = {
val r = redisCommand.decodeRedisReply.apply(bs)
Expand All @@ -13,13 +15,13 @@ case class Operation[RedisReplyT <: RedisReply, T](redisCommand: RedisCommand[Re
}

def completeSuccess(redisReply: RedisReplyT): Promise[T] = {
val v = redisCommand.decodeReply(redisReply)
promise.success(v)
val v = Try(redisCommand.decodeReply(redisReply))
promise.complete(v)
}

def tryCompleteSuccess(redisReply: RedisReply) = {
val v = redisCommand.decodeReply(redisReply.asInstanceOf[RedisReplyT])
promise.trySuccess(v)
val v = Try(redisCommand.decodeReply(redisReply.asInstanceOf[RedisReplyT]))
promise.tryComplete(v)
}

def completeSuccessValue(value: T) = promise.success(value)
Expand Down
8 changes: 8 additions & 0 deletions src/test/scala/redis/commands/StringsSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.commands

import redis._

import scala.concurrent.{Await, Future}
import akka.util.ByteString
import redis.actors.ReplyErrorException
Expand Down Expand Up @@ -117,6 +118,13 @@ class StringsSpec extends RedisStandaloneServer {
Await.result(r, timeOut) mustEqual Some(dumbObject)
}

"GET with deserialization failure" in {
val r = redis.set("getDumbKey", "value").flatMap(_ => {
redis.get[Double]("getDumbKey")
})
Await.result(r, timeOut) must throwA[NumberFormatException]
}

"GETBIT" in {
val r = redis.getbit("getbitKeyNonexisting", 0)
val r2 = redis.set("getbitKey", "Hello").flatMap(_ => {
Expand Down