春招面试模拟,如同雷同,纯属巧合!!!

  面试的大体流程:

  第一步:一般会有笔试题,也可能没有。有笔试题就要好好答了,因为会重视笔试结果,为了节约面试官时间,HR可能先会看,不合格直接让你走人了。

  第二步:开始面试,面试官会让你先来个自我介绍,他在看你的简历。可能有人会有疑问?为什么简历上都写的很清楚还让我做自我介绍?因为面试官不会提前看你的简历,他要有时间去看简历。所以自我介绍,不宜过长或过短,要重点突出,怎么重点突出?提前看好岗位要求,要求都是入职之后用到的技术,所以面试官会看重那些!!!自我介绍结束,步入正题。

  面试官会问:之前的公司用过redis么?

  面试者有两类回答:

  面试者甲:没用过,但自己学过,下载过源码,自己部署安装过,基本的命令像string/hash/lsit/set/zset,都熟悉;

  面试官(心想虽然没用,但动手能力很强,也很好学,不错):redis是内存数据库,那它怎么进行持久化的?

  面试官甲(心想没注意看啊,不知道啊):...

  面试者乙:用过,比较熟悉

  面试官会接着问:持久化方式有哪些?

  面试者乙:RDB和AOF

  面试官:原理?区别?优缺点说一下吧?

  面试官乙:...

  要是是你去面试,你能回答上来么?

  下面让我为你一一揭晓答案!!!

  RDB持久化(Redis DataBase)

  redis是内存数据库,一旦服务器进程退出,服务器中的数据库状态也会消失不见。重点介绍save和bgsave命令。

  RDB文件的创建与载入

  save命令会阻塞Redis服务器进程,直到RDB文件创建为止,在服务器进程阻塞期间,服务器不能处理任何命令请求。

  bgsave命令派生出子进程,,然后由子进程创建RDB文件,父进程继续处理请求。

  创建RDB文件实际rdb.c/rdbLoad函数完成的

  自动间隔性保存

  redis服务器会通过用户配置save选项,每隔一段时间去执行一下bgsave命令;默认的配置文件redis.conf,关于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 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 # 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.
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 it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes # Since version of RDB a CRC64 checksum is placed at the end of the file.
# This makes the format more resistant to corruption but there is a performance
# hit to pay (around %) when saving and loading RDB files, so you can disable it
# for maximum performances.
#
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
rdbchecksum yes # The filename where to dump the DB
dbfilename dump.rdb # The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

rdb

  主要有三条策略,满足任意一个,就会执行bgave命令:

  服务器在900秒之内,对数据库至少修改了1次

  服务器在300秒之内,对数据库至少修改了10次

  服务器在60秒之内,对数据库至少修改了10000次

  优缺点

  优点:

  适合大规模的数据恢复

  对数据完整性和一致性要求不高

  缺点:

  会丢失最后一次修改的数据

  fork会产生额外消耗

  AOF持久化(Append Only File)

  与RDB通过键值对来记录数据库状态不同,AOF是通过Redis服务器所执行的写命令来记录数据库状态的。

  AOF持久化的实现

  AOF持久化功能的实现可以分为命令追加(append)、文件写入、文件同步(sync)三个步骤。

  aof在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 # When the AOF fsync policy is set to always or everysec, and a background
# saving process (a background save or AOF log background rewriting) is
# performing a lot of I/O against the disk, in some Linux configurations
# Redis may block too long on the fsync() call. Note that there is no fix for
# this currently, as even performing fsync in a different thread will block
# our synchronous write() call.
#
# In order to mitigate this problem it's possible to use the following option
# that will prevent fsync() from being called in the main process while a
# BGSAVE or BGREWRITEAOF is in progress.
#
# This means that while another child is saving, the durability of Redis is
# the same as "appendfsync none". In practical terms, this means that it is
# possible to lose up to seconds of log in the worst scenario (with the
# default Linux settings).
#
# If you have latency problems turn this to "yes". Otherwise leave it as
# "no" that is the safest pick from the point of view of durability. no-appendfsync-on-rewrite no # Automatic rewrite of the append only file.
# Redis is able to automatically rewrite the log file implicitly calling
# BGREWRITEAOF when the AOF log size grows by the specified percentage.
#
# This is how it works: Redis remembers the size of the AOF file after the
# latest rewrite (if no rewrite has happened since the restart, the size of
# the AOF at startup is used).
#
# This base size is compared to the current size. If the current size is
# bigger than the specified percentage, the rewrite is triggered. Also
# you need to specify a minimal size for the AOF file to be rewritten, this
# is useful to avoid rewriting the AOF file even if the percentage increase # Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature. auto-aof-rewrite-percentage
auto-aof-rewrite-min-size 64mb # An AOF file may be found to be truncated at the end during the Redis
# startup process, when the AOF data gets loaded back into memory.
# This may happen when the system where Redis is running
# crashes, especially when an ext4 filesystem is mounted without the
# data=ordered option (however this can't happen when Redis itself
# crashes or aborts but the operating system still works correctly).
#
# Redis can either exit with an error when this happens, or load as much
# data as possible (the default now) and start if the AOF file is found
# to be truncated at the end. The following option controls this behavior.
#
# If aof-load-truncated is set to yes, a truncated AOF file is loaded and
# the Redis server starts emitting a log to inform the user of the event.
# Otherwise if the option is set to no, the server aborts with an error
# and refuses to start. When the option is set to no, the user requires
# to fix the AOF file using the "redis-check-aof" utility before to restart
# the server.
#
# Note that if the AOF file will be found to be corrupted in the middle
# the server will still exit with an error. This option only applies when
# Redis will try to read more data from the AOF file but not enough bytes
# will be found.
aof-load-truncated yes

aof

  AOF重写

  随着服务器时间的流逝,文件的体积越来越大,体积过大的AOF文件对redis服务器、甚至整个宿主计算机造成影响。并且AOF文件的体积越大,使用AOF文件进行数据还原所需的时间越多。

  为了解决AOF文件体重膨胀的问题,redis提供了AOF文件重写(rewrite)的功能。

  触发机制

  redis会记录上次重写时AOF的大小,默认配置是当AOF文件大小是上次rewrite后大小的一倍且大于64M;默认配置如下:  

  auto-aof-rewrite-percentage 100
  auto-aof-rewrite-min-size 64mb

  悄悄告诉你们个小秘密:可能在面试时,面试官会吹嘘公司很牛,redis用的出神入化,当你入职之后,可以悄悄看看“auto-aof-rewrite-min-size 64mb”,默认64M大小,根本不够用,告诉发展的公司起码要3G起。

  优缺点

  优点:

  配置灵活,可以选择多种方式进行持久化

  缺点:  

  相同数据集的数据而言,aof文件要远大于rdb文件,恢复速度慢于rdb

  

  

春招必问的redis持久化(RDB AOF),你能答上来么?的更多相关文章

  1. Redis持久化rdb&aof

    Redis持久化rdb&aof 前言 持久化:即把数据存储于断电后不会丢失的设备中,通常是硬盘 常见的持久化方式: 主从:通过从服务器保持持久化,如mongoDB的replication se ...

  2. Redis持久化--RDB+AOF(转)

    1.Redis两种持久化方式 RDB 执行机制:快照,直接将databases中的key-value的二进制形式存储在了rdb文件中 优点:性能较高(因为是快照,且执行频率比aof低,而且rdb文件中 ...

  3. 第十章 Redis持久化--RDB+AOF

    注:本文主要参考自<Redis设计与实现> 1.Redis两种持久化方式 RDB 执行机制:快照,直接将databases中的key-value的二进制形式存储在了rdb文件中 优点:性能 ...

  4. [动图演示]Redis 持久化 RDB/AOF 详解与实践

    Redis 是一个开源( BSD 许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件.它支持的数据类型很丰富,如字符串.链表.集 合.以及散列等,并且还支持多种排序功能. 什么叫持 ...

  5. [动图演示]Redis 持久化 RDB/AOF 详解与实践【华为云技术分享】

    Redis 是一个开源( BSD 许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件.它支持的数据类型很丰富,如字符串.链表.集 合.以及散列等,并且还支持多种排序功能. 什么叫持 ...

  6. redis++:Redis持久化 rdb & aof 工作原理及流程图 (三)

    RDB的原理: 在Redis中RDB持久化的触发分为两种:自己手动触发与Redis定时触发. 针对RDB方式的持久化,手动触发可以使用: 1):save:会阻塞当前Redis服务器,直到持久化完成,线 ...

  7. redis持久化RDB与AOF

    redis持久化 Redis是一种内存型数据库,一旦服务器进程退出,数据库的数据就会丢失,为了解决这个问题,Redis提供了两种持久化的方案,将内存中的数据保存到磁盘中,避免数据的丢失. RDB持久化 ...

  8. Linux 安装redis 基本配置 发布订阅,安全配置,持久化 rdb ,aof

    redis redis相关配置1.yum  源码 rpm  yum 快速,间接,高效,解决依赖关系,(自动安装到某个路径,不可控),通过yum安装的软件查询命令 rpm -ql nginx  yum源 ...

  9. redis的持久化(RDB&AOF的区别)

    RDB 是什么? 在指定的时间间隔内将内存中的数据集快照写入磁盘, 也就是行话讲的Snapshot快照,它恢复时是将快照文件直接读到内存里. Redis会单独创建(fork)一个子进程来进行持久化,会 ...

随机推荐

  1. Java手写数组栈

    public class ArrayStack{ private String[] items; //数组 private int count; //栈内元素 private int n; //栈大小 ...

  2. openjudge 7622 求排列的逆序数(归并)

    7622:求排列的逆序数 总时间限制:  1000ms   内存限制:  65536kB 描述 在Internet上的搜索引擎经常需要对信息进行比较,比如可以通过某个人对一些事物的排名来估计他(或她) ...

  3. matlab写入excel数据

    使用xlswrite 可以help xlswrite查看用法 xlswrite(filename,A)xlswrite(filename,A,sheet)xlswrite(filename,A,xlR ...

  4. FlashFXP中文破解 指南

    flashfxp是一款使用非常广泛,功能非常更强大的FXP/FTP软件.它拥有显示彩色文字.比较CuteFTP的目录.上传和下载文件.共享文件等众多功能,其中深受用户喜爱的便是目录比较功能,它能够有效 ...

  5. cesium加载WFS服务(GeoServer发布)

    需求: 为了便于前端渲染数据,自定义图层渲染. 思路: 获取地图服务中的要素进行渲染. 工具: GeoServer 2.6.4,cesium, 思路有了就开始找资料写代码,cesium有接口可以加载W ...

  6. Java之String类用法总结

    String类概述: 1.String类代表字符串.Java 程序中的所有字符串字面值(如"abc")都作为此类的实例实现. 2.String是一个final类,代表不可变的字符序 ...

  7. K8S基于ingress-nginx实现灰度发布

    之前介绍过使用ambassador实现灰度发布,今天介绍如何使用ingre-nginx实现. 介绍 Ingress-Nginx 是一个K8S ingress工具,支持配置 Ingress Annota ...

  8. [bzoj1375] [Baltic2002] Bicriterial routing 双调路径

    Description 如今的道路收费发展很快.道路的密度越来越大,因此选择最佳路径是很现实的问题.城市的道路是双向的,每条道路有固定的旅行时间以及需要支付的费用. 路径是连续经过的道路组成的.总时间 ...

  9. JAVA中值传递,引用传递

    刚在写一个用例,需要在方法中改变传递的参数的值,可是java中只有传值调用,没有传址调用.所以在java方法中改变参数的值是行不通的.但是可以改变引用变量的属性值. 可以仔细理解一下下面几句话: 1. ...

  10. Ogre 的Node 位移、旋转

    位移旋转有三种方式TS_LOCAL,TS_PARENT,TS_WORLD. TS_LOCAL是指自身坐标系,TS_PARENT是父节点坐标系,TS_WORLD是世界坐标系 比如  translate( ...