一、Redis AOF模式设置
修改配置文件redis.conf参数:
appendonly yes
# appendfsync always
appendfsync everysec
# appendfsync no
二、测试方法
创建多线程,其中每一个线程执行一个无限循环向Redis 发送set key-value命令,由于处理器执行一次循环操作的速度非常快,因此这样每一个线程都模拟了一个多并发的情况。
<span style="font-size:18px;">class pushThread extends Thread {
private JedisPool jedisPool;
private Jedis jj;
private String threadName;
public pushThread(String threadName) {
jedisPool = new JedisPool(new JedisPoolConfig(),"localhost");
jj = jedisPool.getResource();
this.threadName = threadName;
}
public void run() {
int n = 1;
for(;;) {
jj.set("key" + threadName, "" + n);
System.out.println(n + " has been set by " + threadName);
n++;
}
}
}</span>…<span style="font-size:18px;">public static void main(String[] args) {
for(int i = 0; i < 80; i++) {
new pushThread("" + i).start();
}
}</span>
三、测试说明
1、读取Redis的timeout异常在服务器运行时对 RDB 文件进行备份。RDB文件一旦被创建,就不会进行任何修改,当服务器要创建一个新的RDB文件时,它先将文件的内容保存在一个临时文件里,当临时文件写入完毕才会替换原来的RDB文件,因此备份RDB文件都是相对安全的。
原文地址:http://blog.csdn.net/dreamcode/article/details/45740347