Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.
/ play-rediscala Public archive

Play plugin for Rediscala - Non-blocking, Reactive Redis driver for Scala

License

Notifications You must be signed in to change notification settings

skylve/play-rediscala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redisccala Plugin for Play! Framework Build Status Coverage Status

This is plugin is designed for Play 2.3.

Use Rediscala (1.3.1) - A Redis client for Scala (2.10+) and (AKKA 2.2+) with non-blocking and asynchronous I/O operations.

Set up the project dependencies

Edit your build.sbt or Build.scala and add the following :

"net.skylve" %% "play-rediscala" % "0.1"

And register the plugin in conf/play.plugins

200:play.modules.redis.RedisPlugin

Configuration

Simple

redis {
  default: "localhost"
}

Will connect the default db to the localhost redis instance with the default port (6379)

Config formats

You can write server informations in different formats.

With every informations :

default {
  host: "localhost"
  port: 6379
  password: "fuu"
  db: 1
}

Or you can also use an URI and mix with previous config parameters :

default {
  uri: "localhost:6379"
  password: "fuu"
  db: 1
}

URI accept those formats : redis://password@host:port | password@host:port | host:port | host (will use default port (6379))

Multi DB

Rediscala Plugin can handle multiple databases connections like so :

redis {
  default: "localhost"

  cache {
    host: "redis.cache"
    port: 6379
    password: "fuu"
  }
}

Client type

Rediscala offer different client types :

If you want to configure a db to use a specific client type you can add type parameter as so :

redis {
  default: "localhost"   # will use the default type "RedisClient"

  pool {
    type: "RedisClientPool"
    servers: ["redis.one", "redis.two"]  # work with server object too
    password: "123" # will be used if a server does not specify one
  }

  ms {
    type: "RedisClientMasterSlaves"
    
    master: {
      host: "localhost"   # could be an URI too
      password: "fuu"
    }

    slaves: ["redis.slave.one", "redis.slave.two"]

    password: "123" # will be used if the master or a slave configuraton does not specify one
  }

  monitored {
    type: "SentinelMonitoredRedisClient"
    
    # only uri accepted due to current limitation with format (host:port) and auth
    master: "localhost:3000"
    sentinels: ["sentinels.redis.one:6379", "sentinels.redis.two:6379"]
  }
}

How to use

If you only need to acces method in trait RedisCommands, you can simply :

import play.api.Play.current

val client = RedisPlugin() // select the default db
client.ping()

or if you need specific client type (e.g RedisClient, RedisClientPool, RedisClientMasterSlaves, SentinelMonitoredRedisClient), do as so :

import play.api.Play.current

val simpleClient = RedisPlugin.client("db_name")
val poolClient = RedisPlugin.pool("db_name")
val masterSlavesClient = RedisPlugin.mSlaves("db_name")
val monitoredClient = RedisPlugin.monitored("db_name")

If you do not specify a db name, default will be used.

About

Play plugin for Rediscala - Non-blocking, Reactive Redis driver for Scala

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages