View Javadoc
1   /*
2    *    Copyright 2015-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.caches.redis;
17  
18  import javax.net.ssl.HostnameVerifier;
19  import javax.net.ssl.SSLParameters;
20  import javax.net.ssl.SSLSocketFactory;
21  
22  import redis.clients.jedis.JedisPoolConfig;
23  import redis.clients.jedis.Protocol;
24  
25  public class RedisConfig extends JedisPoolConfig {
26  
27    private String host = Protocol.DEFAULT_HOST;
28    private int port = Protocol.DEFAULT_PORT;
29    private int connectionTimeout = Protocol.DEFAULT_TIMEOUT;
30    private int soTimeout = Protocol.DEFAULT_TIMEOUT;
31    private String password;
32    private int database = Protocol.DEFAULT_DATABASE;
33    private String clientName;
34    private boolean ssl;
35    private SSLSocketFactory sslSocketFactory;
36    private SSLParameters sslParameters;
37    private HostnameVerifier hostnameVerifier;
38    private Serializer serializer = JDKSerializer.INSTANCE;
39  
40    public boolean isSsl() {
41      return ssl;
42    }
43  
44    public void setSsl(boolean ssl) {
45      this.ssl = ssl;
46    }
47  
48    public SSLSocketFactory getSslSocketFactory() {
49      return sslSocketFactory;
50    }
51  
52    public void setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
53      this.sslSocketFactory = sslSocketFactory;
54    }
55  
56    public SSLParameters getSslParameters() {
57      return sslParameters;
58    }
59  
60    public void setSslParameters(SSLParameters sslParameters) {
61      this.sslParameters = sslParameters;
62    }
63  
64    public HostnameVerifier getHostnameVerifier() {
65      return hostnameVerifier;
66    }
67  
68    public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
69      this.hostnameVerifier = hostnameVerifier;
70    }
71  
72    public String getHost() {
73      return host;
74    }
75  
76    public void setHost(String host) {
77      if (host == null || host.isEmpty()) {
78        host = Protocol.DEFAULT_HOST;
79      }
80      this.host = host;
81    }
82  
83    public int getPort() {
84      return port;
85    }
86  
87    public void setPort(int port) {
88      this.port = port;
89    }
90  
91    public String getPassword() {
92      return password;
93    }
94  
95    public void setPassword(String password) {
96      if (password == null || password.isEmpty()) {
97        password = null;
98      }
99      this.password = password;
100   }
101 
102   public int getDatabase() {
103     return database;
104   }
105 
106   public void setDatabase(int database) {
107     this.database = database;
108   }
109 
110   public String getClientName() {
111     return clientName;
112   }
113 
114   public void setClientName(String clientName) {
115     if (clientName == null || clientName.isEmpty()) {
116       clientName = null;
117     }
118     this.clientName = clientName;
119   }
120 
121   public int getConnectionTimeout() {
122     return connectionTimeout;
123   }
124 
125   public void setConnectionTimeout(int connectionTimeout) {
126     this.connectionTimeout = connectionTimeout;
127   }
128 
129   public int getSoTimeout() {
130     return soTimeout;
131   }
132 
133   public void setSoTimeout(int soTimeout) {
134     this.soTimeout = soTimeout;
135   }
136 
137   public Serializer getSerializer() {
138     return serializer;
139   }
140 
141   public void setSerializer(Serializer serializer) {
142     this.serializer = serializer;
143   }
144 
145 }