Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Creating Distributed Java Applications With Redis

DZone's Guide to

Creating Distributed Java Applications With Redis

If you make distributed systems with Java, Redisson can provide you with an in-memory data grid. See how Redisson and JDK's implementations match up.

· Java Zone ·
Free Resource

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

How can we scale a Java application with minimal effort?

As we know, almost every multithreaded Java application use classes from the java.util and java.util.concurrent packages. So, it would be easier to scale the application if we have a distributed implementations of the equivalent classes. The benefit of such an approach is allowing the use of the well-known Java API, and therefore changes required in existing code would be minimal.

Redisson is a Redis-based in-memory data grid for Java. It offers implementations of the most important Java classes required for distributed applications.

Below is a list of common Java classes along with their corresponding distributed implementations based on Redis for each of them:

Distributed Locks and Synchronizers

JDK API

Redisson's Redis based Java implementation

java.util.concurrent.locks.Lock

org.redisson.api.RLock

java.util.concurrent.locks.ReadWriteLock

org.redisson.api.RReadWriteLock

java.util.concurrent.CountDownLatch

org.redisson.api.RCountDownLatch

java.util.concurrent.Semaphore

org.redisson.api.RSemaphore


Distributed Collections

JDK API

Redisson's Redis based Java implementation

java.util.Set

org.redisson.api.RSet

java.util.concurrent.ConcurrentMap

org.redisson.api.RMap

java.util.Queue

org.redisson.api.RQueue, 

org.redisson.api.RPriorityQueue, 

org.redisson.api.RDelayedQueue

java.util.Deque

org.redisson.api.RDeque,

org.redisson.api.RPriorityDeque

java.util.concurrent.BlockingQueue

org.redisson.api.RBlockingQueue

java.util.concurrent.BlockingDeque

org.redisson.api.RBlockingDeque


Distributed Services

JDK API

Redisson's Redis based Java implementation

Java RMI

org.redisson.api.RRemoteService

java.util.concurrent.ExecutorService

org.redisson.api.RExecutorService

java.util.concurrent.ScheduledExecutorService


org.redisson.api.RScheduledExecutorService


Distributed Objects

JDK API

Redisson's Redis based Java implementation

java.util.concurrent.atomic.AtomicReference

org.redisson.api.RBucket

java.util.concurrent.atomic.AtomicLong

org.redisson.api.RAtomicLong

java.util.BitSet

org.redisson.api.RBitSet

byte[], java.io.InputStream, java.io.OutputStream


org.redisson.api.RBinaryStream


Redisson supports several types of Redis connections available for Distributed Java applications.

  1. Replicated nodes: automatic master server change discovery (also supports AWS ElastiCache and Azure Redis Cache).

  2. Cluster nodes: automatic servers discovery, status and topology update (also supports AWS ElastiCache Cluster and Azure Redis Cache).

  3. Sentinel nodes: automatic server discovery and status update.

  4. Master with Slave nodes.

  5. Single node.

Quickstart

1. Define the dependency

Maven

<dependency>
   <groupId>org.redisson</groupId>
   <artifactId>redisson</artifactId>
   <version>3.3.1</version>
</dependency>  


Gradle

compile 'org.redisson:redisson:3.3.1'  


2. Create a config object in your Java application

// from JSON
Config config = Config.fromJSON(...)
// from YAML
Config config = Config.fromYAML(...)
// or dynamically
Config config = new Config();
config.useClusterServers()


3. Create a Redisson instance

RedissonClient redisson = Redisson.create(config);


4. Get the Redis based object you need in your Distributed Java application

RMap<MyKey, MyValue> map = redisson.getMap("myMap");

RLock lock = redisson.getLock("myLock");

RExecutorService executor = redisson.getExecutorService("myExecutorService");

// plus over 30 different objects and services ...


And there you have it! All taken care of.

Redisson also offers different caching implementations like JCache API, Hibernate 2nd Level Cache, and Spring Cache.

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

Topics:
java ,distributed applications ,redisson ,in-memory data grid ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}