Skip to content

Commit 94e503a

Browse files
authored
Merge pull request #215 from debasishg/fix-eval
Script evaluation fix
2 parents ec76dca + 44df75b commit 94e503a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ lazy val redisClient = (project in file(".")).settings(coreSettings : _*)
55
lazy val commonSettings: Seq[Setting[_]] = Seq(
66
organization := "net.debasishg",
77
version := "3.7",
8-
scalaVersion := "2.11.12",
8+
scalaVersion := "2.12.6",
99
crossScalaVersions := Seq("2.12.6", "2.11.12", "2.10.7", "2.13.0-M4"),
1010

1111
scalacOptions in Compile ++= Seq( "-unchecked", "-feature", "-language:postfixOps", "-deprecation" ),

src/main/scala/com/redis/EvalOperations.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ trait EvalOperations { self: Redis =>
66

77
// EVAL
88
// evaluates lua code on the server.
9-
def evalMultiBulk[A](luaCode: String, keys: List[Any], args: List[Any])(implicit format: Format, parse: Parse[A]): Option[List[Option[A]]] =
9+
def evalMultiBulk[A](luaCode: String, keys: List[Any], args: List[Any])(implicit format: Format, parse: Parse[A]): Option[List[Option[A]]] =
1010
send("EVAL", argsForEval(luaCode, keys, args))(asList[A])
1111

1212
def evalBulk[A](luaCode: String, keys: List[Any], args: List[Any])(implicit format: Format, parse: Parse[A]): Option[A] =
1313
send("EVAL", argsForEval(luaCode, keys, args))(asBulk)
1414

15+
def evalInt(luaCode: String, keys: List[Any], args: List[Any]): Option[Int] =
16+
send("EVAL", argsForEval(luaCode, keys, args))(asInt)
17+
1518
def evalMultiSHA[A](shahash: String, keys: List[Any], args: List[Any])(implicit format: Format, parse: Parse[A]): Option[List[Option[A]]] =
1619
send("EVALSHA", argsForEval(shahash, keys, args))(asList[A])
1720

src/test/scala/com/redis/EvalOperationsSpec.scala

+21
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,26 @@ class EvalOperationsSpec extends FunSpec
130130

131131
r.scriptExists(shahash.get) should equal (Some(0))
132132
}
133+
134+
it("should do stuff") {
135+
r.lpush("content", "{\"source\": \"output1.txt\", \"col1\": \"water_pressure\", \"col2\": \"sunday\", \"col3\": \"december\"}")
136+
r.lpush("content", "{\"source\": \"output1.txt\", \"col1\": \"air_pressure\", \"col2\": \"saturday\", \"col3\": \"november\"}")
137+
r.lpush("content", "{\"source\": \"output2.txt\", \"col1\": \"air_pressure\", \"col2\": \"saturday\", \"col3\": \"november\"}")
138+
139+
val luaCode = """
140+
if redis.call("EXISTS", KEYS[1]) == 1 then
141+
local res = {}
142+
local payload = redis.call("LRANGE", KEYS[1], 0, -1)
143+
local row = cjson.decode(payload[1])
144+
res[1] = row["source"]
145+
return #res
146+
else
147+
return -1
148+
end
149+
"""
150+
151+
val res = r.evalInt(luaCode, List("content"), List())
152+
res should equal (Some(1))
153+
}
133154
}
134155
}

0 commit comments

Comments
 (0)