0
# Redisson
1
2
Redisson is a Valkey and Redis Java client that provides a comprehensive Real-Time Data Platform with distributed objects and services. It offers in-memory data grid functionality with distributed collections, locks, synchronization primitives, and messaging capabilities, all with support for reactive programming models.
3
4
## Package Information
5
6
- **Package Name**: org.redisson:redisson
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: `<dependency><groupId>org.redisson</groupId><artifactId>redisson</artifactId><version>3.50.0</version></dependency>`
10
11
## Core Imports
12
13
```java
14
import org.redisson.Redisson;
15
import org.redisson.api.RedissonClient;
16
import org.redisson.api.RedissonReactiveClient;
17
import org.redisson.api.RedissonRxClient;
18
import org.redisson.config.Config;
19
```
20
21
## Basic Usage
22
23
```java
24
import org.redisson.Redisson;
25
import org.redisson.api.RedissonClient;
26
import org.redisson.api.RMap;
27
import org.redisson.api.RLock;
28
import org.redisson.config.Config;
29
30
// Create client with default configuration
31
RedissonClient redisson = Redisson.create();
32
33
// Create client with custom configuration
34
Config config = new Config();
35
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
36
RedissonClient redisson = Redisson.create(config);
37
38
// Use distributed map
39
RMap<String, String> map = redisson.getMap("myMap");
40
map.put("key1", "value1");
41
String value = map.get("key1");
42
43
// Use distributed lock
44
RLock lock = redisson.getLock("myLock");
45
lock.lock();
46
try {
47
// Protected code
48
} finally {
49
lock.unlock();
50
}
51
52
// Cleanup
53
redisson.shutdown();
54
```
55
56
## Architecture
57
58
Redisson is built around several key components:
59
60
- **Client Factory**: `Redisson` class provides factory methods for creating different client types
61
- **Core Interfaces**: `RedissonClient` (sync), `RedissonReactiveClient` (reactive), `RedissonRxClient` (RxJava)
62
- **Configuration System**: `Config` class with various server configuration modes (single, cluster, sentinel, etc.)
63
- **Distributed Objects**: Type-safe distributed collections and data structures
64
- **Synchronization Primitives**: Locks, semaphores, barriers with Redis-backed implementations
65
- **Codec System**: Pluggable serialization with built-in support for JSON, Kryo, FST, and more
66
- **Reactive Support**: Full reactive streams and RxJava integration for non-blocking operations
67
68
## Capabilities
69
70
### Client Creation and Configuration
71
72
Core client factory methods and configuration options for connecting to Redis servers in various deployment modes.
73
74
```java { .api }
75
// Factory methods
76
public static RedissonClient create();
77
public static RedissonClient create(Config config);
78
79
// Reactive client access
80
public RedissonReactiveClient reactive();
81
public RedissonRxClient rxJava();
82
```
83
84
[Configuration and Client Setup](./configuration.md)
85
86
### Distributed Collections
87
88
Distributed implementations of standard Java collections including maps, lists, sets, queues, and specialized collections with Redis persistence.
89
90
```java { .api }
91
// Maps and caches
92
public <K, V> RMap<K, V> getMap(String name);
93
public <K, V> RMapCache<K, V> getMapCache(String name);
94
public <K, V> RLocalCachedMap<K, V> getLocalCachedMap(LocalCachedMapOptions<K, V> options);
95
96
// Lists and sequences
97
public <V> RList<V> getList(String name);
98
99
// Sets and sorted sets
100
public <V> RSet<V> getSet(String name);
101
public <V> RSortedSet<V> getSortedSet(String name);
102
public <V> RScoredSortedSet<V> getScoredSortedSet(String name);
103
public RLexSortedSet getLexSortedSet(String name);
104
105
// Queues and deques
106
public <V> RQueue<V> getQueue(String name);
107
public <V> RBlockingQueue<V> getBlockingQueue(String name);
108
public <V> RDeque<V> getDeque(String name);
109
public <V> RPriorityQueue<V> getPriorityQueue(String name);
110
111
// Multimaps
112
public <K, V> RListMultimap<K, V> getListMultimap(String name);
113
public <K, V> RSetMultimap<K, V> getSetMultimap(String name);
114
```
115
116
[Distributed Collections](./collections.md)
117
118
### Locks and Synchronization
119
120
Distributed locking and synchronization primitives for coordinating access across multiple JVM instances.
121
122
```java { .api }
123
// Locks
124
public RLock getLock(String name);
125
public RLock getFairLock(String name);
126
public RLock getSpinLock(String name);
127
public RFencedLock getFencedLock(String name);
128
public RReadWriteLock getReadWriteLock(String name);
129
130
// Multi-locks
131
public RLock getMultiLock(RLock... locks);
132
133
// Synchronization primitives
134
public RSemaphore getSemaphore(String name);
135
public RPermitExpirableSemaphore getPermitExpirableSemaphore(String name);
136
public RCountDownLatch getCountDownLatch(String name);
137
```
138
139
[Locks and Synchronization](./synchronization.md)
140
141
### Reactive and Async APIs
142
143
Non-blocking reactive programming support with Reactive Streams and RxJava interfaces for all distributed objects.
144
145
```java { .api }
146
// Reactive client interface
147
public interface RedissonReactiveClient {
148
<K, V> RMapReactive<K, V> getMap(String name);
149
RLockReactive getLock(String name);
150
}
151
152
// RxJava client interface
153
public interface RedissonRxClient {
154
<K, V> RMapRx<K, V> getMap(String name);
155
RLockRx getLock(String name);
156
}
157
```
158
159
[Reactive and Async APIs](./reactive-async.md)
160
161
### Pub/Sub Messaging
162
163
Publish/subscribe messaging system with pattern matching, sharding, and reliable delivery options.
164
165
```java { .api }
166
// Topics
167
public RTopic getTopic(String name);
168
public RPatternTopic getPatternTopic(String pattern);
169
public RShardedTopic getShardedTopic(String name);
170
public RReliableTopic getReliableTopic(String name);
171
```
172
173
[Pub/Sub Messaging](./messaging.md)
174
175
### Specialized Data Structures
176
177
Advanced data structures including atomic values, probabilistic structures, geospatial operations, time series, streams, and utility objects.
178
179
```java { .api }
180
// Atomic values
181
public RAtomicLong getAtomicLong(String name);
182
public RAtomicDouble getAtomicDouble(String name);
183
public RLongAdder getLongAdder(String name);
184
public RDoubleAdder getDoubleAdder(String name);
185
186
// Probabilistic structures
187
public <V> RBloomFilter<V> getBloomFilter(String name);
188
public <V> RHyperLogLog<V> getHyperLogLog(String name);
189
190
// Geospatial and binary operations
191
public <V> RGeo<V> getGeo(String name);
192
public RBitSet getBitSet(String name);
193
194
// Time series and streams (Redis 5.0.0+)
195
public <V, L> RTimeSeries<V, L> getTimeSeries(String name);
196
public <K, V> RStream<K, V> getStream(String name);
197
198
// Utility structures
199
public RIdGenerator getIdGenerator(String name);
200
public RRateLimiter getRateLimiter(String name);
201
202
// Data holders
203
public <V> RBucket<V> getBucket(String name);
204
public <V> RJsonBucket<V> getJsonBucket(JsonBucketOptions<V> options);
205
```
206
207
[Specialized Data Structures](./data-structures.md)
208
209
### Advanced Services
210
211
Enterprise-grade services for search, scripting, remote procedure calls, and distributed computing.
212
213
```java { .api }
214
// Search capabilities (RediSearch module)
215
public RSearch getSearch();
216
217
// Script and function execution
218
public RScript getScript();
219
public RFunction getFunction();
220
221
// Remote services and executors
222
public RRemoteService getRemoteService(String name);
223
public RScheduledExecutorService getExecutorService(String name);
224
225
// Live object service
226
public RLiveObjectService getLiveObjectService();
227
228
// Transactions and batching
229
public RTransaction createTransaction(TransactionOptions options);
230
public RBatch createBatch(BatchOptions options);
231
```
232
233
## Core Types
234
235
```java { .api }
236
// Main client interface
237
public interface RedissonClient {
238
Config getConfig();
239
void shutdown();
240
void shutdown(long quietPeriod, long timeout, TimeUnit unit);
241
boolean isShutdown();
242
boolean isShuttingDown();
243
String getId();
244
}
245
246
// Base object interface
247
public interface RObject {
248
String getName();
249
Codec getCodec();
250
}
251
252
// Expirable object interface
253
public interface RExpirable extends RExpirableAsync {
254
boolean expire(long timeToLive, TimeUnit timeUnit);
255
boolean expireAt(long timestamp);
256
boolean expireAt(Date timestamp);
257
boolean clearExpire();
258
long remainTimeToLive();
259
long getExpireTime();
260
}
261
262
// Async operations interface
263
public interface RObjectAsync {
264
RFuture<Boolean> touchAsync();
265
RFuture<Boolean> unlinkAsync();
266
RFuture<Boolean> deleteAsync();
267
RFuture<Boolean> isExistsAsync();
268
}
269
```