Valkey and Redis Java client providing complete Real-Time Data Platform with distributed objects and services
—
Redisson provides distributed implementations of standard Java collections that are automatically persisted and synchronized across Redis. These collections maintain the same interfaces as their Java counterparts while providing distributed functionality.
Distributed key-value maps with various caching and persistence strategies.
/**
* Get a distributed map with the specified name
* @param name - unique name of the map
* @return RMap instance
*/
public <K, V> RMap<K, V> getMap(String name);
/**
* Get a distributed map with custom codec
* @param name - unique name of the map
* @param codec - serialization codec
* @return RMap instance
*/
public <K, V> RMap<K, V> getMap(String name, Codec codec);
/**
* Get a distributed map with options
* @param options - map configuration options
* @return RMap instance
*/
public <K, V> RMap<K, V> getMap(MapOptions<K, V> options);
/**
* Get a distributed map cache with TTL support
* @param name - unique name of the map cache
* @return RMapCache instance with expiration capabilities
*/
public <K, V> RMapCache<K, V> getMapCache(String name);
public <K, V> RMapCache<K, V> getMapCache(String name, Codec codec);
public <K, V> RMapCache<K, V> getMapCache(MapCacheOptions<K, V> options);
/**
* Get a local cached map for improved read performance
* @param name - unique name of the local cached map
* @param options - local caching options and strategies
* @return RLocalCachedMap instance
*/
public <K, V> RLocalCachedMap<K, V> getLocalCachedMap(String name, LocalCachedMapOptions<K, V> options);
public <K, V> RLocalCachedMap<K, V> getLocalCachedMap(String name, Codec codec, LocalCachedMapOptions<K, V> options);Map Interfaces:
// Standard distributed map
public interface RMap<K, V> extends ConcurrentMap<K, V>, RObject, RExpirable {
V put(K key, V value);
V putIfAbsent(K key, V value);
V get(Object key);
V remove(Object key);
boolean containsKey(Object key);
boolean containsValue(Object value);
int size();
boolean isEmpty();
void clear();
Set<K> keySet();
Collection<V> values();
Set<Entry<K, V>> entrySet();
// Redisson-specific methods
V addAndGet(K key, Number delta);
Set<K> readAllKeySet();
Collection<V> readAllValues();
Set<Entry<K, V>> readAllEntrySet();
Map<K, V> readAllMap();
// Fast operations
long fastPut(K key, V value);
boolean fastPutIfAbsent(K key, V value);
long fastRemove(K... keys);
}
// Map with TTL capabilities
public interface RMapCache<K, V> extends RMap<K, V> {
V put(K key, V value, long ttl, TimeUnit unit);
V putIfAbsent(K key, V value, long ttl, TimeUnit unit);
V put(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit);
void expire(long timeToLive, TimeUnit timeUnit);
boolean expireAt(long timestamp);
void clearExpire();
long remainTimeToLive();
// Entry-level expiration
boolean expire(K key, long timeToLive, TimeUnit timeUnit);
boolean expireAt(K key, long timestamp);
long remainTimeToLive(K key);
}
// Local cached map for improved performance
public interface RLocalCachedMap<K, V> extends RMap<K, V> {
void preloadCache();
void preloadCache(int count);
void clearLocalCache();
// Cache statistics
LocalCachedMapStats getCachedMapStats();
}Usage Examples:
import org.redisson.api.*;
import java.util.concurrent.TimeUnit;
// Basic map operations
RMap<String, String> map = redisson.getMap("users");
map.put("user1", "Alice");
map.put("user2", "Bob");
String user = map.get("user1"); // "Alice"
// Map cache with TTL
RMapCache<String, String> cache = redisson.getMapCache("sessions");
cache.put("session1", "data", 30, TimeUnit.MINUTES);
cache.put("session2", "data", 1, TimeUnit.HOURS, 15, TimeUnit.MINUTES); // TTL + max idle time
// Local cached map for performance
LocalCachedMapOptions<String, String> options = LocalCachedMapOptions.<String, String>defaults()
.cacheSize(1000)
.timeToLive(10, TimeUnit.MINUTES)
.maxIdle(5, TimeUnit.MINUTES);
RLocalCachedMap<String, String> localCachedMap = redisson.getLocalCachedMap("products", options);
localCachedMap.put("product1", "data"); // Cached locally and in RedisDistributed lists maintaining insertion order with indexed access.
/**
* Get a distributed list with the specified name
* @param name - unique name of the list
* @return RList instance
*/
public <V> RList<V> getList(String name);
public <V> RList<V> getList(String name, Codec codec);
public <V> RList<V> getList(PlainOptions options);List Interface:
public interface RList<V> extends List<V>, RObject, RExpirable, RSortable<List<V>> {
// Standard List methods
boolean add(V element);
void add(int index, V element);
V get(int index);
V set(int index, V element);
V remove(int index);
boolean remove(Object o);
int indexOf(Object o);
int lastIndexOf(Object o);
int size();
boolean isEmpty();
void clear();
// Redisson-specific methods
List<V> readAll();
void trim(int fromIndex, int toIndex);
// Range operations
List<V> range(int fromIndex);
List<V> range(int fromIndex, int toIndex);
// Fast operations
boolean addAll(Collection<? extends V> c);
boolean addAll(int index, Collection<? extends V> c);
int addAfter(V elementToFind, V element);
int addBefore(V elementToFind, V element);
// Sorting
List<V> sort(SortOrder order);
List<V> sort(SortOrder order, int offset, int count);
List<V> sort(String byPattern, SortOrder order);
List<V> sort(String byPattern, List<String> getPatterns, SortOrder order);
}Usage Examples:
// Basic list operations
RList<String> list = redisson.getList("tasks");
list.add("Task 1");
list.add("Task 2");
list.add(1, "Task 1.5"); // Insert at index
String task = list.get(0); // "Task 1"
list.remove(1); // Remove "Task 1.5"
// Range operations
List<String> subset = list.range(0, 5); // Get first 5 elements
list.trim(0, 10); // Keep only first 10 elements
// Sorting
list.addAll(Arrays.asList("c", "a", "b"));
List<String> sorted = list.sort(SortOrder.ASC); // ["a", "b", "c"]Distributed sets ensuring unique elements.
/**
* Get a distributed set with the specified name
* @param name - unique name of the set
* @return RSet instance
*/
public <V> RSet<V> getSet(String name);
public <V> RSet<V> getSet(String name, Codec codec);
public <V> RSet<V> getSet(PlainOptions options);
/**
* Get a distributed set cache with TTL support
* @param name - unique name of the set cache
* @return RSetCache instance with expiration capabilities
*/
public <V> RSetCache<V> getSetCache(String name);
public <V> RSetCache<V> getSetCache(String name, Codec codec);
/**
* Get a distributed sorted set
* @param name - unique name of the sorted set
* @return RSortedSet instance maintaining sort order
*/
public <V> RSortedSet<V> getSortedSet(String name);
public <V> RSortedSet<V> getSortedSet(String name, Codec codec);
/**
* Get a distributed scored sorted set (Redis ZSET)
* @param name - unique name of the scored sorted set
* @return RScoredSortedSet instance with score-based ordering
*/
public <V> RScoredSortedSet<V> getScoredSortedSet(String name);
public <V> RScoredSortedSet<V> getScoredSortedSet(String name, Codec codec);
/**
* Get a lexicographically sorted set
* @param name - unique name of the lex sorted set
* @return RLexSortedSet instance with lexicographic ordering
*/
public RLexSortedSet getLexSortedSet(String name);Set Interfaces:
// Standard distributed set
public interface RSet<V> extends Set<V>, RObject, RExpirable, RSortable<Set<V>> {
boolean add(V element);
boolean remove(Object o);
boolean contains(Object o);
int size();
boolean isEmpty();
void clear();
Object[] toArray();
<T> T[] toArray(T[] a);
// Redisson-specific methods
Set<V> readAll();
boolean move(String destination, V member);
// Set operations
Set<V> removeRandom(int amount);
V removeRandom();
V random();
Set<V> random(int count);
// Union/Intersection
int union(String... names);
Set<V> readUnion(String... names);
int intersection(String... names);
Set<V> readIntersection(String... names);
int diff(String... names);
Set<V> readDiff(String... names);
}
// Sorted set with natural ordering
public interface RSortedSet<V> extends SortedSet<V>, RSet<V> {
Comparator<? super V> comparator();
V first();
V last();
SortedSet<V> headSet(V toElement);
SortedSet<V> tailSet(V fromElement);
SortedSet<V> subSet(V fromElement, V toElement);
}
// Scored sorted set (Redis ZSET)
public interface RScoredSortedSet<V> extends RObject, RExpirable, RSortable<Collection<V>> {
boolean add(double score, V object);
boolean addAll(Map<V, Double> objects);
V first();
V last();
Double firstScore();
Double lastScore();
Collection<V> valueRange(int startIndex, int endIndex);
Collection<ScoredEntry<V>> entryRange(int startIndex, int endIndex);
Collection<V> valueRange(double startScore, boolean startScoreInclusive,
double endScore, boolean endScoreInclusive);
Double getScore(V o);
int rank(V o);
int revRank(V o);
// Score-based operations
Double addScore(V object, Number value);
int removeRangeByScore(double startScore, boolean startScoreInclusive,
double endScore, boolean endScoreInclusive);
int removeRangeByRank(int startIndex, int endIndex);
}Usage Examples:
// Basic set operations
RSet<String> set = redisson.getSet("uniqueUsers");
set.add("user1");
set.add("user2");
set.add("user1"); // Duplicate, won't be added
boolean contains = set.contains("user1"); // true
// Sorted set with scores (leaderboard)
RScoredSortedSet<String> leaderboard = redisson.getScoredSortedSet("gameScores");
leaderboard.add(1000, "player1");
leaderboard.add(1500, "player2");
leaderboard.add(800, "player3");
Collection<String> topPlayers = leaderboard.valueRangeReversed(0, 2); // Top 3 players
Double player1Score = leaderboard.getScore("player1"); // 1000.0
int player1Rank = leaderboard.revRank("player1"); // Position in leaderboard (0-based)Distributed queues with FIFO ordering and blocking capabilities.
/**
* Get a distributed queue with the specified name
* @param name - unique name of the queue
* @return RQueue instance
*/
public <V> RQueue<V> getQueue(String name);
public <V> RQueue<V> getQueue(String name, Codec codec);
/**
* Get a blocking queue that blocks on empty queue reads
* @param name - unique name of the blocking queue
* @return RBlockingQueue instance
*/
public <V> RBlockingQueue<V> getBlockingQueue(String name);
public <V> RBlockingQueue<V> getBlockingQueue(String name, Codec codec);
/**
* Get a deque (double-ended queue) for both ends operations
* @param name - unique name of the deque
* @return RDeque instance
*/
public <V> RDeque<V> getDeque(String name);
public <V> RDeque<V> getDeque(String name, Codec codec);
/**
* Get a blocking deque
* @param name - unique name of the blocking deque
* @return RBlockingDeque instance
*/
public <V> RBlockingDeque<V> getBlockingDeque(String name);
public <V> RBlockingDeque<V> getBlockingDeque(String name, Codec codec);
/**
* Get a priority queue with custom ordering
* @param name - unique name of the priority queue
* @return RPriorityQueue instance
*/
public <V> RPriorityQueue<V> getPriorityQueue(String name);
public <V> RPriorityQueue<V> getPriorityQueue(String name, Codec codec);
/**
* Get a transfer queue for producer-consumer patterns
* @param name - unique name of the transfer queue
* @return RTransferQueue instance
*/
public <V> RTransferQueue<V> getTransferQueue(String name);
public <V> RTransferQueue<V> getTransferQueue(String name, Codec codec);Queue Interfaces:
// Standard queue interface
public interface RQueue<V> extends Queue<V>, RObject, RExpirable {
boolean add(V element);
boolean offer(V element);
V remove();
V poll();
V element();
V peek();
// Redisson-specific methods
List<V> readAll();
boolean addAll(Collection<? extends V> c);
List<V> poll(int limit);
// Polling with destination
V pollFromAny(long timeout, TimeUnit unit, String... queueNames);
Map<String, List<V>> pollFirstAndOfferFirstTo(String queueName, int count, long timeout, TimeUnit unit);
}
// Blocking queue with timeout operations
public interface RBlockingQueue<V> extends BlockingQueue<V>, RQueue<V> {
void put(V element) throws InterruptedException;
boolean offer(V element, long timeout, TimeUnit unit) throws InterruptedException;
V take() throws InterruptedException;
V poll(long timeout, TimeUnit unit) throws InterruptedException;
// Multi-queue operations
V takeFromAny(String... queueNames) throws InterruptedException;
V pollFromAny(long timeout, TimeUnit unit, String... queueNames) throws InterruptedException;
// Batch operations
int drainTo(Collection<? super V> c);
int drainTo(Collection<? super V> c, int maxElements);
}
// Double-ended queue
public interface RDeque<V> extends Deque<V>, RQueue<V> {
void addFirst(V element);
void addLast(V element);
boolean offerFirst(V element);
boolean offerLast(V element);
V removeFirst();
V removeLast();
V pollFirst();
V pollLast();
V getFirst();
V getLast();
V peekFirst();
V peekLast();
// Move operations
V move(DequeMoveArgs args);
}
// Priority queue with comparator support
public interface RPriorityQueue<V> extends Queue<V>, RObject, RExpirable {
Comparator<? super V> comparator();
boolean trySetComparator(Comparator<? super V> comparator);
boolean add(V element);
boolean offer(V element);
V poll();
V peek();
// Bulk operations
List<V> readAll();
boolean addAll(Collection<? extends V> c);
}Usage Examples:
// Basic queue operations
RQueue<String> queue = redisson.getQueue("tasks");
queue.offer("task1");
queue.offer("task2");
String nextTask = queue.poll(); // "task1" (FIFO)
// Blocking queue for producer-consumer
RBlockingQueue<String> blockingQueue = redisson.getBlockingQueue("jobs");
// Producer thread
blockingQueue.put("job1");
blockingQueue.offer("job2", 5, TimeUnit.SECONDS);
// Consumer thread
String job = blockingQueue.take(); // Blocks until element available
String jobWithTimeout = blockingQueue.poll(10, TimeUnit.SECONDS);
// Priority queue with custom ordering
RPriorityQueue<Task> priorityQueue = redisson.getPriorityQueue("priorityTasks");
priorityQueue.trySetComparator((t1, t2) -> t2.getPriority() - t1.getPriority()); // High priority first
priorityQueue.offer(new Task("low", 1));
priorityQueue.offer(new Task("high", 10));
Task highestPriority = priorityQueue.poll(); // "high" priority task
// Deque operations
RDeque<String> deque = redisson.getDeque("workItems");
deque.addFirst("urgent");
deque.addLast("normal");
String urgent = deque.pollFirst(); // "urgent"
String normal = deque.pollLast(); // "normal"Distributed multimaps that can store multiple values per key, backed by either lists or sets.
/**
* Get a list-based multimap where each key maps to a list of values
* @param name - unique name of the list multimap
* @return RListMultimap instance
*/
public <K, V> RListMultimap<K, V> getListMultimap(String name);
public <K, V> RListMultimap<K, V> getListMultimap(String name, Codec codec);
public <K, V> RListMultimap<K, V> getListMultimap(PlainOptions options);
/**
* Get a list multimap cache with TTL support
* @param name - unique name of the list multimap cache
* @return RListMultimapCache instance with expiration capabilities
*/
public <K, V> RListMultimapCache<K, V> getListMultimapCache(String name);
public <K, V> RListMultimapCache<K, V> getListMultimapCache(String name, Codec codec);
/**
* Get a set-based multimap where each key maps to a set of unique values
* @param name - unique name of the set multimap
* @return RSetMultimap instance
*/
public <K, V> RSetMultimap<K, V> getSetMultimap(String name);
public <K, V> RSetMultimap<K, V> getSetMultimap(String name, Codec codec);
public <K, V> RSetMultimap<K, V> getSetMultimap(PlainOptions options);
/**
* Get a set multimap cache with TTL support
* @param name - unique name of the set multimap cache
* @return RSetMultimapCache instance with expiration capabilities
*/
public <K, V> RSetMultimapCache<K, V> getSetMultimapCache(String name);
public <K, V> RSetMultimapCache<K, V> getSetMultimapCache(String name, Codec codec);Multimap Interfaces:
// List-based multimap allowing duplicate values per key
public interface RListMultimap<K, V> extends RObject, RExpirable {
int size();
boolean isEmpty();
boolean containsKey(Object key);
boolean containsValue(Object value);
boolean containsEntry(Object key, Object value);
// Adding entries
boolean put(K key, V value);
boolean putAll(K key, Iterable<? extends V> values);
boolean putAll(Multimap<? extends K, ? extends V> multimap);
// Retrieving values
RList<V> get(K key);
Collection<V> getAll(K key);
RList<V> removeAll(Object key);
boolean remove(Object key, Object value);
// Key and value collections
Set<K> keySet();
Multiset<K> keys();
Collection<V> values();
Collection<Entry<K, V>> entries();
// Fast operations
long fastRemove(K... keys);
}
// Set-based multimap ensuring unique values per key
public interface RSetMultimap<K, V> extends RObject, RExpirable {
int size();
boolean isEmpty();
boolean containsKey(Object key);
boolean containsValue(Object value);
boolean containsEntry(Object key, Object value);
// Adding entries
boolean put(K key, V value);
boolean putAll(K key, Iterable<? extends V> values);
// Retrieving values
RSet<V> get(K key);
Collection<V> getAll(K key);
RSet<V> removeAll(Object key);
boolean remove(Object key, Object value);
// Key and value collections
Set<K> keySet();
Multiset<K> keys();
Collection<V> values();
Collection<Entry<K, V>> entries();
}Multimap Usage Examples:
// List multimap - allows duplicate values per key
RListMultimap<String, String> listMultimap = redisson.getListMultimap("userRoles");
listMultimap.put("user1", "admin");
listMultimap.put("user1", "user");
listMultimap.put("user1", "admin"); // Duplicate allowed in list multimap
RList<String> user1Roles = listMultimap.get("user1"); // ["admin", "user", "admin"]
Collection<String> allRoles = listMultimap.getAll("user1");
// Set multimap - unique values per key only
RSetMultimap<String, String> setMultimap = redisson.getSetMultimap("userPermissions");
setMultimap.put("user1", "read");
setMultimap.put("user1", "write");
setMultimap.put("user1", "read"); // Duplicate ignored in set multimap
RSet<String> user1Permissions = setMultimap.get("user1"); // ["read", "write"]
// Multimap cache with TTL
RListMultimapCache<String, String> multimapCache = redisson.getListMultimapCache("sessionData");
multimapCache.put("session1", "data1");
multimapCache.expireKey("session1", 30, TimeUnit.MINUTES);Specialized collection types for specific use cases and performance optimization.
/**
* Get a ring buffer with fixed capacity and circular overwriting
* @param name - unique name of the ring buffer
* @return RRingBuffer instance
*/
public <V> RRingBuffer<V> getRingBuffer(String name);
public <V> RRingBuffer<V> getRingBuffer(String name, Codec codec);
/**
* Get a reliable queue with delivery acknowledgment
* @param name - unique name of the reliable queue
* @return RReliableQueue instance
*/
public <V> RReliableQueue<V> getReliableQueue(String name);
public <V> RReliableQueue<V> getReliableQueue(String name, Codec codec);
/**
* Get a priority blocking queue with thread-safe operations
* @param name - unique name of the priority blocking queue
* @return RPriorityBlockingQueue instance
*/
public <V> RPriorityBlockingQueue<V> getPriorityBlockingQueue(String name);
public <V> RPriorityBlockingQueue<V> getPriorityBlockingQueue(String name, Codec codec);
/**
* Get a priority deque supporting both priority ordering and deque operations
* @param name - unique name of the priority deque
* @return RPriorityDeque instance
*/
public <V> RPriorityDeque<V> getPriorityDeque(String name);
public <V> RPriorityDeque<V> getPriorityDeque(String name, Codec codec);Advanced Collection Usage Examples:
// Ring buffer with fixed capacity
RRingBuffer<String> ringBuffer = redisson.getRingBuffer("events");
ringBuffer.trySetCapacity(100); // Fixed size of 100 elements
ringBuffer.add("event1");
ringBuffer.add("event2");
// When capacity is reached, oldest elements are overwritten
// Reliable queue with acknowledgment
RReliableQueue<String> reliableQueue = redisson.getReliableQueue("importantTasks");
reliableQueue.offer("critical-task");
// Consumer processes with acknowledgment
String task = reliableQueue.poll(); // Remove from queue
// Process task...
// If processing succeeds, task is automatically acknowledged
// If JVM crashes before ack, task returns to queue// Map configuration options
public class MapOptions<K, V> {
private MapLoader<K, V> loader;
private MapWriter<K, V> writer;
private WriteBehindOptions writeBehindOptions;
private WriteMode writeMode = WriteMode.WRITE_THROUGH;
public MapOptions<K, V> loader(MapLoader<K, V> loader);
public MapOptions<K, V> writer(MapWriter<K, V> writer);
public MapOptions<K, V> writeMode(WriteMode writeMode);
public MapOptions<K, V> writeBehind(WriteBehindOptions options);
}
// Map cache configuration with eviction
public class MapCacheOptions<K, V> extends MapOptions<K, V> {
private EvictionPolicy evictionPolicy = EvictionPolicy.NONE;
private int maxSize;
private long timeToLiveInMillis;
private long maxIdleInMillis;
public MapCacheOptions<K, V> evictionPolicy(EvictionPolicy evictionPolicy);
public MapCacheOptions<K, V> maxSize(int maxSize);
public MapCacheOptions<K, V> timeToLive(long timeToLive, TimeUnit timeUnit);
public MapCacheOptions<K, V> maxIdle(long maxIdle, TimeUnit timeUnit);
}
// Local cached map options for performance
public class LocalCachedMapOptions<K, V> extends MapOptions<K, V> {
public enum ReconnectionStrategy { CLEAR, LOAD, NONE }
public enum SyncStrategy { INVALIDATE, UPDATE, NONE }
private ReconnectionStrategy reconnectionStrategy = ReconnectionStrategy.CLEAR;
private SyncStrategy syncStrategy = SyncStrategy.INVALIDATE;
private int cacheSize = 0;
private long timeToLiveInMillis;
private long maxIdleInMillis;
public LocalCachedMapOptions<K, V> cacheSize(int cacheSize);
public LocalCachedMapOptions<K, V> timeToLive(long timeToLive, TimeUnit timeUnit);
public LocalCachedMapOptions<K, V> maxIdle(long maxIdle, TimeUnit timeUnit);
public LocalCachedMapOptions<K, V> reconnectionStrategy(ReconnectionStrategy strategy);
public LocalCachedMapOptions<K, V> syncStrategy(SyncStrategy strategy);
}Install with Tessl CLI
npx tessl i tessl/maven-org-redisson--redisson