001/*
002 * Copyright 2012-2017 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.data.redis;
018
019import java.time.Duration;
020import java.util.List;
021
022import org.springframework.boot.context.properties.ConfigurationProperties;
023
024/**
025 * Configuration properties for Redis.
026 *
027 * @author Dave Syer
028 * @author Christoph Strobl
029 * @author EddĂș MelĂ©ndez
030 * @author Marco Aust
031 * @author Mark Paluch
032 * @author Stephane Nicoll
033 */
034@ConfigurationProperties(prefix = "spring.redis")
035public class RedisProperties {
036
037        /**
038         * Database index used by the connection factory.
039         */
040        private int database = 0;
041
042        /**
043         * Connection URL. Overrides host, port, and password. User is ignored. Example:
044         * redis://user:[email protected]:6379
045         */
046        private String url;
047
048        /**
049         * Redis server host.
050         */
051        private String host = "localhost";
052
053        /**
054         * Login password of the redis server.
055         */
056        private String password;
057
058        /**
059         * Redis server port.
060         */
061        private int port = 6379;
062
063        /**
064         * Whether to enable SSL support.
065         */
066        private boolean ssl;
067
068        /**
069         * Connection timeout.
070         */
071        private Duration timeout;
072
073        private Sentinel sentinel;
074
075        private Cluster cluster;
076
077        private final Jedis jedis = new Jedis();
078
079        private final Lettuce lettuce = new Lettuce();
080
081        public int getDatabase() {
082                return this.database;
083        }
084
085        public void setDatabase(int database) {
086                this.database = database;
087        }
088
089        public String getUrl() {
090                return this.url;
091        }
092
093        public void setUrl(String url) {
094                this.url = url;
095        }
096
097        public String getHost() {
098                return this.host;
099        }
100
101        public void setHost(String host) {
102                this.host = host;
103        }
104
105        public String getPassword() {
106                return this.password;
107        }
108
109        public void setPassword(String password) {
110                this.password = password;
111        }
112
113        public int getPort() {
114                return this.port;
115        }
116
117        public void setPort(int port) {
118                this.port = port;
119        }
120
121        public boolean isSsl() {
122                return this.ssl;
123        }
124
125        public void setSsl(boolean ssl) {
126                this.ssl = ssl;
127        }
128
129        public void setTimeout(Duration timeout) {
130                this.timeout = timeout;
131        }
132
133        public Duration getTimeout() {
134                return this.timeout;
135        }
136
137        public Sentinel getSentinel() {
138                return this.sentinel;
139        }
140
141        public void setSentinel(Sentinel sentinel) {
142                this.sentinel = sentinel;
143        }
144
145        public Cluster getCluster() {
146                return this.cluster;
147        }
148
149        public void setCluster(Cluster cluster) {
150                this.cluster = cluster;
151        }
152
153        public Jedis getJedis() {
154                return this.jedis;
155        }
156
157        public Lettuce getLettuce() {
158                return this.lettuce;
159        }
160
161        /**
162         * Pool properties.
163         */
164        public static class Pool {
165
166                /**
167                 * Maximum number of "idle" connections in the pool. Use a negative value to
168                 * indicate an unlimited number of idle connections.
169                 */
170                private int maxIdle = 8;
171
172                /**
173                 * Target for the minimum number of idle connections to maintain in the pool. This
174                 * setting only has an effect if it is positive.
175                 */
176                private int minIdle = 0;
177
178                /**
179                 * Maximum number of connections that can be allocated by the pool at a given
180                 * time. Use a negative value for no limit.
181                 */
182                private int maxActive = 8;
183
184                /**
185                 * Maximum amount of time a connection allocation should block before throwing an
186                 * exception when the pool is exhausted. Use a negative value to block
187                 * indefinitely.
188                 */
189                private Duration maxWait = Duration.ofMillis(-1);
190
191                public int getMaxIdle() {
192                        return this.maxIdle;
193                }
194
195                public void setMaxIdle(int maxIdle) {
196                        this.maxIdle = maxIdle;
197                }
198
199                public int getMinIdle() {
200                        return this.minIdle;
201                }
202
203                public void setMinIdle(int minIdle) {
204                        this.minIdle = minIdle;
205                }
206
207                public int getMaxActive() {
208                        return this.maxActive;
209                }
210
211                public void setMaxActive(int maxActive) {
212                        this.maxActive = maxActive;
213                }
214
215                public Duration getMaxWait() {
216                        return this.maxWait;
217                }
218
219                public void setMaxWait(Duration maxWait) {
220                        this.maxWait = maxWait;
221                }
222
223        }
224
225        /**
226         * Cluster properties.
227         */
228        public static class Cluster {
229
230                /**
231                 * Comma-separated list of "host:port" pairs to bootstrap from. This represents an
232                 * "initial" list of cluster nodes and is required to have at least one entry.
233                 */
234                private List<String> nodes;
235
236                /**
237                 * Maximum number of redirects to follow when executing commands across the
238                 * cluster.
239                 */
240                private Integer maxRedirects;
241
242                public List<String> getNodes() {
243                        return this.nodes;
244                }
245
246                public void setNodes(List<String> nodes) {
247                        this.nodes = nodes;
248                }
249
250                public Integer getMaxRedirects() {
251                        return this.maxRedirects;
252                }
253
254                public void setMaxRedirects(Integer maxRedirects) {
255                        this.maxRedirects = maxRedirects;
256                }
257
258        }
259
260        /**
261         * Redis sentinel properties.
262         */
263        public static class Sentinel {
264
265                /**
266                 * Name of the Redis server.
267                 */
268                private String master;
269
270                /**
271                 * Comma-separated list of "host:port" pairs.
272                 */
273                private List<String> nodes;
274
275                public String getMaster() {
276                        return this.master;
277                }
278
279                public void setMaster(String master) {
280                        this.master = master;
281                }
282
283                public List<String> getNodes() {
284                        return this.nodes;
285                }
286
287                public void setNodes(List<String> nodes) {
288                        this.nodes = nodes;
289                }
290
291        }
292
293        /**
294         * Jedis client properties.
295         */
296        public static class Jedis {
297
298                /**
299                 * Jedis pool configuration.
300                 */
301                private Pool pool;
302
303                public Pool getPool() {
304                        return this.pool;
305                }
306
307                public void setPool(Pool pool) {
308                        this.pool = pool;
309                }
310
311        }
312
313        /**
314         * Lettuce client properties.
315         */
316        public static class Lettuce {
317
318                /**
319                 * Shutdown timeout.
320                 */
321                private Duration shutdownTimeout = Duration.ofMillis(100);
322
323                /**
324                 * Lettuce pool configuration.
325                 */
326                private Pool pool;
327
328                public Duration getShutdownTimeout() {
329                        return this.shutdownTimeout;
330                }
331
332                public void setShutdownTimeout(Duration shutdownTimeout) {
333                        this.shutdownTimeout = shutdownTimeout;
334                }
335
336                public Pool getPool() {
337                        return this.pool;
338                }
339
340                public void setPool(Pool pool) {
341                        this.pool = pool;
342                }
343
344        }
345
346}