Use sedis as version cache
This commit is contained in:
parent
d0dc0a2ca2
commit
02ab64c0e8
|
@ -8,12 +8,14 @@ trait Resolvers {
|
|||
val iliaz = "iliaz.com" at "http://scala.iliaz.com/"
|
||||
val sonatype = "sonatype" at "http://oss.sonatype.org/content/repositories/releases"
|
||||
val novusS = "repo.novus snaps" at "http://repo.novus.com/snapshots/"
|
||||
val guice = "guice-maven" at "http://guice-maven.googlecode.com/svn/trunk"
|
||||
}
|
||||
|
||||
trait Dependencies {
|
||||
val scalaz = "org.scalaz" %% "scalaz-core" % "6.0.4"
|
||||
val specs2 = "org.specs2" %% "specs2" % "1.8.2"
|
||||
val redis = "net.debasishg" %% "redisclient" % "2.4.2"
|
||||
//val redis = "net.debasishg" %% "redisclient" % "2.4.2"
|
||||
val redis = "org.sedis" %% "sedis" % "1.0"
|
||||
val casbah = "com.mongodb.casbah" %% "casbah" % "2.1.5-1"
|
||||
val salat = "com.novus" %% "salat-core" % "0.0.8-SNAPSHOT"
|
||||
val slf4j = "org.slf4j" % "slf4j-nop" % "1.6.4"
|
||||
|
@ -33,7 +35,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
organization := "com.github.ornicar",
|
||||
version := "0.1",
|
||||
scalaVersion := "2.9.1",
|
||||
resolvers := Seq(iliaz, codahale, sonatype, novusS, typesafe),
|
||||
resolvers := Seq(iliaz, codahale, sonatype, novusS, typesafe, guice),
|
||||
libraryDependencies := Seq(scalalib),
|
||||
libraryDependencies in test := Seq(specs2),
|
||||
shellPrompt := {
|
||||
|
@ -43,7 +45,11 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
)
|
||||
|
||||
val lila = PlayProject("lila", mainLang = SCALA, settings = buildSettings).settings(
|
||||
libraryDependencies ++= Seq(scalaz, slf4j)
|
||||
libraryDependencies ++= Seq(scalaz),
|
||||
// Adds system code to continuous triggers
|
||||
watchSources <+= baseDirectory map { _ / "system/src/main/scala" },
|
||||
// Adds chess code to continuous triggers
|
||||
watchSources <+= baseDirectory map { _ / "chess/src/main/scala" }
|
||||
) dependsOn (system)
|
||||
|
||||
lazy val system = Project("system", file("system"), settings = buildSettings).settings(
|
||||
|
|
|
@ -2,9 +2,11 @@ package lila.system
|
|||
|
||||
import com.mongodb.casbah.MongoConnection
|
||||
import com.mongodb.casbah.commons.conversions.scala._
|
||||
import com.redis.RedisClient
|
||||
import com.typesafe.config._
|
||||
|
||||
import org.sedis._
|
||||
import redis.clients.jedis._
|
||||
|
||||
import ai._
|
||||
|
||||
trait SystemEnv {
|
||||
|
@ -28,9 +30,12 @@ trait SystemEnv {
|
|||
config getInt "mongo.port"
|
||||
)(config getString "mongo.dbName")
|
||||
|
||||
def redis = new RedisClient(
|
||||
def versionCache = new VersionCache(redis)
|
||||
|
||||
def redis = new Pool(new JedisPool(
|
||||
new JedisPoolConfig(),
|
||||
config getString "redis.host",
|
||||
config getInt "redis.port")
|
||||
config getInt "redis.port"))
|
||||
}
|
||||
|
||||
object SystemEnv extends EnvBuilder {
|
||||
|
|
15
system/src/main/scala/VersionCache.scala
Normal file
15
system/src/main/scala/VersionCache.scala
Normal file
|
@ -0,0 +1,15 @@
|
|||
package lila.system
|
||||
|
||||
import org.sedis._
|
||||
import redis.clients.jedis._
|
||||
import Dress._
|
||||
|
||||
final class VersionCache(pool: Pool) {
|
||||
|
||||
def get(gameId: String, color: Color): Option[Int] =
|
||||
pool.withClient { client ⇒
|
||||
client get key(gameId, color) flatMap parseIntOption
|
||||
}
|
||||
|
||||
def key(gameId: String, color: Color) = gameId + ":" + color.letter + ":v"
|
||||
}
|
Loading…
Reference in a new issue