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.
Join the DZone community and get the full member experience.
Join For FreeHow 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:
Redis based Distributed Java 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 |
Redis based Distributed Java 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 |
Redis based Distributed Java 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 |
Redis based Distributed Java 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.
Replicated nodes: automatic master server change discovery (also supports AWS ElastiCache and Azure Redis Cache).
Cluster nodes: automatic servers discovery, status and topology update (also supports AWS ElastiCache Cluster and Azure Redis Cache).
Sentinel nodes: automatic server discovery and status update.
Master with Slave nodes.
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 for Java like JCache API, Hibernate 2nd Level Cache, and Spring Cache.
Opinions expressed by DZone contributors are their own.
Comments