RedisDS

Redis Client Encapsulation - RedisDS

Introduction

RedisDS is based on Jedis encapsulation and requires the Jedis dependency to be introduced separately.

Usage

Introducing Dependencies

<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
	<version>3.7.0</version>
</dependency>

Configuration

Create a redis.setting file in the config directory under the ClassPath (or src/main/resources):

#-------------------------------------------------------------------------------
# Redis client configuration sample
# Each group represents a Redis instance
# The ungrouped Pool configuration is the shared configuration for all groups. If a group defines its own Pool configuration, it overrides the shared configuration.
# Pool configuration from: https://www.cnblogs.com/jklk/p/7095067.html
#-------------------------------------------------------------------------------

#----- Default (public) configuration
# Address, default localhost
host = localhost
# Port, default 6379
port = 6379
# Timeout, default 2000
timeout = 2000
# Connection timeout, default timeout
connectionTimeout = 2000
# Read timeout, default timeout
soTimeout = 2000
# Password, default none
password = 
# Database index, default 0
database = 0
# Client name, default "Hutool"
clientName = Hutool
# SSL connection, default false
ssl = false;

#----- Custom group connection
[custom]
# Address, default localhost
host = localhost
# Whether to block when exhausted, false for exception, true for blocking until timeout, default true
BlockWhenExhausted = true;
# Set the name of the eviction policy class, default DefaultEvictionPolicy (when the connection exceeds the maximum idle time or the number of connections exceeds the maximum idle connections)
evictionPolicyClassName = org.apache.commons.pool2.impl.DefaultEvictionPolicy
# Whether to enable JMX management function of the pool, default true
jmxEnabled = true;
# Whether to enable LIFO, default true
lifo = true;
# Maximum idle connections, default 8
maxIdle = 8
# Minimum idle connections, default 0
minIdle = 0
# Maximum connections, default 8
maxTotal = 8
# Maximum wait time in milliseconds when getting a connection (if set to block when exhausted), if it exceeds the timeout, an exception is thrown. Less than zero: block for an indeterminate amount of time, default -1.
maxWaitMillis = -1;
# Minimum idle time before eviction in milliseconds, default 1800000 milliseconds (30 minutes)
minEvictableIdleTimeMillis = 1800000;
# The maximum number of evictions to check each time an eviction run is performed. If negative, it is 1/abs(n), default 3.
numTestsPerEvictionRun = 3;
# How long an object can be idle before eviction. When the idle time is greater than this value and the number of idle connections is greater than the maximum number of idle connections, it will be evicted directly without further judgment based on MinEvictableIdleTimeMillis (default eviction policy).
SoftMinEvictableIdleTimeMillis = 1800000;
# Check validity when getting a connection, default false.
testOnBorrow = false;
# Check validity when idle, default false.
testWhileIdle = false;
# Time interval between eviction scans in milliseconds. If negative, the eviction thread will not run, default -1.
timeBetweenEvictionRunsMillis = -1;

Usage

Jedis jedis = RedisDS.create().getJedis();