RDB 试验(一)同步命令 save

  • 重置配置文件
[root@redis3_0_7 ~]# redis-cli -p 6382 shutdown
[root@redis3_0_7 ~]# cd /opt/soft/redis/config
[root@redis3_0_7 config]# rm -rf redis-6382.conf 
[root@redis3_0_7 config]# cp ../redis.conf .
[root@redis3_0_7 config]# cp redis.conf redis-6379.conf
[root@redis3_0_7 config]# vi redis-6379.conf
daemonize yes
pidfile /var/run/redis-6379.pid
port 6379
logfile "6379.log"
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6379.rdb
dir /opt/soft/redis/data
  • 重置后的 redis-6379.conf
daemonize yes
pidfile /var/run/redis-6379.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "6379.log"
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6379.rdb
dir /opt/soft/redis/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
  • 启动 redis
[root@redis3_0_7 config]# redis-server redis-6379.conf
[root@redis3_0_7 config]# redis-cli
127.0.0.1:6379> dbsize
(integer) 0
  • 用 Jedis 向 redis 中插入数据,更改 key,让程序运行 4 遍;
public class PipelineMain {

    public static void main(String[] args) {
        Jedis jedis = new Jedis(Const.HOST, Const.PORT);
        for(int i = 0; i < 1000; i++) {
            Pipeline pipeline = jedis.pipelined();
            for(int j = i * 1000; j < (i + 1) * 1000; j++) {
                pipeline.hset("HashKey3:" + j, "field" + j, "value" + j);
            }
            pipeline.syncAndReturnAll();
        }
    }

}
  • redis 大小
127.0.0.1:6379> dbsize
(integer) 4000000
127.0.0.1:6379> info memory
# Memory
used_memory:546325720
used_memory_human:521.02M
used_memory_rss:560660480
used_memory_peak:546346432
used_memory_peak_human:521.04M
used_memory_lua:36864
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-3.6.0
  • 客户端 1 准备读
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
  • 客户端 2 执行 save
127.0.0.1:6379> save
  • 客户端 1 读,被阻塞
127.0.0.1:6379> get hello
  • 客户端 2 save 执行完,客户端 1 读才完成
127.0.0.1:6379> save
OK
(3.86s)
127.0.0.1:6379> get hello
"world"
(2.73s)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值