forked from acrosa/scala-redis
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added EvalApi support to Cluster classes
- Loading branch information
Michał Siatkowski
committed
Aug 26, 2019
1 parent
b12fd6c
commit fb912e2
Showing
9 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.redis.cluster | ||
|
||
import com.redis.api.EvalApi | ||
import com.redis.serialization.{Format, Parse} | ||
|
||
trait EvalOps extends EvalApi { | ||
self: RedisClusterOps => | ||
|
||
// todo: broken output | ||
override def evalMultiBulk[A](luaCode: String, keys: List[Any], args: List[Any]) | ||
(implicit format: Format, parse: Parse[A]): Option[List[Option[A]]] = | ||
processForKeys(keys)(gkeys => rc => rc.evalMultiBulk(luaCode, gkeys, args)) | ||
.flatten.headOption | ||
|
||
// todo: broken output | ||
override def evalBulk[A](luaCode: String, keys: List[Any], args: List[Any]) | ||
(implicit format: Format, parse: Parse[A]): Option[A] = | ||
processForKeys(keys)(gkeys => rc => rc.evalBulk(luaCode, gkeys, args)) | ||
.flatten.headOption | ||
|
||
// todo: broken output | ||
override def evalInt(luaCode: String, keys: List[Any], args: List[Any]): Option[Int] = | ||
processForKeys(keys)(gkeys => rc => rc.evalInt(luaCode, gkeys, args)) | ||
.flatten.headOption | ||
|
||
// todo: broken output | ||
override def evalMultiSHA[A](shahash: String, keys: List[Any], args: List[Any]) | ||
(implicit format: Format, parse: Parse[A]): Option[List[Option[A]]] = | ||
processForKeys(keys)(gkeys => rc => rc.evalMultiSHA(shahash, gkeys, args)) | ||
.flatten.headOption | ||
|
||
// todo: broken output | ||
override def evalSHA[A](shahash: String, keys: List[Any], args: List[Any]) | ||
(implicit format: Format, parse: Parse[A]): Option[A] = | ||
processForKeys(keys)(gkeys => rc => rc.evalSHA(shahash, gkeys, args)) | ||
.flatten.headOption | ||
|
||
// todo: broken output | ||
override def evalSHABulk[A](shahash: String, keys: List[Any], args: List[Any]) | ||
(implicit format: Format, parse: Parse[A]): Option[A] = | ||
processForKeys(keys)(gkeys => rc => rc.evalSHABulk(shahash, gkeys, args)) | ||
.flatten.headOption | ||
|
||
override def scriptLoad(luaCode: String): Option[String] = { | ||
val r = onAllConns(_.scriptLoad(luaCode)) | ||
oneCommonAnswerOr(r)(orError("ScriptLoad")).flatten | ||
} | ||
|
||
private val scriptExistsNot = Some(0) | ||
|
||
override def scriptExists(shahash: String): Option[Int] = { | ||
val r = onAllConns(_.scriptExists(shahash)) | ||
oneCommonAnswerOr(r)(_.find(_ == scriptExistsNot)).flatten | ||
} | ||
|
||
override def scriptFlush: Option[String] = { | ||
val r = onAllConns(_.scriptFlush) | ||
oneCommonAnswerOr(r)(orError("ScriptFlush")).flatten | ||
} | ||
|
||
private def orError[A](method: String)(r: Iterable[A]): Option[A] = | ||
throw new IllegalStateException(s"Various values returned while $method from various instances: ${r.mkString(",")}") | ||
|
||
protected def oneCommonAnswerOr[A](r: Iterable[A])(moreResultHandler: Iterable[A] => Option[A]): Option[A] = { | ||
val distinct = r.toSeq.distinct | ||
if (distinct.size > 1) { | ||
moreResultHandler(distinct) | ||
} else { | ||
r.headOption | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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