linux 上操作:
redis-cli 链接
redis-cli -a password
也可以单独输入密码:
127.0.0.1:6379>auth d3bcc7a988ad2d652276bca0ad8141a5
查看已存在的键值对:
127.0.0.1:6379> keys *
配置主从服务器:
配置slave服务器很简单,只需要在slave的配置文件中加入以下配置:
slaveof masterip masterport
如果主机开启了登录验证,那么还需要加入下面这句:
masterauth authpassword
java链接redis缓存:
<!--redis -->
<
bean
id
=
"poolConfig"
class
=
"redis.clients.jedis.JedisPoolConfig"
>
<
property
name
=
"maxIdle"
value
=
"${redis.maxIdle}"
/>
<
property
name
=
"maxWaitMillis"
value
=
"${redis.maxWait}"
/>
<
property
name
=
"testOnBorrow"
value
=
"${redis.testOnBorrow}"
/>
</
bean
>
<
bean
id
=
"jedisConnectionFactory"
class
=
"org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name
=
"${redis.host}"
p:port
=
"${redis.port}"
p:use-pool
=
"true"
p:password
=
"${redis.password}"
/>
<
bean
id
=
"redisTemplate"
class
=
"org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref
=
"jedisConnectionFactory"
/>
<
bean
id
=
"cacheManager"
class
=
"org.springframework.data.redis.cache.RedisCacheManager"
c:redis-operations-ref
=
"redisTemplate"
>
<
property
name
=
"expires"
>
<
map
>
<!-- <entry key="logFormat" value="${redis.logFormat.timeout}"/>-->
<
entry
key
=
"existTask"
value
=
"${redis.existTask.timeout}"
/>
</
map
>
</
property
>
</
bean
>
<!--redis end -->
${}这个表示是变量,在config.properties文件中配置的。