1,spring Configuration
<bean id= "Jedispoolconfig" class= "Redis.clients.jedis.JedisPoolConfig" >
<!--control how many Jedis instances a pool can allocate--
<property name= "Maxtotal" value= "${redis.maxtotal}"/>
<!--controls the maximum number of Jedis instances in a pool that have a status of idle (idle)--
<property name= "Maxidle" value= "${redis.maxidle}"/>
<property name= "Minidle" value= "${redis.minidle}"/>
<!--indicates that when borrow a Jedis instance, the maximum wait time, if the wait time is exceeded, is thrown directly jedisconnectionexception--
<property name= "Maxwaitmillis" value= "${redis.maxwaitmillis}"/>
<!--whether validate operations are performed in advance when borrow an Jedis instance, and if true, the resulting Jedis instance is available--
<property name= "Testonborrow" value= "${redis.testonborrow}"/>
<property name= "Testonreturn" value= "${redis.testonreturn}"/>
<property name= "Testwhileidle" value= "${redis.testwhileidle}"/>
</bean>
<!--Redis connection pool pools, not required: Timeout/password--
<bean id = "Jedispool" class= "Redis.clients.jedis.JedisPool" >
<constructor-arg index= "0" ref= "jedispoolconfig"/>
<constructor-arg index= "1" value= "${redis.host}"/>
<constructor-arg index= "2" value= "${redis.port}" type= "int"/>
<constructor-arg index= "3" value= "${redis.timeout}" type= "int"/>
<constructor-arg index= "4" value= "${redis.password}"/>
</bean>
2, using
Jedis Redis = Jedispool.getresource ();
Redis.hset ("test002", "Pos2", "002");
Attention:
1, in order for the client to access the Redis in a password way, you need to configure the Dongdong
A: Locate the redis.conf configuration file,
Where, attributes,
Requirepass Password # Configuration Redis Password for connection
B: Run the client, performing the following 2 commands, respectively:
CONFIG SET requirepass "Password"
AUTH "Password"
C: Later, each time the client connects, run the REDIS-CLI command, you need to execute the command first
AUTH "Password"
In order to continue the subsequent operation
2, in addition, common configuration options
Daemonize Yes # Redis whether the next process runs
AppendOnly Yes #是否启用aof日志
Redis2.8 integrated configuration of single Redis Jedispool with spring