Coder Social home page Coder Social logo

play-lettuce's Introduction

play-lettuce

Build Status

A Redis cache plugin for Play 2.8+, based on lettuce (https://lettuce.io/).

It does support Scala (2.13 and 2.12) and Java AsyncCacheApi and SyncCacheApi.

It supports SSL, and therefore is suitable for use with Azure Redis Cache.

Usage

Add dependency to sbt (along with the resolver to BinTray):

libraryDependencies += "com.github.mebur" %% "play-lettuce" % "1.1.0"

resolvers ++= Seq(
  "mebur-bintray" at "https://dl.bintray.com/mebur/maven"
)

Enable the module:

# Enable redis cache plugin
play.modules.enabled += "com.github.mebur.playlettuce.LettuceModule"

Then (optionally) enable Kryo serialization, by adding:

libraryDependencies += "com.twitter" %% "chill-akka" % "0.9.3"
libraryDependencies += "com.twitter" % "chill-java" % "0.9.3"

And then adding in you configuration something like this:

akka {
  actor {
    kryo {
      idstrategy = default
      resolve-subclasses = true
    }
    serializers {
      java = "akka.serialization.JavaSerializer"
      kryo = "com.twitter.chill.akka.AkkaSerializer"
    }

    serialization-bindings {
      "scala.Product" = kryo
      "scala.None" = kryo
      "scala.Some" = kryo
      "scala.collection.Seq" = kryo
      "scala.collection.Map" = kryo
      "my.custom.Class" = kryo
      "java.io.Serializable" = kryo
    }
  }
}

Configuration

After doing all of the above, one must set the redis endpoint for each cache by specifying lettuce.$cachename.url:

play.cache {
  defaultCache = "default"
  bindCaches = []
}

lettuce.default.url = "redis://localhost/0"

If you need additional caches, put them into bindCaches and then create the corresponding lettuce.$cacheName.url config key.

Never specify the exact same URL for two caches: please use different databases to separate them

Correct example:

play.cache {
  defaultCache = "default"
  bindCaches = ["users"]
}

lettuce.default.url = "redis://localhost/0"
lettuce.users.url = "redis://localhost/1"

Wrong example (the two caches might have key conflicts, and will throw an error upon start):

play.cache {
  defaultCache = "default"
  bindCaches = ["users"]
}

lettuce.default.url = "redis://localhost/0"
lettuce.users.url = "redis://localhost/0"  # Same URL, everything explodes in a ball of fire.

Optionally, for each cache, a timeout can be set for syncronous wrappers:

lettuce.default.syncTimeout = 3s

History

v1.1.0

  • Play 2.8 version

v1.0.0

  • Added multiset/multiget support in custom interface (dominics)
  • No configuration silently exports no bindings (dominics)
  • Better support for multiple caches without using KEYS command but mandating separated databases for different caches

v0.2.3

  • Timeout for sync wrappers is configurable

v0.2.2

  • More robust serialization

v0.2.1

  • Cross building scala 2.13 & 2.12

v0.2.0

  • Added support for Scala sync API
  • Added support for Java API (sync & async)

v0.1

  • Initial version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.