Files
doc-exports/docs/dcs/umn/dcs-ug-0713005.html
Chen, Junjie 2b90aa9fff DCS UMN 20240313 version
Reviewed-by: Mützel, Andrea <andrea.muetzel@t-systems.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
2024-04-10 14:46:00 +00:00

532 lines
39 KiB
HTML

<a name="dcs-ug-0713005"></a><a name="dcs-ug-0713005"></a>
<h1 class="topictitle1">Jedis</h1>
<div id="body8662426"><p id="dcs-ug-0713005__en-us_topic_0148195198_p1484772321512"><span class="keyword" id="dcs-ug-0713005__en-us_topic_0148195198_keyword1962119547578">Access a DCS Redis instance through Jedis</span> on an ECS in the same VPC. For more information about how to use other Redis clients, visit <a href="https://redis.io/clients" target="_blank" rel="noopener noreferrer">the Redis official website</a>.</p>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p1563285635914">Spring Data Redis is already integrated with <a href="https://github.com/redis/jedis" target="_blank" rel="noopener noreferrer">Jedis</a> and <a href="https://github.com/lettuce-io/lettuce-core" target="_blank" rel="noopener noreferrer">Lettuce</a> for Spring Boot projects. Spring Boot 1.x is integrated with Jedis, and Spring Boot 2.x is integrated with Lettuce. To use Jedis in Spring Boot 2.x and later, you need to solve Lettuce dependency conflicts.</p>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section1502270695932"><h4 class="sectiontitle">Prerequisites</h4><ul id="dcs-ug-0713005__en-us_topic_0148195198_ul46828691102415"><li id="dcs-ug-0713005__en-us_topic_0148195198_li7215915117">A DCS Redis instance has been created and is in the <strong id="dcs-ug-0713005__en-us_topic_0148195198_b618817912244">Running</strong> state.</li><li id="dcs-ug-0713005__en-us_topic_0148195198_li214620143217">View the IP address/domain name and port number of the DCS Redis instance to be accessed.<p id="dcs-ug-0713005__en-us_topic_0148195198_p314651418212"><a name="dcs-ug-0713005__en-us_topic_0148195198_li214620143217"></a><a name="en-us_topic_0148195198_li214620143217"></a>For details, see <a href="dcs-ug-0312016.html">Viewing Details of a DCS Instance</a>.</p>
</li><li id="dcs-ug-0713005__en-us_topic_0148195198_li34386431426">An ECS has been created. For details about how to create an ECS, see the <a href="https://docs.otc.t-systems.com/en-us/usermanual/ecs/en-us_topic_0163572588.html" target="_blank" rel="noopener noreferrer"><em id="dcs-ug-0713005__en-us_topic_0148195198_i2648730165116">Elastic Cloud Server User Guide</em></a>.</li><li id="dcs-ug-0713005__en-us_topic_0148195198_li152161914112">If the ECS runs the Linux OS, ensure that the Java compilation environment has been installed on the ECS.</li></ul>
</div>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section4771195210217"><h4 class="sectiontitle">Pom Configuration</h4><pre class="screen" id="dcs-ug-0713005__en-us_topic_0148195198_screen1444712164">&lt;!-- import spring-data-redis --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt;
&lt;!--In Spring Boot 2.0, Lettuce is used by default. To use Jedis, solve dependency conflicts.--&gt;
&lt;exclusions&gt;
&lt;exclusion&gt;
&lt;groupId&gt;io.lettuce&lt;/groupId&gt;
&lt;artifactId&gt;lettuce-core&lt;/artifactId&gt;
&lt;/exclusion&gt;
&lt;/exclusions&gt;
&lt;/dependency&gt;
&lt;!--Jedis dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;redis.clients&lt;/groupId&gt;
&lt;artifactId&gt;jedis&lt;/artifactId&gt;
&lt;version&gt;3.10.0&lt;/version&gt;
&lt;/dependency&gt;</pre>
</div>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section3175173816130"><h4 class="sectiontitle">application.properties Configuration</h4><ul id="dcs-ug-0713005__en-us_topic_0148195198_ul171428613142"><li id="dcs-ug-0713005__en-us_topic_0148195198_li91422069145">Single-node, master/standby, and Proxy Cluster<pre class="screen" id="dcs-ug-0713005__en-us_topic_0148195198_screen037375315314">#Redis host
spring.redis.host=&lt;host&gt;
#Redis port
spring.redis.port=&lt;port&gt;
#Redis database number
spring.redis.database=0
#Redis password
spring.redis.password=&lt;password&gt;
#Redis read/write timeout
spring.redis.timeout=2000
#Whether to enable connection pooling
spring.redis.jedis.pool.enabled=true
#Minimum connections in the pool
spring.redis.jedis.pool.min-idle=50
#Maximum idle connections in the pool
spring.redis.jedis.pool.max-idle=200
#Maximum connections in the pool
spring.redis.jedis.pool.max-active=200
#Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. The default value -1 indicates to wait indefinitely.
spring.redis.jedis.pool.max-wait=3000
#Interval for checking and evicting idle connection. Default: 60s.
spring.redis.jedis.pool.time-between-eviction-runs=60S</pre>
</li><li id="dcs-ug-0713005__en-us_topic_0148195198_li108863001419">Redis Cluster<pre class="screen" id="dcs-ug-0713005__en-us_topic_0148195198_screen176823411158">#Redis Cluster node connection information
spring.redis.cluster.nodes=&lt;ip:port&gt;,&lt;ip:port&gt;,&lt;ip:port&gt;
#Redis Cluster password
spring.redis.password=&lt;password&gt;
#Redis Cluster max. redirecting times
spring.redis.cluster.max-redirects=3
#Redis read/write timeout
spring.redis.timeout=2000
#Whether to enable connection pooling
spring.redis.jedis.pool.enabled=true
#Minimum connections in the pool
spring.redis.jedis.pool.min-idle=50
#Maximum idle connections in the pool
spring.redis.jedis.pool.max-idle=200
#Maximum connections in the pool
spring.redis.jedis.pool.max-active=200
#Maximum amount of time a connection allocation should block before throwing an exception when the pool is exhausted. The default value -1 indicates to wait indefinitely.
spring.redis.jedis.pool.max-wait=3000
#Interval for checking and evicting idle connections. Default: 60s.
spring.redis.jedis.pool.time-between-eviction-runs=60S</pre>
</li></ul>
</div>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section12244191616"><a name="dcs-ug-0713005__en-us_topic_0148195198_section12244191616"></a><a name="en-us_topic_0148195198_section12244191616"></a><h4 class="sectiontitle">Bean Configuration</h4><ul id="dcs-ug-0713005__en-us_topic_0148195198_ul20670155513168"><li id="dcs-ug-0713005__en-us_topic_0148195198_li1867025531618">Single-node, master/standby, and Proxy Cluster<pre class="screen" id="dcs-ug-0713005__en-us_topic_0148195198_screen1367011553161">import java.time.Duration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import redis.clients.jedis.JedisPoolConfig;
@Configuration
public class RedisConfiguration {
@Value("${redis.host}")
private String redisHost;
@Value("${redis.port:6379}")
private Integer redisPort = 6379;
@Value("${redis.database:0}")
private Integer redisDatabase = 0;
@Value("${redis.password:}")
private String redisPassword;
@Value("${redis.connect.timeout:3000}")
private Integer redisConnectTimeout = 3000;
@Value("${redis.read.timeout:2000}")
private Integer redisReadTimeout = 2000;
@Value("${redis.pool.minSize:50}")
private Integer redisPoolMinSize = 50;
@Value("${redis.pool.maxSize:200}")
private Integer redisPoolMaxSize = 200;
@Value("${redis.pool.maxWaitMillis:3000}")
private Integer redisPoolMaxWaitMillis = 3000;
@Value("${redis.pool.softMinEvictableIdleTimeMillis:1800000}")
private Integer redisPoolSoftMinEvictableIdleTimeMillis = 30 * 60 * 1000;
@Value("${redis.pool.timeBetweenEvictionRunsMillis:60000}")
private Integer redisPoolBetweenEvictionRunsMillis = 60 * 1000;
@Bean
public RedisConnectionFactory redisConnectionFactory(JedisClientConfiguration clientConfiguration) {
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration();
standaloneConfiguration.setHostName(redisHost);
standaloneConfiguration.setPort(redisPort);
standaloneConfiguration.setDatabase(redisDatabase);
standaloneConfiguration.setPassword(redisPassword);
return new JedisConnectionFactory(standaloneConfiguration, clientConfiguration);
}
@Bean
public JedisClientConfiguration clientConfiguration() {
JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder()
.connectTimeout(Duration.ofMillis(redisConnectTimeout))
.readTimeout(Duration.ofMillis(redisReadTimeout))
.usePooling().poolConfig(redisPoolConfig())
.build();
return clientConfiguration;
}
private JedisPoolConfig redisPoolConfig() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
//Minimum connections in the pool
poolConfig.setMinIdle(redisPoolMinSize);
//Maximum idle connections in the pool
poolConfig.setMaxIdle(redisPoolMaxSize);
//Maximum total connections in the pool
poolConfig.setMaxTotal(redisPoolMaxSize);
//Wait when pool is exhausted? Set to true to wait. To validate setMaxWait, it has to be true.
poolConfig.setBlockWhenExhausted(true);
//Longest time to wait for connection after pool is exhausted. The default value -1 indicates to wait indefinitely.
poolConfig.setMaxWaitMillis(redisPoolMaxWaitMillis);
//Set to true to enable connectivity test on creating connections. Default: false.
poolConfig.setTestOnCreate(false);
//Set to true to enable connectivity test on borrowing connections. Default: false. Set to false for heavy-traffic services to reduce overhead.
poolConfig.setTestOnBorrow(true);
//Set to true to enable connectivity test on returning connections. Default: false. Set to false for heavy-traffic services to reduce overhead.
poolConfig.setTestOnReturn(false);
//Indicates whether to check for idle connections. If this is set to false, idle connections are not evicted.
poolConfig.setTestWhileIdle(true);
//Duration after which idle connections are evicted. If the idle duration is greater than this value and the maximum number of idle connections is reached, idle connections are directly evicted.
poolConfig.setSoftMinEvictableIdleTimeMillis(redisPoolSoftMinEvictableIdleTimeMillis);
//Disable MinEvictableIdleTimeMillis().
poolConfig.setMinEvictableIdleTimeMillis(-1);
//Interval for checking and evicting idle connections. Default: 60s.
poolConfig.setTimeBetweenEvictionRunsMillis(redisPoolBetweenEvictionRunsMillis);
return poolConfig;
}
}</pre>
</li><li id="dcs-ug-0713005__en-us_topic_0148195198_li11670105581616">Redis Cluster<pre class="screen" id="dcs-ug-0713005__en-us_topic_0148195198_screen367185541616">import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import redis.clients.jedis.JedisPoolConfig;
@Configuration
public class RedisConfiguration {
@Value("${redis.cluster.nodes}")
private String redisClusterNodes;
@Value("${redis.password:}")
private String redisPassword;
@Value("${redis.connect.timeout:3000}")
private Integer redisConnectTimeout = 3000;
@Value("${redis.read.timeout:2000}")
private Integer redisReadTimeout = 2000;
@Value("${redis.pool.minSize:50}")
private Integer redisPoolMinSize = 50;
@Value("${redis.pool.maxSize:200}")
private Integer redisPoolMaxSize = 200;
@Value("${redis.pool.maxWaitMillis:3000}")
private Integer redisPoolMaxWaitMillis = 3000;
@Value("${redis.pool.softMinEvictableIdleTimeMillis:1800000}")
private Integer redisPoolSoftMinEvictableIdleTimeMillis = 30 * 60 * 1000;
@Value("${redis.pool.timeBetweenEvictionRunsMillis:60000}")
private Integer redisPoolBetweenEvictionRunsMillis = 60 * 1000;
@Bean
public RedisConnectionFactory redisConnectionFactory(JedisClientConfiguration clientConfiguration) {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
List&lt;RedisNode&gt; clusterNodes = new ArrayList&lt;&gt;();
for (String clusterNodeStr : redisClusterNodes.split(",")) {
String[] nodeInfo = clusterNodeStr.split(":");
clusterNodes.add(new RedisNode(nodeInfo[0], Integer.valueOf(nodeInfo[1])));
}
clusterConfiguration.setClusterNodes(clusterNodes);
clusterConfiguration.setPassword(redisPassword);
clusterConfiguration.setMaxRedirects(3);
return new JedisConnectionFactory(clusterConfiguration, clientConfiguration);
}
@Bean
public JedisClientConfiguration clientConfiguration() {
JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder()
.connectTimeout(Duration.ofMillis(redisConnectTimeout))
.readTimeout(Duration.ofMillis(redisReadTimeout))
.usePooling().poolConfig(redisPoolConfig())
.build();
return clientConfiguration;
}
private JedisPoolConfig redisPoolConfig() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
//Minimum connections in the pool
poolConfig.setMinIdle(redisPoolMinSize);
//Maximum idle connections in the pool
poolConfig.setMaxIdle(redisPoolMaxSize);
//Maximum total connections in the pool
poolConfig.setMaxTotal(redisPoolMaxSize);
//Wait when pool is exhausted? Set to true to wait. To validate setMaxWait, it has to be true.
poolConfig.setBlockWhenExhausted(true);
//Longest time to wait for connection after pool is exhausted. The default value -1 indicates to wait indefinitely.
poolConfig.setMaxWaitMillis(redisPoolMaxWaitMillis);
//Set to true to enable connectivity test on creating connections. Default: false.
poolConfig.setTestOnCreate(false);
//Set to true to enable connectivity test on borrowing connections. Default: false. Set to false for heavy-traffic services to reduce overhead.
poolConfig.setTestOnBorrow(true);
//Set to true to enable connectivity test on returning connections. Default: false. Set to false for heavy-traffic services to reduce overhead.
poolConfig.setTestOnReturn(false);
//Indicates whether to check for idle connections. If this is set to false, idle connections are not evicted.
poolConfig.setTestWhileIdle(true);
//Duration after which idle connections are evicted. If the idle duration is greater than this value and the maximum number of idle connections is reached, idle connections are directly evicted.
poolConfig.setSoftMinEvictableIdleTimeMillis(redisPoolSoftMinEvictableIdleTimeMillis);
//Disable MinEvictableIdleTimeMillis().
poolConfig.setMinEvictableIdleTimeMillis(-1);
//Interval for checking and evicting idle connections. Default: 60s.
poolConfig.setTimeBetweenEvictionRunsMillis(redisPoolBetweenEvictionRunsMillis);
return poolConfig;
}
}</pre>
</li></ul>
</div>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section197189558496"><h4 class="sectiontitle">(Optional) Configuring SSL Connections</h4><p id="dcs-ug-0713005__en-us_topic_0148195198_p0199852509">If SSL is enabled for the instance, use the following content to replace the JedisClientConfiguration construction method clientConfiguration() in <a href="#dcs-ug-0713005__en-us_topic_0148195198_section12244191616">Bean Configuration</a> for connecting to the instance with SSL. For details about whether your DCS Redis instances support SSL, see <a href="dcs-ug-023129.html">Configuring SSL</a>.</p>
<pre class="screen" id="dcs-ug-0713005__en-us_topic_0148195198_screen1951072415317">@Bean
public JedisClientConfiguration clientConfiguration() throws Exception {
JedisClientConfiguration.JedisClientConfigurationBuilder configurationBuilder
= JedisClientConfiguration.builder()
.connectTimeout(Duration.ofMillis(redisConnectTimeout))
.readTimeout(Duration.ofMillis(redisReadTimeout));
configurationBuilder.usePooling().poolConfig(redisPoolConfig());
configurationBuilder.useSsl().sslSocketFactory(getTrustStoreSslSocketFactory());
return configurationBuilder.build();
}
private SSLSocketFactory getTrustStoreSslSocketFactory() throws Exception{
//Load the CA certificate in the user-defined path based on service requirements.
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate ca;
try (InputStream is = new FileInputStream("./ca.crt")) {
ca = cf.generateCertificate(is);
}
//Create keystore.
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
//Create TrustManager.
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
//Create SSLContext.
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());
return context.getSocketFactory();
}</pre>
</div>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section1579822471716"><h4 class="sectiontitle">Parameter Description</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dcs-ug-0713005__en-us_topic_0148195198_table16401346121714" frame="border" border="1" rules="all"><caption><b>Table 1 </b>RedisStandaloneConfiguration parameters</caption><thead align="left"><tr id="dcs-ug-0713005__en-us_topic_0148195198_row14640164641710"><th align="left" class="cellrowborder" valign="top" width="22.41224122412241%" id="mcps1.3.8.2.2.4.1.1"><p id="dcs-ug-0713005__en-us_topic_0148195198_p26404465175">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="19.18191819181918%" id="mcps1.3.8.2.2.4.1.2"><p id="dcs-ug-0713005__en-us_topic_0148195198_p11640946171714">Default Value</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="58.405840584058396%" id="mcps1.3.8.2.2.4.1.3"><p id="dcs-ug-0713005__en-us_topic_0148195198_p106408468176">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dcs-ug-0713005__en-us_topic_0148195198_row964012462171"><td class="cellrowborder" valign="top" width="22.41224122412241%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1064034618177">hostName</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1928085120181">localhost</p>
</td>
<td class="cellrowborder" valign="top" width="58.405840584058396%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p5640246171718">IP address/domain name for connecting to a DCS Redis instance</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row1764044661719"><td class="cellrowborder" valign="top" width="22.41224122412241%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p16640446161713">port</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1664020467171">6379</p>
</td>
<td class="cellrowborder" valign="top" width="58.405840584058396%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1964124691715">Port number</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row5641134612173"><td class="cellrowborder" valign="top" width="22.41224122412241%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p196411446111716">database</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p18641346111714">0</p>
</td>
<td class="cellrowborder" valign="top" width="58.405840584058396%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p10641124681711">Database number. Default: 0.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row864144681718"><td class="cellrowborder" valign="top" width="22.41224122412241%" headers="mcps1.3.8.2.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p13641154621716">password</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.2.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p764184618172">-</p>
</td>
<td class="cellrowborder" valign="top" width="58.405840584058396%" headers="mcps1.3.8.2.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p146411346201718">Password</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dcs-ug-0713005__en-us_topic_0148195198_table1692805132314" frame="border" border="1" rules="all"><caption><b>Table 2 </b>RedisClusterConfiguration parameters</caption><thead align="left"><tr id="dcs-ug-0713005__en-us_topic_0148195198_row49291453233"><th align="left" class="cellrowborder" valign="top" width="22.189999999999998%" id="mcps1.3.8.3.2.3.1.1"><p id="dcs-ug-0713005__en-us_topic_0148195198_p1188843212315">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="77.81%" id="mcps1.3.8.3.2.3.1.2"><p id="dcs-ug-0713005__en-us_topic_0148195198_p1188873218236">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dcs-ug-0713005__en-us_topic_0148195198_row99291753239"><td class="cellrowborder" valign="top" width="22.189999999999998%" headers="mcps1.3.8.3.2.3.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p392955132315">clusterNodes</p>
</td>
<td class="cellrowborder" valign="top" width="77.81%" headers="mcps1.3.8.3.2.3.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1292912532316">Cluster node connection information, including the node IP address and port number</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row14929165192319"><td class="cellrowborder" valign="top" width="22.189999999999998%" headers="mcps1.3.8.3.2.3.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p4929558239">maxRedirects</p>
</td>
<td class="cellrowborder" valign="top" width="77.81%" headers="mcps1.3.8.3.2.3.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1092918572317">Maximum redirecting times</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row492915520235"><td class="cellrowborder" valign="top" width="22.189999999999998%" headers="mcps1.3.8.3.2.3.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p22421838182414">password</p>
</td>
<td class="cellrowborder" valign="top" width="77.81%" headers="mcps1.3.8.3.2.3.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p248214432417">Password</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="tablenoborder"><a name="dcs-ug-0713005__en-us_topic_0148195198_table1153832317251"></a><a name="en-us_topic_0148195198_table1153832317251"></a><table cellpadding="4" cellspacing="0" summary="" id="dcs-ug-0713005__en-us_topic_0148195198_table1153832317251" frame="border" border="1" rules="all"><caption><b>Table 3 </b>JedisPoolConfig parameters</caption><thead align="left"><tr id="dcs-ug-0713005__en-us_topic_0148195198_row3538122319251"><th align="left" class="cellrowborder" valign="top" width="22.55225522552255%" id="mcps1.3.8.4.2.4.1.1"><p id="dcs-ug-0713005__en-us_topic_0148195198_p12525103512511">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="18.751875187518753%" id="mcps1.3.8.4.2.4.1.2"><p id="dcs-ug-0713005__en-us_topic_0148195198_p652563516251">Default Value</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="58.69586958695869%" id="mcps1.3.8.4.2.4.1.3"><p id="dcs-ug-0713005__en-us_topic_0148195198_p19525435182512">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dcs-ug-0713005__en-us_topic_0148195198_row4538172311255"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p14539152372515">minIdle</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p165393236258">-</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p153982315251">Minimum connections in the connection pool</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row14539923172511"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1553932313259">maxIdle</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p20539102392512">-</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p15539132312258">Maximum idle connections in the connection pool</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row1053932317258"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p153982352514">maxTotal</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p553942382512">-</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1853982314258">Maximum total connections in the connection pool</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row1853910232259"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1753972314258">blockWhenExhausted</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p0539823192514">true</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p16539923202510">Indicates whether to wait after the connection pool is exhausted. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b0688125253318">true</strong>: Wait. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b7637203103418">false</strong>: Do not wait. To validate <strong id="dcs-ug-0713005__en-us_topic_0148195198_b1505332153410">maxWaitMillis</strong>, this parameter must be set to <strong id="dcs-ug-0713005__en-us_topic_0148195198_b0984144023419">true</strong>.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row9539142342516"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p4539122392516">maxWaitMillis</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p135390231259">-1</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p453952316251">Maximum amount of time (in milliseconds) to wait for connection after the connection pool is exhausted. The default value <strong id="dcs-ug-0713005__en-us_topic_0148195198_b1788810816353">-1</strong> indicates to wait indefinitely.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row135391223172515"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p13539202317251">testOnCreate</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1953972302519">false</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p25390232254">Indicates whether to enable connectivity test on creating connections. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b4402516123918">false</strong>: Disable. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b14426163343916">true</strong>: Enable.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row155404235253"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p16540723162511">testOnBorrow</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p14540142352510">false</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1354012230258">Indicates whether to enable connectivity test on obtaining connections. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b16685102124015">false</strong>: Disable. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b11686223404">true</strong>: Enable. For heavy-traffic services, set this parameter to <strong id="dcs-ug-0713005__en-us_topic_0148195198_b71415299402">false</strong> to reduce overhead.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row54412213281"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p14522220280">testOnReturn</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p104514226288">false</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p74542220287">Indicates whether to enable connectivity test on returning connections. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b6328250134013">false</strong>: Disable. <strong id="dcs-ug-0713005__en-us_topic_0148195198_b23280504402">true</strong>: Enable. For heavy-traffic services, set this parameter to <strong id="dcs-ug-0713005__en-us_topic_0148195198_b1514835574011">false</strong> to reduce overhead.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row11261925152815"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p2012662532814">testWhileIdle</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p5126625162819">false</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1012622522814">Indicates whether to check for idle connections. If this parameter is set to <strong id="dcs-ug-0713005__en-us_topic_0148195198_b1350475064211">false</strong>, idle connections are not evicted. Recommended value: <strong id="dcs-ug-0713005__en-us_topic_0148195198_b59010587426">true</strong>.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row1081813217289"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p128188321283">softMinEvictableIdleTimeMillis</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1481823218282">1800000</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p128181032112817">Duration (in milliseconds) after which idle connections are evicted. If the idle duration is greater than this value and the maximum number of idle connections is reached, idle connections are directly evicted.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row310620335284"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p18106183392810">minEvictableIdleTimeMillis</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1310743314288">60000</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p110783316286">Minimum amount of time (in milliseconds) a connection may remain idle in the pool before it is eligible for eviction. The recommended value is <strong id="dcs-ug-0713005__en-us_topic_0148195198_b117061026114520">-1</strong>, indicating that <strong id="dcs-ug-0713005__en-us_topic_0148195198_b14555612114615">softMinEvictableIdleTimeMillis</strong> is used instead.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row93734330285"><td class="cellrowborder" valign="top" width="22.55225522552255%" headers="mcps1.3.8.4.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p73731330282">timeBetweenEvictionRunsMillis</p>
</td>
<td class="cellrowborder" valign="top" width="18.751875187518753%" headers="mcps1.3.8.4.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p17373203322814">60000</p>
</td>
<td class="cellrowborder" valign="top" width="58.69586958695869%" headers="mcps1.3.8.4.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p53748332282">Interval (in milliseconds) for checking and evicting idle connections.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dcs-ug-0713005__en-us_topic_0148195198_table01247207364" frame="border" border="1" rules="all"><caption><b>Table 4 </b>JedisClientConfiguration parameters</caption><thead align="left"><tr id="dcs-ug-0713005__en-us_topic_0148195198_row712412017365"><th align="left" class="cellrowborder" valign="top" width="22.492249224922492%" id="mcps1.3.8.5.2.4.1.1"><p id="dcs-ug-0713005__en-us_topic_0148195198_p1767103514363">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="19.18191819181918%" id="mcps1.3.8.5.2.4.1.2"><p id="dcs-ug-0713005__en-us_topic_0148195198_p13767133573616">Default Value</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="58.32583258325833%" id="mcps1.3.8.5.2.4.1.3"><p id="dcs-ug-0713005__en-us_topic_0148195198_p1076743510369">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dcs-ug-0713005__en-us_topic_0148195198_row14125172083619"><td class="cellrowborder" valign="top" width="22.492249224922492%" headers="mcps1.3.8.5.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p31251120203617">connectTimeout</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.5.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p14125182023610">2000</p>
</td>
<td class="cellrowborder" valign="top" width="58.32583258325833%" headers="mcps1.3.8.5.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p612512013364">Connection timeout interval, in milliseconds.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row912542015362"><td class="cellrowborder" valign="top" width="22.492249224922492%" headers="mcps1.3.8.5.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p812592018367">readTimeout</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.5.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p1012519208369">2000</p>
</td>
<td class="cellrowborder" valign="top" width="58.32583258325833%" headers="mcps1.3.8.5.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p18125122063619">Timeout interval for waiting for a response, in milliseconds.</p>
</td>
</tr>
<tr id="dcs-ug-0713005__en-us_topic_0148195198_row5177162523613"><td class="cellrowborder" valign="top" width="22.492249224922492%" headers="mcps1.3.8.5.2.4.1.1 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p71771525183617">poolConfig</p>
</td>
<td class="cellrowborder" valign="top" width="19.18191819181918%" headers="mcps1.3.8.5.2.4.1.2 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p161771625203615">-</p>
</td>
<td class="cellrowborder" valign="top" width="58.32583258325833%" headers="mcps1.3.8.5.2.4.1.3 "><p id="dcs-ug-0713005__en-us_topic_0148195198_p10177142573611">Pool configurations. For details, see <a href="#dcs-ug-0713005__en-us_topic_0148195198_table1153832317251">JedisPoolConfig</a>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dcs-ug-0713005__en-us_topic_0148195198_section158230372383"><h4 class="sectiontitle">Suggestion for Configuring DCS Instances</h4><ul id="dcs-ug-0713005__en-us_topic_0148195198_ul9588659439"><li id="dcs-ug-0713005__en-us_topic_0148195198_li258995184317">Connection pool configuration<div class="note" id="dcs-ug-0713005__en-us_topic_0148195198_note9553151614412"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dcs-ug-0713005__en-us_topic_0148195198_p955371615418">The following calculation is applicable only to common service scenarios. You can customize it based on your service requirements.</p>
</div></div>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p2070416813403">There is no standard connection pool size. You can configure one based on your service traffic. The following formulas are for reference:</p>
<ul id="dcs-ug-0713005__en-us_topic_0148195198_ul1716981813454"><li id="dcs-ug-0713005__en-us_topic_0148195198_li41701918104516">Minimum number of connections = (QPS of a single node accessing Redis)/(1000 ms/Average time spent on a single command)</li><li id="dcs-ug-0713005__en-us_topic_0148195198_li1417081844519">Maximum number of connections = (QPS of a single node accessing Redis)/(1000 ms/Average time spent on a single command) x 150%</li></ul>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p1487102818408">For example, if the QPS of a service application is about 10,000, each request needs to access Redis 10 times (that is, 100,000 accesses to Redis every second), and the service application has 10 hosts, the calculation is as follows:</p>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p16996203474019">QPS of a single node accessing Redis = 100,000/10 = 10,000</p>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p5219193815403">Average time spent on a single command = 20 ms (Redis takes 5 ms to 10 ms to process a single command under normal conditions. If network jitter occurs, it takes 15 ms to 20 ms.)</p>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p5838194274018">Minimum number of connections = 10,000/(1000 ms/20 ms) = 200</p>
<p id="dcs-ug-0713005__en-us_topic_0148195198_p13808204614020">Maximum number of connections = 10,000/(1000 ms/20 ms) x 150% = 300</p>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dcs-ug-211105003.html">Java</a></div>
</div>
</div>