Skip to content

Commit

Permalink
Merge pull request #145 from bmironenko/master
Browse files Browse the repository at this point in the history
Fixes issue #144.
  • Loading branch information
debasishg committed Sep 10, 2015
2 parents b8c4025 + 7a0e295 commit 2ed503e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/scala/com/redis/HashOperations.scala
Expand Up @@ -5,16 +5,16 @@ import serialization._
trait HashOperations { self: Redis =>
def hset(key: Any, field: Any, value: Any)(implicit format: Format): Boolean =
send("HSET", List(key, field, value))(asBoolean)

def hsetnx(key: Any, field: Any, value: Any)(implicit format: Format): Boolean =
send("HSETNX", List(key, field, value))(asBoolean)

def hget[A](key: Any, field: Any)(implicit format: Format, parse: Parse[A]): Option[A] =
send("HGET", List(key, field))(asBulk)

def hmset(key: Any, map: Iterable[Product2[Any,Any]])(implicit format: Format): Boolean =
send("HMSET", key :: flattenPairs(map))(asBoolean)

def hmget[K,V](key: Any, fields: K*)(implicit format: Format, parseV: Parse[V]): Option[Map[K,V]] =
send("HMGET", key :: fields.toList){
asList.map { values =>
Expand All @@ -24,28 +24,28 @@ trait HashOperations { self: Redis =>
}.toMap
}
}

def hincrby(key: Any, field: Any, value: Int)(implicit format: Format): Option[Long] =
send("HINCRBY", List(key, field, value))(asLong)

def hincrbyfloat(key: Any, field: Any, value: Float)(implicit format: Format): Option[Float] =
send("HINCRBYFLOAT", List(key, field, value))(asBulk).map(_.toFloat)
send("HINCRBYFLOAT", List(key, field, value))(asBulk.map(_.toFloat))

def hexists(key: Any, field: Any)(implicit format: Format): Boolean =
send("HEXISTS", List(key, field))(asBoolean)

def hdel(key: Any, field: Any, fields: Any*)(implicit format: Format): Option[Long] =
send("HDEL", List(key, field) ::: fields.toList)(asLong)

def hlen(key: Any)(implicit format: Format): Option[Long] =
send("HLEN", List(key))(asLong)

def hkeys[A](key: Any)(implicit format: Format, parse: Parse[A]): Option[List[A]] =
send("HKEYS", List(key))(asList.map(_.flatten))

def hvals[A](key: Any)(implicit format: Format, parse: Parse[A]): Option[List[A]] =
send("HVALS", List(key))(asList.map(_.flatten))

def hgetall[K,V](key: Any)(implicit format: Format, parseK: Parse[K], parseV: Parse[V]): Option[Map[K,V]] =
send("HGETALL", List(key))(asListPairs[K,V].map(_.flatten.toMap))

Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/com/redis/PipelineSpec.scala
Expand Up @@ -143,4 +143,14 @@ class PipelineSpec extends FunSpec
res.get should equal(List(Some(1)))
}
}

describe("hincrbyfloat inside a pipeline") {
it("should succeed with a correct response") {
val float = 1.45.toFloat
val res = r.pipeline { p =>
p.hincrbyfloat("hincrbyfloat", "key", float)
}
res.get should equal(List(Some(float)))
}
}
}

0 comments on commit 2ed503e

Please sign in to comment.