14. Integration with frameworks

Nikita Koksharov edited this page Sep 3, 2018 · 158 revisions

14.1. Spring Framework

Redisson is fully compatible with the Spring framework and has provided a way to configure a RedissonClient instance along with all of its supported objects and services using Spring XML namespace like you could with other Spring provided features.

First of all, you need to add Redisson schema to your Spring XML file like this:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:redisson="http://redisson.org/schema/redisson"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://redisson.org/schema/redisson
       http://redisson.org/schema/redisson/redisson.xsd
">
...
</beans>

And then, create a Redisson configuration using XML as described in configuration chapter. For instance, a single server instance can be configured like this:

<!-- minimal requirement -->
<redisson:client>
    <!-- defaults to 127.0.0.1:6379 -->
    <redisson:single-server/>
</redisson:client>
<!-- or -->
<redisson:client>
    <redisson:single-server address="${redisAddress}"/>
</redisson:client>

Other connection types are described in the configuration chapter alongside with all the available options.

You may have noticed in the above example: a property expression is used to inject the address value. This is supported naturally by Spring and all it is required to work is a <context:property-placeholder/> tag, and please don't forget to add the <context:annotation-config/> tag if you want to auto wire the Redisson instance into your own bean.

Usually for an application, one Redisson instance is sufficient enough for typical usage, however in a scenario where an application requires to connect to a few different Redis environments, more than one Redisson may be required to co-exist alongside of each other. You can achieve this by having more than one <redisson:client/> defined in an application:

<redisson:client id="myRedisson1" name="redisson1,redisson2" >
    <redisson:single-server address="127.0.0.1:6379" client-name="1"/>
</redisson:client>

<redisson:client id="myRedisson2" name="redisson3,redisson4">
    <redisson:single-server address="127.0.0.1:6380" client-name="2"/>
</redisson:client>

Each Redisson instance is distinguished by its id attribute and the value can also be use as a qualifier candidate. Comma separated values appeared in the name attribute are parsed as bean aliases, these names can also be used as qualifier candidates available for auto wiring.

A qualifier tag can be use to explicitly specify a qualifier candidate name, however it cannot co-exist with the name attribute.

<redisson:client>
    <qualifier value="qualifiedName"/>
    <redisson:single-server address="127.0.0.1:6379"/>
</redisson:client>

In addition to the Redisson instance itself, other Redisson supplied objects may be created in a similar manner as well. They can be declared within the <Redisson:client/> as child element or they can be declared as a root bean when supplied with a Redisson bean reference.

Elements representing Redisson objects followed the Spring naming conventions and carried the same namespace as the Redisson instance:

<redisson:client id="myRedisson">
    <redisson:single-server address="127.0.0.1:6379"/>
    <redisson:map id="map" key="map"/>
</redisson:client>
<!-- or -->
<redisson:map id="map1" key="map" redisson-ref="myRedisson"/>

As one would expect, Redisson service objects can be obtained in the same way:

<redisson:client id="myRedisson">
    <redisson:single-server address="127.0.0.1:6379"/>
    <redisson:executor-service
        id="executorService"
        service="executorServiceName"/>
</redisson:client>
<!-- or -->
<redisson:executor-service
    id="executorService"
    service="executorServiceName"
    redisson-ref="myRedisson"/>

With Redisson Remote Service and Live Object Service, It is also possible to perform service registration and service object obtaining declaratively via the Redisson Spring XML namespace.

<redisson:remote-service
    id="remoteService"
    service="remoteServiceName"
    redisson-ref="myRedisson">
    <!-- Service registration -->
    <redisson:rpc-server
        api-class="com.example.MyTestService"
        bean="myTestServiceBean"/>
    <!-- Obtain a (proxied) service instance -->
    <redisson:rpc-client
        id="client"
        api-class="com.example.MyTestService">
        <redisson:remote-invocation-options>
            <redisson:remote-ack within="1" time-unit="SECONDS"/>
            <redisson:remote-result within="1" time-unit="SECONDS"/>
        </redisson:remote-invocation-options>
    </redisson:rpc-client>
</redisson:remote-service>
<!-- my service bean -->
<bean id="myTestServiceBean" class="com.example.MyTestServiceImpl"/>

<redisson:live-object-service
    id="live-object-service-ext"
    redisson-ref="myRedisson">
    <!-- Class registration -->
    <redisson:live-object-registration  class="com.example.MyTestEntity"/>
    <!-- Proxied instance obtaining -->
    <redisson:live-object
        id="liveObject"
        object-id="testLiveObjectId"
        class="com.example.MyTestEntity"/>
</redisson:live-object-service>

Obviously when the Redisson services are defined within a <redisson:client/> element, the redisson-ref attribute can be omitted.

Below is a list of usage examples for all the supported objects and services:

<redisson:client>
    <redisson:single-server address="127.0.0.1:6379"/>
    <redisson:binary-stream id="binary-stream" key="binary-stream"/>
    <redisson:geo id="geo" key="geo"/>
    <redisson:set-cache id="set-cache" key="set-cache"/>
    <redisson:map-cache id="map-cache" key="map-cache"/>
    <redisson:bucket id="bucket" key="bucket"/>
    <redisson:buckets id="buckets"/>
    <redisson:hyper-log-log id="hyper-log-log" key="hyper-log-log"/>
    <redisson:list id="list" key="list"/>
    <redisson:list-multimap id="list-multimap" key="list-multimap"/>
    <redisson:list-multimap-cache id="list-multimap-cache" key="list-multimap-cache"/>
    <redisson:local-cached-map id="local-cached-map" key="local-cached-map">
        <redisson:local-cached-map-options id="local-options" eviction-policy="LRU" time-to-live="1" time-to-live-unit="SECONDS"/>
    </redisson:local-cached-map>
    <redisson:map id="map" key="map"/>
    <redisson:set-multimap id="set-multimap" key="set-multimap"/>
    <redisson:set-multimap-cache id="set-multimap-cache" key="set-multimap-cache"/>
    <redisson:semaphore id="semaphore" key="semaphore"/>
    <redisson:permit-expirable-semaphore id="permit-expirable-semaphore" key="permit-expirable-semaphore"/>
    <redisson:lock id="lock" key="lock"/>
    <redisson:fair-lock id="fair-lock" key="fair-lock"/>
    <redisson:read-write-lock id="read-write-lock" key="read-write-lock">
        <redisson:read-lock id="read-lock"/>
        <redisson:write-lock id="write-lock"/>
    </redisson:read-write-lock>
    <redisson:multi-lock id="multi-lock">
        <ref bean="lock"/>
        <redisson:lock id="lock-1" key="lock-1"/>
        <redisson:fair-lock id="fair-lock-1" key="fair-lock-1"/>
        <redisson:write-lock id="write-lock-1" read-write-lock-ref="read-write-lock"/>
        <redisson:read-lock id="read-lock-1" read-write-lock-ref="read-write-lock"/>
    </redisson:multi-lock>
    <redisson:red-lock id="red-lock">
        <ref bean="lock"/>
        <redisson:lock id="lock-2" key="lock-2"/>
        <redisson:fair-lock id="fair-lock-2" key="fair-lock-2"/>
        <redisson:write-lock id="write-lock-2" read-write-lock-ref="read-write-lock"/>
        <redisson:read-lock id="read-lock-2" read-write-lock-ref="read-write-lock"/>
    </redisson:red-lock>
    <redisson:set id="set" key="set"/>
    <redisson:sorted-set id="sorted-set" key="sorted-set"/>
    <redisson:scored-sorted-set id="scored-sorted-set" key="scored-sorted-set"/>
    <redisson:lex-sorted-set id="lex-sorted-set" key="lex-sorted-set"/>
    <redisson:topic id="topic" topic="topic"/>
    <redisson:pattern-topic id="pattern-topic" pattern="pattern-topic"/>
    <redisson:blocking-fair-queue id="blocking-fair-queue" key="blocking-fair-queue"/>
    <redisson:queue id="queue" key="queue"/>
    <redisson:delayed-queue id="delayed-queue" destination-queue-ref="queue"/>
    <redisson:priority-queue id="priority-queue" key="priority-queue"/>
    <redisson:priority-deque id="priority-deque" key="priority-deque"/>
    <redisson:blocking-queue id="blocking-queue" key="blocking-queue"/>
    <redisson:bounded-blocking-queue id="bounded-blocking-queue" key="bounded-blocking-queue"/>
    <redisson:deque id="deque" key="deque"/>
    <redisson:blocking-deque id="blocking-deque" key="blocking-deque"/>
    <redisson:atomic-long id="atomic-long" key="atomic-long"/>
    <redisson:atomic-double id="atomic-double" key="atomic-double"/>
    <redisson:count-down-latch id="count-down-latch" key="count-down-latch"/>
    <redisson:bit-set id="bit-set" key="bit-set"/>
    <redisson:bloom-filter id="bloom-filter" key="bloom-filter"/>
    <redisson:script id="script"/>
    <redisson:executor-service id="executor-service" service="executor-service"/>
    <redisson:remote-service id="remote-service" service="remote-service">
        <redisson:rpc-server api-class="com.example.MyTestService" bean="myServiceBean"/>
        <redisson:rpc-client id="rpc-client" api-class="com.example.MyTestService">
            <redisson:remote-invocation-options id="options">
                <!--one of two--> 
                <!--<redisson:remote-no-ack/>-->
                <redisson:remote-ack within="1" time-unit="SECONDS"/>
                <!--one of two-->                     
                <!--<redisson:remote-no-result/>-->
                <redisson:remote-result within="1" time-unit="SECONDS"/>
            </redisson:remote-invocation-options>
        </redisson:rpc-client>
    </redisson:remote-service>
    <redisson:keys id="keys"/>
    <redisson:live-object-service id="live-object-service">
        <redisson:live-object-registration  class="com.example.MyEntity" />
        <redisson:live-object id="live-object" object-id="live-object" class="com.example.MyEntity" />
    </redisson:live-object-service>
</redisson:client>

Spring's qualifier element is allowed as a nested child element for each of the type mentioned above.

A RedisClient may too be obtained in the same way if the access to low level Redis client is required:

<!-- Minimal requirement for redis client-->
<!-- Use default host 127.0.0.1 and port 6379 -->
<redisson:redis/>
<!-- or -->
<redisson:redis
    host="127.0.0.1"
    port="6379"
    connection-timeout="10000"
    command-timeout="10000"/>

14.2. Spring Cache

Redisson provides Redis based Spring Cache implementation made according to Spring Cache specification. Each Cache instance has two important parameters: ttl and maxIdleTime and stores data infinitely if they are not defined or equal to 0.

Config example:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson() throws IOException {
            Config config = new Config();
            config.useClusterServers()
                  .addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001");
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) {
            Map<String, CacheConfig> config = new HashMap<String, CacheConfig>();

            // create "testMap" cache with ttl = 24 minutes and maxIdleTime = 12 minutes
            config.put("testMap", new CacheConfig(24*60*1000, 12*60*1000));
            return new RedissonSpringCacheManager(redissonClient, config);
        }

    }

Cache configuration could be read from JSON or YAML configuration files:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson(@Value("classpath:/redisson.json") Resource configFile) throws IOException {
            Config config = Config.fromJSON(configFile.getInputStream());
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
            return new RedissonSpringCacheManager(redissonClient, "classpath:/cache-config.json");
        }

    }

14.2.1 Spring Cache. Local cache and data partitioning

Redisson provides various Spring Cache managers with two important features:

local cache - so called near cache, which is useful for use cases when Spring Cache used mostly for read operations and/or network roundtrips are undesirable. It caches Map entries on Redisson side and executes read operations up to 45x faster in comparison with usual implementation.

data partitioning - data partitioning in cluster mode. It allows to scale available memory, read/write operations and entry eviction process for individual Spring Cache instance in Redis cluster.

Below is the list of all available managers with local cache and/or data partitioning support:

Class name Local cache
support
Data partitioning
support
RedissonSpringCacheManager
 
No No
RedissonSpringLocalCachedCacheManager
available only in Redisson PRO edition
Yes No
RedissonClusteredSpringCacheManager
available only in Redisson PRO edition
No Yes
RedissonClusteredSpringLocalCachedCacheManager
available only in Redisson PRO edition
Yes Yes

Follow options object should be supplied during org.redisson.spring.cache.RedissonSpringLocalCachedCacheManager or org.redisson.spring.cache.RedissonSpringClusteredLocalCachedCacheManager initialization:

      LocalCachedMapOptions options = LocalCachedMapOptions.defaults()
      // LFU, LRU, SOFT, WEAK and NONE eviction policies are available
     .evictionPolicy(EvictionPolicy.NONE)
      // If cache size is 0 then local cache is unbounded.
     .cacheSize(1000)
      // Follow reconnection strategies are available:
      // CLEAR - Clear local cache if map instance has been disconnected for a while.
      // LOAD - Store invalidated entry hash in invalidation log for 10 minutes
      //        Cache keys for stored invalidated entry hashes will be removed 
      //        if LocalCachedMap instance has been disconnected less than 10 minutes
      //        or whole cache will be cleaned otherwise.
      // NONE - Default. No synchronizations on map changes
     .reconnectionStrategy(ReconnectionStrategy.NONE)
      // Follow sync strategies are available:
      // INVALIDATE - Default. Invalidate cache entry across all LocalCachedMap instances on map entry change
      // UPDATE - Update cache entry across all LocalCachedMap instances on map entry change
      // NONE - No synchronizations on map changes
     .syncStrategy(SyncStrategy.INVALIDATE)
      // time to live for each map entry in local cache
     .timeToLive(10000)
      // or
     .timeToLive(10, TimeUnit.SECONDS)
      // max idle time for each map entry in local cache
     .maxIdle(10000)
      // or
     .maxIdle(10, TimeUnit.SECONDS);

Each Spring Cache instance has two important parameters: ttl and maxIdleTime and stores data infinitely if they are not defined or equal to 0.

Complete config example:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson() throws IOException {
            Config config = new Config();
            config.useClusterServers()
                  .addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001");
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) {
            Map<String, CacheConfig> config = new HashMap<String, CacheConfig>();

            // create "testMap" cache with ttl = 24 minutes and maxIdleTime = 12 minutes
            LocalCachedMapOptions options = LocalCachedMapOptions.defaults()
                   .evictionPolicy(EvictionPolicy.LFU)
                   .cacheSize(1000);
            config.put("testMap", new LocalCachedCacheConfig(24*60*1000, 12*60*1000, options));
            return new RedissonSpringLocalCachedCacheManager(redissonClient, config);
        }

    }

Cache configuration could be read from JSON or YAML configuration files:

    @Configuration
    @ComponentScan
    @EnableCaching
    public static class Application {

        @Bean(destroyMethod="shutdown")
        RedissonClient redisson(@Value("classpath:/redisson.yaml") Resource configFile) throws IOException {
            Config config = Config.fromYAML(configFile.getInputStream());
            return Redisson.create(config);
        }

        @Bean
        CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
            return new RedissonSpringLocalCachedCacheManager(redissonClient, "classpath:/cache-config.yaml");
        }

    }

14.2.2 Spring Cache. JSON and YAML config format

JSON:

{
  "testMap": {
    "ttl": 1440000,
    "maxIdleTime": 720000,
    "localCacheOptions": {
      "invalidationPolicy": "ON_CHANGE",
      "evictionPolicy": "NONE",
      "cacheSize": 0,
      "timeToLiveInMillis": 0,
      "maxIdleInMillis": 0
    }
  }
}

YAML:

---
testMap:
  ttl: 1440000
  maxIdleTime: 720000
  localCacheOptions:
    invalidationPolicy: "ON_CHANGE"
    evictionPolicy: "NONE"
    cacheSize: 0
    timeToLiveInMillis: 0
    maxIdleInMillis: 0

Above are settings for Spring Cache with name testMap.

Please note: localCacheOptions settings are available for org.redisson.spring.cache.RedissonSpringLocalCachedCacheManager or org.redisson.spring.cache.RedissonSpringClusteredLocalCachedCacheManager classes only.

14.3. Hibernate Cache

Hibernate Cache implementation maintained by hibernate-redis project.

Please read Setup instruction before start.

14.3.1. Hibernate Cache. Local cache and data partitioning

Redisson provides various Hibernate Cache factories with two important features:

local cache - so called near cache, which is useful for use cases when Hibernate Cache used mostly for read operations and/or network roundtrips are undesirable. It caches Map entries on Redisson side and executes read operations up to 5x faster in comparison with usual implementation.

data partitioning - data partitioning in cluster mode. It allows to scale available memory, read/write operations and entry eviction process for individual Hibernate Cache instance in Redis cluster.

Below is the list of all available factories with local cache and/or data partitioning support:

Class name Local cache
support
Data partitioning
support
SingletonRedisRegionFactory
 
No No
LocalCachedRedisRegionFactory
available only in Redisson PRO edition
Yes No
ClusteredRedisRegionFactory
available only in Redisson PRO edition
No Yes
ClusteredLocalCachedRedisRegionFactory
available only in Redisson PRO edition
Yes Yes

Configuration example:

// Secondary Cache
props.put(Environment.USE_SECOND_LEVEL_CACHE, true);
props.put(Environment.USE_QUERY_CACHE, true);
props.put(Environment.CACHE_REGION_FACTORY, org.redisson.hibernate.v52.LocalCachedRedisRegionFactory.class.getName());
props.put(Environment.CACHE_REGION_PREFIX, "hibernate");

// Configuration for Redis that used by hibernate
props.put(Environment.CACHE_PROVIDER_CONFIG, "hibernate-redis.properties");

hibernate-redis.properties file example:

hibernate-redis.properties file
# redisson configuraiton file path
redisson-config=conf/redisson.yaml

# default expiration time for non-listed region names
redis.expiryInSeconds.default=120

# default local cache settings for non-listed region names

# if value is `ON_CHANGE`, `ON_CHANGE_WITH_CLEAR_ON_RECONNECT` or `ON_CHANGE_WITH_LOAD_ON_RECONNECT` 
# corresponding map entry is removed from cache across all Hibernate Local Cache instances 
# during every invalidation message sent on each map entry update/remove operation
redis.localCache.invalidationPolicy.default=ON_CHANGE_WITH_CLEAR_ON_RECONNECT

# if cache size is 0 then local cache is unbounded
redis.localCache.cacheSize.default=10000

# LFU, LRU, SOFT, WEAK and NONE policies are available
redis.localCache.evictionPolicy.default=LFU

# time to live for each map entry in local cache
redis.localCache.timeToLiveInMillis.default=1000000

# max idle time for each map entry in local cache
redis.localCache.maxIdleInMillis.default=1000000

# expiration time for 'player' region name
redis.expiryInSeconds.hibernate.player=900

# local cache settings for 'player' region name
redis.localCache.invalidationPolicy.hibernate.player=ON_CHANGE_WITH_CLEAR_ON_RECONNECT
redis.localCache.cacheSize.hibernate.player=10000
redis.localCache.evictionPolicy.hibernate.player=LFU
redis.localCache.timeToLiveInMillis.hibernate.player=1000000
redis.localCache.maxIdleInMillis.hibernate.player=1000000

Please note: redis.localCache.* settings are available for ClusteredLocalCachedRedisRegionFactory or LocalCachedRedisRegionFactory classes only.

14.4 JCache API (JSR-107) implementation

Redisson provides an implementation of JCache API (JSR-107) for Redis.

Here is an example of JCache API usage. Using default config located at /redisson-jcache.json or /redisson-jcache.yaml:

MutableConfiguration<String, String> config = new MutableConfiguration<>();
        
CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", config);

Using config file with custom location:

MutableConfiguration<String, String> config = new MutableConfiguration<>();

// json config
URI redissonConfigUri = getClass().getResource("redisson-jcache.json").toURI();
// or yaml config
URI redissonConfigUri = getClass().getResource("redisson-jcache.yaml").toURI();
CacheManager manager = Caching.getCachingProvider().getCacheManager(redissonConfigUri, null);
Cache<String, String> cache = manager.createCache("namedCache", config);

Using Redisson's config object:

MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<>();

Config redissonCfg = ...
Configuration<String, String> config = RedissonConfiguration.fromConfig(redissonCfg, jcacheConfig);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", config);

Using Redisson instance object:

MutableConfiguration<String, String> jcacheConfig = new MutableConfiguration<>();

RedissonClient redisson = ...
Configuration<String, String> config = RedissonConfiguration.fromInstance(redisson, jcacheConfig);

CacheManager manager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = manager.createCache("namedCache", config);

Read more here about Redisson configuration.

Provided implementation fully passes TCK tests. Here is the test module.

14.5 Tomcat Redis Session Manager

Please find more information regarding this chapter here.

14.6 Spring Session

Redisson provides Spring Session store implementation. Each session attribute is written into Redis during each HttpSession.setAttribute invocation.

Usage:

  1. Ensure you have Spring Session library in your classpath, add it if necessary:

    Maven

    <!-- for Redisson 2.x -->
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session</artifactId>
        <version>1.3.3.RELEASE</version>
    </dependency>
    
    <!-- for Redisson 3.x -->
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session-core</artifactId>
        <version>2.0.3.RELEASE</version>
    </dependency>

    Gradle

    // for Redisson 2.x
    compile 'org.springframework.session:spring-session:1.3.3.RELEASE'  
    
    // for Redisson 3.x
    compile 'org.springframework.session:spring-session-core:2.0.3.RELEASE'  
  2. Add @EnableRedissonHttpSession annotation and Redisson bean to Spring configuration:

    @EnableRedissonHttpSession 
    public class Config {
    
       @Bean
       public RedissonClient redisson() {
           return Redisson.create();
       }
    }
  3. Add application initializer which extends AbstractHttpSessionApplicationInitializer class:

    public class Initializer extends AbstractHttpSessionApplicationInitializer { 
    
         public Initializer() {
                 super(Config.class); 
         }
    }

14.7. Spring Transaction Manager

Redisson provides implementation of org.springframework.transaction.PlatformTransactionManager interface to participant in Spring transactions. See also Transactions section.

Code example:

@Configuration
@EnableTransactionManagement
public class RedissonTransactionContextConfig {
    
    @Bean
    public TransactionalBean transactionBean() {
        return new TransactionalBean();
    }
    
    @Bean
    public RedissonTransactionManager transactionManager(RedissonClient redisson) {
        return new RedissonTransactionManager(redisson);
    }
    
    @Bean
    public RedissonClient redisson() {
        return BaseTest.createInstance();
    }
    
    @PreDestroy
    public void destroy() {
        redisson().shutdown();
    }
}



public class TransactionalBean {

    @Autowired
    private RedissonTransactionManager transactionManager;

    @Transactional
    public void commitData() {
        RTransaction transaction = transactionManager.getCurrentTransaction();
        RMap<String, String> map = transaction.getMap("test1");
        map.put("1", "2");
    }

}

14.8. Spring Data Redis

Please find information regarding this chapter here.

14.9. Spring Boot Starter

Please find information regarding this chapter here.

14.10. JMX and Dropwizard Metrics

It's easy to retrieve Redisson metrics gathered with Dropwizard Metrics library.

This feature available only in Redisson PRO edition.

The following metrics are available.

Config

Config config = ... // redisson config object
config.enableMetrics()
      .setRegistryName("myMetrics")
      // enable JMX
      .setJmxEnabled()
      // JMX domain name
      .setJmxDomain("myDomain");

...

// get Redisson metrics registry by name specified during configuration
MetricRegistry registry = SharedMetricRegistries.getOrCreate("myMetrics");

JSON config is appended to Redisson config:

 "enableMetrics":{"jmxEnabled":false, "jmxDomain":"myDomain", "registryName": "myRegistry"}

YAML config is appended to Redisson config:

 enableMetrics:
  jmxEnabled: false
  jmxDomain: "myDomain"
  registryName: "myRegistry"

Configuration metrics

  • redisson.executor-pool-size - A Gauge of the number of executor threads pool size
  • redisson.netty-pool-size - A Gauge of the number of netty threads pool size

Metrics per Redis node.

Base name: redisson.redis.<host>:<port>

  • status - A Gauge of the string value [connected, disconnected]
  • type - A Gauge of the Redis node type [MASTER, SLAVE]

  • total-response-bytes - A Meter of the total amount of bytes received from Redis
  • response-bytes - A Histogram of the number of bytes received from Redis
  • total-request-bytes - A Meter of the total amount of bytes sent to Redis
  • request-bytes - A Histogram of the number of bytes sent to Redis

  • connections.active - A Counter of the number of busy connections
  • connections.free - A Counter of the number of free connections
  • connections.max-pool-size - A Counter of the number of maximum connection pool size
  • connections.reconnected - A Counter of the number of reconnected connections
  • connections.total - A Counter of the number of total connections in pool

  • operations.total - A Meter of the number of total executed operations
  • operations.total-failed - A Meter of the number of total failed operations
  • operations.total-successful - A Meter of the number of total successful operations

  • publish-subscribe-connections.active - A Counter of the number of active publish subscribe connections
  • publish-subscribe-connections.free - A Counter of the number of free publish subscribe connections
  • publish-subscribe-connections.max-pool-size - A Counter of the number of maximum publish subscribe connection pool size
  • publish-subscribe-connections.total - A Counter of the number of total publish subscribe connections in pool

Metrics per RRemoteService object

Base name: redisson.remote-service.<name>

  • invocations.total - A Meter of the number of total executed invocations
  • invocations.total-failed - A Meter of the number of total failed to execute invocations
  • invocations.total-successful - A Meter of the number of total successful to execute invocations

Metrics per RExecutorService object

Base name: redisson.executor-service.<name>

  • tasks.submitted - A Meter of the number of submitted tasks
  • tasks.executed - A Meter of the number of executed tasks

  • workers.active - A Gauge of the number of busy task workers
  • workers.free - A Gauge of the number of free task workers
  • workers.total - A Gauge of the number of total task workers
  • workers.tasks-executed.total - A Meter of the number of total executed tasks by workers
  • workers.tasks-executed.total-failed - A Meter of the number of total failed to execute tasks by workers
  • workers.tasks-executed.total-successful - A Meter of the number of total successful to execute tasks by workers

Metrics per RMap object

Base name: redisson.map.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

Metrics per RMapCache object

Base name: redisson.map-cache.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

Metrics per RClusteredMapCache object

Base name: redisson.clustered-map-cache.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

Metrics per RLocalCachedMap object

Base name: redisson.local-cached-map.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

  • local-cache.hits - A Meter of the number of get requests for data contained in local cache
  • local-cache.misses - A Meter of the number of get requests for data contained in local cache
  • local-cache.evictions - A Meter of the number of evictions for data contained in local cache
  • local-cache.size - A Gauge of the number of local cache size

Metrics per RClusteredLocalCachedMap object

Base name: redisson.clustered-local-cached-map.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

  • local-cache.hits - A Meter of the number of get requests for data contained in local cache
  • local-cache.misses - A Meter of the number of get requests for data contained in local cache
  • local-cache.evictions - A Meter of the number of evictions for data contained in local cache
  • local-cache.size - A Gauge of the number of local cache size

Metrics per RLocalCachedMapCache object

Base name: redisson.local-cached-map-cache.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

  • local-cache.hits - A Meter of the number of get requests for data contained in local cache
  • local-cache.misses - A Meter of the number of get requests for data contained in local cache
  • local-cache.evictions - A Meter of the number of evictions for data contained in local cache
  • local-cache.size - A Gauge of the number of local cache size

Metrics per RClusteredLocalCachedMapCache object

Base name: redisson.clustered-local-cached-map-cache.<name>

  • hits - A Meter of the number of get requests for data contained in cache
  • misses - A Meter of the number of get requests for data not contained in cache
  • puts - A Meter of the number of puts to the cache
  • removals - A Meter of the number of removals from the cache

  • local-cache.hits - A Meter of the number of get requests for data contained in local cache
  • local-cache.misses - A Meter of the number of get requests for data contained in local cache
  • local-cache.evictions - A Meter of the number of evictions for data contained in local cache
  • local-cache.size - A Gauge of the number of local cache size

Metrics per RTopic object

Base name: redisson.topic.<name>

  • messages-sent - A Meter of the number of messages sent for topic
  • messages-received - A Meter of the number of messages received for topic

Metrics per RBucket object

Base name: redisson.bucket.<name>

  • gets - A Meter of the number of get operations executed for bucket object
  • sets - A Meter of the number of set operations executed for bucket object
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.