Spring XML配置
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 最大空闲数 -->
<property name="maxIdle" value="600" />
<!-- 最大空连接数 -->
<property name="maxTotal" value="600" />
<!-- 最大等待时间 -->
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
<!-- 连接超时时是否阻塞,false时报异常,ture阻塞直到超时, 默认true -->
<property name="blockWhenExhausted" value="${redis.blockWhenExhausted}" />
<!-- 返回连接时,检测连接是否成功 -->
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<constructor-arg name="poolConfig" ref = "poolConfig"/>
<constructor-arg name="host" value = "127.0.0.1"/>
<constructor-arg name="port" value = "3976"/>
<constructor-arg name="timeout" value = "2000"/>
<constructor-arg name="password" value = ""/>
</bean>
Spring application.properties
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=20
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=1000
应用配置
*maxActive:最大连接数据库连接数,设 0 为没有限制
*maxIdle:最大等待连接中的数量,设 0 为没有限制
*maxWait:最大等待毫秒数, 单位为 ms, 超过时间会出错误信息
Redis服务key淘汰策略
noeviction: 不删除策略, 达到最大内存限制时, 如果需要更多内存, 直接返回错误信息。 大多数写命令都会导致占用更多的内存(有极少数会例外, 如 DEL )。
allkeys-lru: 所有key通用; 优先删除最近最少使用(less recently used ,LRU) 的 key。
volatile-lru: 只限于设置了 expire 的部分; 优先删除最近最少使用(less recently used ,LRU) 的 key。
allkeys-random: 所有key通用; 随机删除一部分 key。
volatile-random: 只限于设置了 expire 的部分; 随机删除一部分 key。
volatile-ttl: 只限于设置了 expire 的部分; 优先删除剩余时间(time to live,TTL) 短的key。
Redis服务端配置例子
daemonize yes
pidfile /var/run/redis.6379.pid
port 6379
timeout 300
tcp-keepalive 60
loglevel notice
logfile /data/redis/rd6379/log/redis.log
# syslog-enabled no
# syslog-ident redis
# syslog-facility local0
databases 16
# save ""
# save 900 1
# save 300 10
# save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/rd6379/datafile/
#slaveof ip 6379
#masterauth ..
slave-serve-stale-data yes
slave-read-only yes
# repl-ping-slave-period 10
repl-timeout 600
repl-disable-tcp-nodelay no
repl-backlog-size 64mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
requirepass woshimima
# rename-command CONFIG ""
maxclients 10000
maxmemory 8000000000
maxmemory-policy noeviction
# maxmemory-samples 3
appendonly yes
# appendfsync always
appendfsync everysec
# appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 20000
protected-mode no
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 8192mb 4096mb 600
client-output-buffer-limit pubsub 32mb 8mb 60
lazyfree-lazy-server-del yes
aof-rewrite-incremental-fsync yes









网友评论