Git Product home page Git Product logo

play-redis's Introduction

Redis Module for Play Framework

This plugin allow you to integrate redis with your Play application. It consists of three parts:

1. A redis client used to persist data to a redis instance.
2. A redis implementation of Play’s cache interface. This allows you to use redis for your caching needs.
3. A redis cache monitor that helps you debug issues with your redis cache.

With this plugin, you can choose to use redis as a persistent data store or a caching system or both. Note that if you choose both, you’ll need separate redis instances. The cache is flushed at application shutdown.

Installation
To install the redis module, add this to your conf/dependencies.yml file:

require:
– play → redis

Using the Redis Client
Configuring the redis client is easy. Simply add this property to your conf/application.conf file:

redis.url=redis://username:password@host:port

Within your application code, the redis client is available via the play.modules.redis.Redis class. For example, you can set and get values with the following code:

Redis.set("key", "value");
Redis.get("key");

Note that this class abstracts away the client implementation. If for some reason, you wish to get the native client, that is possible as well:

RedisConnectionManager.getRawConnection().set("key", "value");

RedisConnectionManager.getRawConnection will return a Jedis client.

Using the Redis Client with Shared Instances
The plugin supports sharded instances. Within your conf/application.conf file, specify the connection urls to the various shards:

redis.1.url=redis://username:password@host:port
redis.2.url=redis://...

Now you may use the Redis client the same way as above. If you wish to get a native client, you can with the following:

RedisConnectionManager.getRawConnectionFromShard("key");

This will return a Jedis client to the shard containing the key argument.

Using Redis for Caching
Again, the configuration is easy. Add these properties to your conf/application.conf file:

redis.cache=enabled
redis.cache.url=redis://username:password@host:port

Now you can use the Cache interface like you normally would in your Play application:

Cache.set("key", "value", "30s");

Using the Redis Cache Monitor
This monitor helps debug your cache while your Play app is running. Simply add this to your routes file:

* /cache module:redis

Now you can drop the cacheMonitor tag in any of your views:

#{cacheMonitor /}

The cache monitor will report your cache contents as well as information about your cache redis instance.

Source Code
The source code is available on Github at https://github.com/tkral/play-redis

Change Log

v0.3:

  • Add caching support for model objects

play-redis's People

Contributors

tkral avatar jonhelgi avatar

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.