redis持久化的两种方式
redis是一个内存型数据库。当redis服务器重启时,数据会丢失。我们可以将redis内存中的数据持久化保存到硬盘的文件中。
redis持久化有两种机制。RDB与AOF。默认方式是RDB。
1.RDB
默认方式,不需要进行配置,默认就使用这种机制。在一定的间隔时间中,检测key的变化情况,然后持久化数据。
(1)编辑/etc/redis/redis.conf
################################ 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 sec ( min) if at least key changed
# after sec ( min) if at least keys changed
# after sec if at least 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 "" save
save
save
(2)重新启动redis服务器
2.AOF
日志记录的方式,可以记录每一条命令的操作。可以每一次命令操作后,持久化数据。
(1)编辑/etc/redis/redis.conf
############################## APPEND ONLY MODE ############################### # By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.
appendonly no # The name of the append only file (default: "appendonly.aof") appendfilename "appendonly.aof" # The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log. Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".
# appendfsync always
appendfsync everysec
# appendfsync no
appendonly no(关闭aof) --> appendonly yes (开启aof)
# appendfsync always : 每一次操作都进行持久化
appendfsync everysec : 每隔一秒进行一次持久化
# appendfsync no : 不进行持久化
redis持久化的两种方式的更多相关文章
- Redis持久化的两种方式和区别
该文转载自:http://www.cnblogs.com/swyi/p/6093763.html Redis持久化的两种方式和区别 Redis是一种高级key-value数据库.它跟memcached ...
- Redis持久化的两种方式(RDB和AOF)
redis提供了两种持久化的方式,分别是RDB(Redis DataBase)和AOF(Append Only File). RDB,简而言之,就是在不同的时间点,将redis存储的数据生成快照并存储 ...
- redis持久化的两种方式RDB和AOF
原文链接:http://www.cnblogs.com/tdws/p/5754706.html Redis的持久化过程中并不需要我们开发人员过多的参与,我们要做的是什么呢?除了深入了解RDB和AOF的 ...
- redis 持久化的两种方式
一:快照模式 或许在用Redis之初的时候,就听说过redis有两种持久化模式,第一种是SNAPSHOTTING模式,还是一种是AOF模式,而且在实战场景下用的最多的 莫过于SNAPSHOTTING模 ...
- redis 持久化有几种方式?
面试题 redis 的持久化有哪几种方式?不同的持久化机制都有什么优缺点?持久化机制具体底层是如何实现的? 面试官心理分析 redis 如果仅仅只是将数据缓存在内存里面,如果 redis 宕机了再重启 ...
- 转载redis持久化的几种方式
redis持久化的几种方式 1.前言 Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服 ...
- Redis的持久化的两种方式drbd以及aof日志方式
redis的持久化配置: 主要包括两种方式:1.快照 2 日志 来看一下redis的rdb的配置选项和它的工作原理: save 900 1 // 表示的是900s内,有1条写入,则产生快照 save ...
- Redis数据持久化的两种方式RDB和AOF
由于Redis的数据都存放在内存中,如果没有配置持久化,redis重启后数据就全丢失了,于是需要开启redis的持久化功能,将数据保存到磁 盘上,当redis重启后,可以从磁盘中恢复数据.redis提 ...
- redis做持久化的两种方式,RDB、AOF讲解
redis的两种持久化方式: 1.RDB方式 概念:在指定的时间间隔内保存数据快照 实现方式: 找到redis的安装目录,修改redis的配置文件(redis.conf):① 修改备份的时间间隔:sa ...
随机推荐
- 解题:USACO14OPEN Fair Photography
题面 有点像JRY的那道序列题,大概是统计题的经典套路? 先说无修改的:将白奶牛记为$-1$,花奶牛记为$1$,然后做前缀和统计某个前缀和$sum$第一次出现的位置,之后再出现就统计答案.对于修改(将 ...
- poi excel导入纯数字单元格显示科学计数法的处理
POI读取Excel文件时,对纯数字单元格的处理 用POI读取Excel文件的时候,可能会遇到这样的问题:Excel文件中某一单元格中的数据为数字,例如12345678910123. 正常读取的话 ...
- 约瑟夫环问题算法(M)
http://blog.csdn.net/zhuimengzh/article/details/6727221 用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出.写出C程序 ...
- merger_by_one 处理二维数组,根据里面某字段合并, 里面有的保留,有的求和~~
public function tt(){ $param = array( array ( 'hykno' => '2222222-CB', 'tcdk_fid' => '458B6D70 ...
- python基础之面向对象02
---继承 当我们定义完成某个类时,可以再定义一个新类,新类可以继承第一个类.新类被称为子类,而被继承的类称为父类/基类/超类. 继承就是子类继承父类的属性和方法(注意是类属性和类方法). 继承可以使 ...
- python中的zip
>>> a = zip([1,2,3],[34,35,36]) >>> print(a) <zip object at 0x0394D0F8> > ...
- bzoj千题计划140:bzoj4519: [Cqoi2016]不同的最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=4519 最小割树 #include<queue> #include<cstdio&g ...
- bzoj千题计划119:bzoj1029: [JSOI2007]建筑抢修
http://www.lydsy.com/JudgeOnline/problem.php?id=1029 把任务按截止时间从小到大排序 如果当前时间+当前任务耗时<=当前任务截止时间,把这个任务 ...
- IFrame跨域处理方法-Javascript
在漫长的前端开发旅途上,无可避免的会接触到ajax,而且一般情况下都是用在同一域下的ajax请求:但是如果请求是发生在不同的域下,请求就无法执行,并且会抛出异常提示不允许跨域请求,目前我没有找到明确的 ...
- laravel 和 thinkphp 条件查询的区别
laravel:以二维数组形式where查询,可以为空,即,该条where不运行: thinkphp:以字符串形式查询,不能为空.