Redisson概述

Redisson概述

Redisson is a Redis Java client with features of In-Memory Data Grid.
Redisson objects provides a separation of concern, which allows you to keep focus on the data modeling and application logic.

Programmatic configuration

1
2
3
4
5
6
7
Config config = new Config();
config.setTransportMode(TransportMode.EPOLL);
config.useClusterServers()
// use "rediss://" for SSL connection
.addNodeAddress("perredis://127.0.0.1:7181");

RedissonClient redisson = Redisson.create(config);

Declarative configuration

1
2
3
4
5
6
YAML file based configuration
Redisson configuration could be stored in YAML format.
Use config.fromYAML method to read configuration stored in YAML format:

Config config = Config.fromYAML(new File("config-file.yaml"));
RedissonClient redisson = Redisson.create(config);

Common settings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Follow settings belong to org.redisson.Config object and common for all modes:

codec
Default value: org.redisson.codec.FstCodec

Redis data codec. Used during read and write Redis data. Several implementations are available.

nettyThreads
Default value: 32

Threads amount shared between all redis clients used by Redisson. Netty threads used in Redis response decoding and command sending. 0 = cores_amount * 2

nettyHook
Default value: empty object

Netty hook applied to Netty Bootstrap and Channel objects.

executor
Use external ExecutorService which process all listeners of RTopic, RRemoteService invocation handlers and RExecutorService tasks.

eventLoopGroup
Use external EventLoopGroup. EventLoopGroup processes all Netty connection tied with Redis servers by own threads.
Each Redisson client creates own EventLoopGroup by default. So if there are multiple Redisson instances in same JVM it would be useful to share one EventLoopGroup among them.

Only io.netty.channel.epoll.EpollEventLoopGroup, io.netty.channel.kqueue.KQueueEventLoopGroup and io.netty.channel.nio.NioEventLoopGroup are allowed for usage.

transportMode
Default value: TransportMode.NIO

Available values:
TransportMode.NIO,
TransportMode.EPOLL - requires netty-transport-native-epoll lib in classpath
TransportMode.KQUEUE - requires netty-transport-native-kqueue lib in classpath

threads
Default value: 16

Threads amount shared across all listeners of RTopic object, invocation handlers of RRemoteService, RTopic object and RExecutorService tasks.

lockWatchdogTimeout
Default value: 30000

Lock watchdog timeout in milliseconds. This parameter is only used if lock has been acquired without leaseTimeout parameter definition.
Lock will be expired after lockWatchdogTimeout if watchdog didn't extend it to the next lockWatchdogTimeout time interval.
This prevents against infinity locked locks due to Redisson client crush or any other reason when lock can't be released in proper way.

addressResolverGroupFactory
Default value: org.redisson.connection.DnsAddressResolverGroupFactory

Allows to specify customized implementation of DnsAddressResolverGroup.

Available implementations:

org.redisson.connection.DnsAddressResolverGroupFactory - uses default DNS servers list provided by OS.
org.redisson.connection.RoundRobinDnsAddressResolverGroupFactory - uses default DNS servers list provided by OS in round robin mode.
useScriptCache
Default value: false

Defines whether to use Lua-script cache on Redis side. Most Redisson methods are Lua-script based and this setting turned on could increase speed of such methods execution and save network traffic.

NOTE: readMode option is not taken into account for such calls as Redis slave redirects execution of cached Lua-script on Redis master node.

keepPubSubOrder
Default value: true

Defines whether keep PubSub messages handling in arrival order or handle messages concurrently. This setting applied only for PubSub messages per channel.

minCleanUpDelay
Default value: 5

Defines minimum delay in seconds for clean up process of expired entries. Applied to JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects.

maxCleanUpDelay
Default value: 1800

Defines maximum delay in seconds for clean up process of expired entries. Applied to JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects.

cleanUpKeysAmount
Default value: 100

Defines expired keys amount deleted per single operation during clean up process of expired entries. Applied to JCache, RSetCache, RMapCache, RListMultimapCache, RSetMultimapCache objects.

meterMode
Default value: MeterMode.ALL

Defines Micrometer statistics collection mode.

This setting is available only in Redisson PRO edition.

Available values:

MeterMode.ALL - collect both Redis and Redisson objects statistics
MeterMode.REDIS - collect only Redis statistics
MeterMode.OBJECTS - collect only Redisson objects statistics
meterRegistryProvider
Default value: null

Defines Micrometer registry provider used to collect various statistics for Redisson objects. Please refer to statistics monitoring sections for list of all available providers.

This setting is available only in Redisson PRO edition.

useThreadClassLoader
Default value: true

Defines whether to supply Thread ContextClassLoader to Codec. Usage of Thread.getContextClassLoader() may resolve ClassNotFoundException error arise during Redis response decoding.
This error might arise if Redisson is used in both Tomcat and deployed application.

performanceMode
Default value: LOWER_LATENCY_MODE_2

Defines command processing engine performance mode. Since all values are application specific (except NORMAL value) it's recommended to try all of them.

This setting is available only in Redisson PRO edition.

Available values:

HIGHER_THROUGHPUT - switches command processor engine to higher throughput mode
LOWER_LATENCY_AUTO - switches command processor engine to lower latency mode and detect optimal settings automatically
LOWER_LATENCY_MODE_2 - switches command processor engine to lower latency mode with predefined settings set #2
LOWER_LATENCY_MODE_1 - switches command processor engine to lower latency mode with predefined settings set #1
NORMAL - switches command processor engine to normal mode