未解决的问题
persistence-available no #不用持久化
maxmemory 4gb #内存限制
maxmemory-policy volatile-lru #内存满时,删除设置了超时时间的那些key的最近最久没有使用的
#save 900 1 #还注释了这三行,这是rdb满足什么条件执行持久化,我觉得有上面的配置这个不注释也可以
#save 300 10
#save 60 10000
这样配置会报这样的错误
persistence-available [no]
这样不会报错,但我感觉不应该用中括号?
不过把save
注释掉,也就不会执行持久化了。
问题1
以前遇到过一个问题,但redis日志没有记录下来,只有应用程序的日志:
[search-service][ERROR] [2018-02-05 14:24:53] com.pyc.redis.RedisClient.hexists(363) | redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
[search-service][ERROR] [2018-02-05 04:48:32] com.pyc.redis.RedisClient.hgetAll(395) | redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
[search-service][ERROR] [2018-02-05 11:50:30] com.pyc.redis.RedisClient.exists(174) | redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
检查程序发现,jedis实例没有正确关闭导致的。
原来是jedisPool.returnResource(jedis);
后来是jedis.close();
应用程序响应时间特别的慢,redis.conf配置文件中redis.pool.maxWait=3000
(单位毫秒)的意思是最大建立连接等待时间。本来没有redis,程序就比较慢,再去建立一个不能响应的连接就更耗时了。
补充一句,如果redis报错,程序会处理这个错误,简单的记录到日志中,所以应用服务会绕过redis缓存,直接操作数据库,应用程序速度会变慢,但不会停止服务。
/**
* 判断key值是否存在
* @author zhouna
* @data 2017年11月20日 上午11:29:01
*
* @param key
* @return
*/
public static boolean exists(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
return jedis.exists(key);
} catch (Exception e) {
logger.error(e+" exists(key:"+key+")", e);
return false;
} finally {
if (jedis != null) { jedis.close(); }
}
}
可以通过修改配置文件可以将日志记录下来:
logfile E:/redis-2.4.5-win32-win64/64bit/redis-log.txt
并且在启动redis时带上配置文件名,否则就是默认配置文件,默认配置文件不是当前目录下的配置文件。
问题2
程序错误日志
[search-service][ERROR] [2018-02-18 23:59:59] com.pyc.redis.RedisClient.hset(435) | redis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. hset(key:LIST_PRODUCT_FILTERED_STORE, field:######, value:[com.pyc.search.searchservice.model.Product@3bfa36d4,
....]
redis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
at redis.clients.jedis.Protocol.processError(Protocol.java:113)
at redis.clients.jedis.Protocol.process(Protocol.java:138)
at redis.clients.jedis.Protocol.read(Protocol.java:192)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:282)
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:207)
at redis.clients.jedis.Jedis.hset(Jedis.java:585)
at com.pyc.redis.RedisClient.hset(RedisClient.java:432)
at com.pyc.search.searchservice.core.SearchResult.getResultFromTopDocsFilteredByStore(SearchResult.java:476)
redis窗口
[8288] 28 Feb 10:09:25.406 # fork operation complete
[8288] 28 Feb 10:09:25.855 # Background saving error
[8288] 28 Feb 10:09:25.956 * 1 changes in 3600 seconds. Saving...
[8288] 28 Feb 10:09:26.176 * Background saving started by pid 9148
[9148] 28 Feb 10:09:50.334 # Write error saving DB on disk: No space left on dev
ice
[9148] 28 Feb 10:09:50.608 # rdbSave failed in qfork: No space left on device
[8288] 28 Feb 10:09:50.645 # fork operation complete
[8288] 28 Feb 10:09:51.349 # Background saving error
[8288] 28 Feb 10:09:51.450 * 1 changes in 3600 seconds. Saving...
[8288] 28 Feb 10:09:51.694 * Background saving started by pid 8540
[8540] 28 Feb 10:10:18.171 # Write error saving DB on disk: No space left on dev
ice
[8540] 28 Feb 10:10:18.446 # rdbSave failed in qfork: No space left on device
[8288] 28 Feb 10:10:18.525 # fork operation complete
[8288] 28 Feb 10:10:19.129 # Background saving error
[8288] 28 Feb 10:10:19.231 * 1