当前位置:网站首页>RDB持久化验证测试

RDB持久化验证测试

2022-06-26 09:41:00 xianghan收藏册

RDB持久化验证测试

验证shutdown的持久化

1.正例

如果已经存在rdb文件先删除

rm -rf dump.rdb

保存测试值

set k1 1
set k2 2

执行shutdown,验证保存rdb文件

127.0.0.1:6379> SHUTDOWN
not connected> exit

查看文件

[[email protected] redis-3.2.9]# ll
total 20344
-rw-rw-r--.  1 root root   87407 May 17  2017 00-RELEASENOTES
-rw-rw-r--.  1 root root      53 May 17  2017 BUGS
-rw-rw-r--.  1 root root    1805 May 17  2017 CONTRIBUTING
-rw-rw-r--.  1 root root    1487 May 17  2017 COPYING
drwxrwxr-x.  7 root root    4096 Jan 22 17:54 deps
-rw-r--r--.  1 root root      93 Jan 25 16:59 dump.rdb
-rw-rw-r--.  1 root root      11 May 17  2017 INSTALL
-rw-rw-r--.  1 root root     151 May 17  2017 Makefile
-rw-rw-r--.  1 root root    4223 May 17  2017 MANIFESTO
-rw-rw-r--.  1 root root    6834 May 17  2017 README.md
-rwxr-xr-x.  1 root root 2433664 Jan 22 18:09 redis-benchmark
-rwxr-xr-x.  1 root root   25165 Jan 22 18:09 redis-check-aof
-rwxr-xr-x.  1 root root 5183694 Jan 22 18:09 redis-check-rdb
-rwxr-xr-x.  1 root root 2586683 Jan 22 18:09 redis-cli
-rw-rw-r--.  1 root root   46696 Jan 22 18:10 redis.conf
-rwxr-xr-x.  1 root root 5183694 Jan 22 18:09 redis-sentinel
-rwxr-xr-x.  1 root root 5183694 Jan 22 18:09 redis-server
-rwxrwxr-x.  1 root root     271 May 17  2017 runtest
-rwxrwxr-x.  1 root root     280 May 17  2017 runtest-cluster
-rwxrwxr-x.  1 root root     281 May 17  2017 runtest-sentinel
-rw-rw-r--.  1 root root    7606 May 17  2017 sentinel.conf
drwxrwxr-x.  2 root root    4096 Jan 22 18:05 src
drwxrwxr-x. 10 root root    4096 May 17  2017 tests
drwxrwxr-x.  7 root root    4096 May 17  2017 utils

恢复运行

./redis-server redis.conf

验证

127.0.0.1:6379> get k1
"1"

数据恢复成功

2.反例

保存测试值

set k1 1
set k2 2

执行shutdown,验证保存rdb文件

127.0.0.1:6379> SHUTDOWN
not connected> exit

查看文件

[[email protected] redis-3.2.9]# ll
total 20344
-rw-rw-r--.  1 root root   87407 May 17  2017 00-RELEASENOTES
-rw-rw-r--.  1 root root      53 May 17  2017 BUGS
-rw-rw-r--.  1 root root    1805 May 17  2017 CONTRIBUTING
-rw-rw-r--.  1 root root    1487 May 17  2017 COPYING
drwxrwxr-x.  7 root root    4096 Jan 22 17:54 deps
-rw-r--r--.  1 root root      93 Jan 25 16:59 dump.rdb
-rw-rw-r--.  1 root root      11 May 17  2017 INSTALL
-rw-rw-r--.  1 root root     151 May 17  2017 Makefile
-rw-rw-r--.  1 root root    4223 May 17  2017 MANIFESTO
-rw-rw-r--.  1 root root    6834 May 17  2017 README.md
-rwxr-xr-x.  1 root root 2433664 Jan 22 18:09 redis-benchmark
-rwxr-xr-x.  1 root root   25165 Jan 22 18:09 redis-check-aof
-rwxr-xr-x.  1 root root 5183694 Jan 22 18:09 redis-check-rdb
-rwxr-xr-x.  1 root root 2586683 Jan 22 18:09 redis-cli
-rw-rw-r--.  1 root root   46696 Jan 22 18:10 redis.conf
-rwxr-xr-x.  1 root root 5183694 Jan 22 18:09 redis-sentinel
-rwxr-xr-x.  1 root root 5183694 Jan 22 18:09 redis-server
-rwxrwxr-x.  1 root root     271 May 17  2017 runtest
-rwxrwxr-x.  1 root root     280 May 17  2017 runtest-cluster
-rwxrwxr-x.  1 root root     281 May 17  2017 runtest-sentinel
-rw-rw-r--.  1 root root    7606 May 17  2017 sentinel.conf
drwxrwxr-x.  2 root root    4096 Jan 22 18:05 src
drwxrwxr-x. 10 root root    4096 May 17  2017 tests
drwxrwxr-x.  7 root root    4096 May 17  2017 utils

删除rdb文件

rm -rf dump.rdb

恢复运行

./redis-server redis.conf

验证

127.0.0.1:6379> get k1
(nil)

数据恢复失败,原因是rdb被删除了

原网站

版权声明
本文为[xianghan收藏册]所创,转载请带上原文链接,感谢
https://blog.csdn.net/xianghanscce/article/details/125400884