MyBatis Redis integration - Reference Documentation

Redis is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

The Redis integration is built on top of the Jedis client, written by Jonathan Leibiusky.

Users that want to use Redis into their applications, have to download the zip bundle, decompress it and add the jars in the classpath; Apache Maven users instead can simply add in the pom.xml the following dependency:

<dependencies>
  ...
  <dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-redis</artifactId>
    <version>1.0.0-beta3-SNAPSHOT</version>
  </dependency>
  ...
</dependencies>

then, just configure it in the mapper XML

<mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.redis.RedisCache" />
  ...
</mapper>

The Redis cache is configurable by putting the /redis.properties classpath resource; if not found, the client will use the default setting.

Any property found in the configuration file will be set as a property to the bean JedisConfigPool. There is an additional parameter redis.host to set the Redis server host name; if not set "localhost" will be used.

All properties are prefixed with 'redis' to avoid issues with other property types such as host.

To set cache TTL, set the value in seconds to timeout property.

<cache type="org.mybatis.caches.redis.RedisCache">
  <property name="timeout" value="3" />
</cache>
@CacheNamespace(properties = { @Property(name = "timeout", value = "3") })