LoginSignup
1
1

More than 5 years have passed since last update.

Memcachedのshadeを使ってみる

Last updated at Posted at 2015-01-20

MemcachedをScalaで使うならこれがいいということで使ってみた。

詳しくはshadeを参照

SBTでresolverとDependencyを書いて

resolvers += "Spy" at "http://files.couchbase.com/maven2/"
dependencies += "com.bionicspirit" %% "shade" % "1.6.0"

あとはget, set, add, deleteを使用する

Non-blockingの場合

import concurrent.duration._
import concurrent.Future
import shade.memcached._
import scala.concurrent.ExecutionContext.Implicits.{global => ec}

val memcached = Memcached(Configuration("127.0.0.1:11211"), ec)
val op: Future[Boolean] = memcached.set("username", "Alex", 1.minute)

Blockingの場合

import concurrent.duration._
import concurrent.Future
import shade.memcached._
import scala.concurrent.ExecutionContext.Implicits.{global => ec}

val memcached = Memcached(Configuration("127.0.0.1:11211"), ec)

memcached.awaitGet("username") match {
    case Some(username) => doSomething
    case None =>
        memcached.awaitSet("username", "Alex", 1.minute)
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1