Redis持久化(persistence)

Redis持久化简介:

    当使用Redis进行数据操作的时候,不可避免的能会遇到一些意外的情况导致Redis停止工作,诸如宕机,电源断电等因素。此时Redis提供了RDB以及AOF两种方式来进行数据的备份,两者各有优缺点。可以选择其中的一个单独使用,也支持两者同时使用。通常的情况下AOF保存的数据会比RDB完整,此外在两者同时使用的情况下会优先载入AOF来进行数据恢复。下面介绍下两者的优缺点及其实现。

Redis持久化之RDB:

  RDB简介:

    RDB(Redis DataBase)通过快照(SnapShotting)来实现在指定的时候内对数据进行保存。可以通过配置文件来修改RDB的触发,文件名等等。同也可以通过手动调用SAVE(阻塞)或者BGSAVE命令来触发RDB。

################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""  
#   配置RDB的触发条件使用save ""或者全部注释则关闭RDB
save 900 1
save 300 10
save 60 10000

# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
# This will make the user aware (in a hard way) that data is not persisting
# on disk properly, otherwise chances are that no one will notice and some
# disaster will happen.
#
# If the background saving process will start working again Redis will
# automatically allow writes again.
#
# However if you have setup your proper monitoring of the Redis server
# and persistence, you may want to disable this feature so that Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.
# 如果bgsave发生错误,停止Redis数据写入,保证数据的一致性。
stop-writes-on-bgsave-error yes

# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值