1. Add dependency

Maven

  1. <dependency>
  2. <groupId>org.redisson</groupId>
  3. <artifactId>redisson</artifactId>
  4. <version>xVERSIONx</version>
  5. </dependency>

Gradle

  1. compile 'org.redisson:redisson:xVERSIONx'

SBT

  1. libraryDependencies += "org.redisson" % "redisson" % "xVERSIONx"

2. Start development

  1. Create config object.
    Use one of supported modes: (single mode, replicated mode, cluster mode, sentinel mode, proxy mode, multi cluster mode, multi sentinel mode)

    1. Config config = new Config();
    2. config.useClusterServers()
    3. // use "redis://" for Redis connection
    4. // use "valkey://" for Valkey connection
    5. // use "valkeys://" for Valkey SSL connection
    6. // use "rediss://" for Redis SSL connection
    7. .addNodeAddress("redis://127.0.0.1:7181");
    8. // or read config from file
    9. config = Config.fromYAML(new File("config-file.yaml"));
  2. Create Redisson instance.

    1. // Sync and Async API
    2. RedissonClient redisson = Redisson.create(config);
    3. // Reactive API
    4. RedissonReactiveClient redissonReactive = redisson.reactive();
    5. // RxJava3 API
    6. RedissonRxClient redissonRx = redisson.rxJava();
  3. Get Redis or Valkey based object or service.

    1. // java.util.concurrent.ConcurrentMap
    2. RMap<MyKey, MyValue> map = redisson.getMap("myMap");
    3. RMapReactive<MyKey, MyValue> mapReactive = redissonReactive.getMap("myMap");
    4. RMapRx<MyKey, MyValue> mapRx = redissonRx.getMap("myMap");
    5. // client side caching
    6. RLocalCachedMap<MyKey, MyValue> map = redisson.getLocalCachedMap(LocalCachedMapOptions.<MyKey, MyValue>name("myMap"));
    7. // java.util.concurrent.locks.Lock
    8. RLock lock = redisson.getLock("myLock");
    9. RLockReactive lockReactive = redissonReactive.getLock("myLock");
    10. RLockRx lockRx = redissonRx.getLock("myLock");
    11. // java.util.concurrent.ExecutorService
    12. RExecutorService executor = redisson.getExecutorService("myExecutorService");
    13. // over 50 Redis or Valkey based Java objects and services ...

More code examples can be found here.

Upgrade to Redisson PRO with advanced features.