1)什么是Redis?

  English:Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker【1】.

  中文Redis是一个开源的内存数据库,支持多种数据结构的存取,常用来作为数据库,缓存和消息队列。

2)解释一下Redis的特性?

English:It supports data structures such as stringshasheslistssetssorted sets with range queries, bitmapshyperloglogsgeospatial indexes with radius queries and streams. Redis has built-in replicationLua scriptingLRU evictiontransactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

Other features include:

  中文:Redis支持多种数据结构:一方面,支持字符串,哈希表,数组,集合和支持范围查询的有序集合等基础数据结构;另一方面也支持位图,hyperloglog,带半径查找的地理信息定位和流式结构的高级数据结构。同时,它自带了复制,lua脚本,lru缓存清除,事务和不同等级的持久化方式,更通过哨兵方式提供了高可用,通过集群方式提供了自动分片。

  主要特性:

    事务

    发布/订阅

Lua脚本

KEY有效期设置

LRU缓存清除

自动故障转移

3) Memcached和Redis的区别是什么?

                           Redis                            Memcached
  • 虽然同样都支持缓存,但Redis支持一些其他特性 如持久化和复制
  • Redis 不支持CAS(检查和设置)。这对于维护缓存一致性很有用
  • Redis h具有较强的数据结构;它可以处理字符串、二进制安全字符串、二进制安全字符串列表、排序列表等。
  • Redis 支持键值最大为2GB
  • Redis是单线程的
  • Memcached 只支持缓存。
  • Memcached支持CAS(检查和设置)。
  • 在Memcached中,您必须序列化对象或数组才能保存它们,要将它们读取回来,您必须对它们进行反序列化。
  • Memcached键值支持最大250byte长度
  • Memcached 是多线程的

4) Redis的优势是什么?

  速度快

  支持服务器端锁定

  有很多客户端库【6】

  具有命令级原子操作(tx操作)

  应用广泛

5) Redis有哪些不足?

  单线程

  持久化开销大

6) Redis的键操作有哪些? 

    DEL
DUMP
EXISTS
EXPIRE
EXPIREAT
KEYS
MIGRATE
MOVE
OBJECT
PERSIST
PEXPIRE
PEXPIREAT
PTTL
RANDOMKEY
RENAME
RENAMENX
RESTORE
SCAN
SORT
TOUCH
TTL
TYPE
UNLINK
WAIT

7) 谁在使用Redis? 

  Twitter  GitHub  Weibo  Pinterest  Snapchat  Craigslist  Digg  StackOverflow  Flickr【2】

8) 使用Redis时需要注意什么?

1. key名设计

  • (1)【建议】: 可读性和可管理性

以业务名(或数据库名)为前缀(防止key冲突),用冒号分隔,比如业务名:表名:id

ugc:video:1
  • (2)【建议】:简洁性

保证语义的前提下,控制key的长度,当key较多时,内存占用也不容忽视,例如:

user:{uid}:friends:messages:{mid}简化为u:{uid}:fr:m:{mid}。
  • (3)【强制】:不要包含特殊字符

反例:包含空格、换行、单双引号以及其他转义字符

2. value设计

  • (1)【强制】:拒绝bigkey(防止网卡流量、慢查询)

string类型控制在10KB以内,hash、list、set、zset元素个数不要超过5000。

反例:一个包含200万个元素的list。

非字符串的bigkey,不要使用del删除,使用hscan、sscan、zscan方式渐进式删除,同时要注意防止bigkey过期时间自动删除问题(例如一个200万的zset设置1小时过期,会触发del操作,造成阻塞,而且该操作不会不出现在慢查询中(latency可查)),查找方法删除方法

  • (2)【推荐】:选择适合的数据类型。

例如:实体类型(要合理控制和使用数据结构内存编码优化配置,例如ziplist,但也要注意节省内存和性能之间的平衡)

反例:

set user:1:name tom
set user:1:age 19
set user:1:favor football

正例:

hmset user:1 name tom age 19 favor football

3.【推荐】:控制key的生命周期,redis不是垃圾桶。

建议使用expire设置过期时间(条件允许可以打散过期时间,防止集中过期),不过期的数据重点关注idletime。

9) Redis的持久化方式和各种优缺点?

  Redis持久化提供了4个选项

  1)RDB(快照)方式【The RDB persistence performs point-in-time snapshots of your dataset at specified intervals】

  2)AOF(命令式如mysql 的binlog)【the AOF persistence logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset. Commands are logged using the same format as the Redis protocol itself, in an append-only fashion. Redis is able to rewrite the log on background when it gets too big】

  3)不持久化

  4)AOF 和RDB混合方式

  各种方式的优缺点

RDB advantages
RDB is a very compact single-file point-in-time representation of your Redis data. RDB files are perfect for backups. For instance you may want to archive your RDB files every hour for the latest 24 hours, and to save an RDB snapshot every day for 30 days. This allows you to easily restore different versions of the data set in case of disasters.
RDB is very good for disaster recovery, being a single compact file can be transferred to far data centers, or on Amazon S3 (possibly encrypted).
RDB maximizes Redis performances since the only work the Redis parent process needs to do in order to persist is forking a child that will do all the rest. The parent instance will never perform disk I/O or alike.
RDB allows faster restarts with big datasets compared to AOF.
RDB disadvantages
RDB is NOT good if you need to minimize the chance of data loss in case Redis stops working (for example after a power outage). You can configure different save points where an RDB is produced (for instance after at least five minutes and 100 writes against the data set, but you can have multiple save points). However you'll usually create an RDB snapshot every five minutes or more, so in case of Redis stopping working without a correct shutdown for any reason you should be prepared to lose the latest minutes of data.
RDB needs to fork() often in order to persist on disk using a child process. Fork() can be time consuming if the dataset is big, and may result in Redis to stop serving clients for some millisecond or even for one second if the dataset is very big and the CPU performance not great. AOF also needs to fork() but you can tune how often you want to rewrite your logs without any trade-off on durability.
AOF advantages
Using AOF Redis is much more durable: you can have different fsync policies: no fsync at all, fsync every second, fsync at every query. With the default policy of fsync every second write performances are still great (fsync is performed using a background thread and the main thread will try hard to perform writes when no fsync is in progress.) but you can only lose one second worth of writes.
The AOF log is an append only log, so there are no seeks, nor corruption problems if there is a power outage. Even if the log ends with an half-written command for some reason (disk full or other reasons) the redis-check-aof tool is able to fix it easily.
Redis is able to automatically rewrite the AOF in background when it gets too big. The rewrite is completely safe as while Redis continues appending to the old file, a completely new one is produced with the minimal set of operations needed to create the current data set, and once this second file is ready Redis switches the two and starts appending to the new one.
AOF contains a log of all the operations one after the other in an easy to understand and parse format. You can even easily export an AOF file. For instance even if you flushed everything for an error using a FLUSHALL command, if no rewrite of the log was performed in the meantime you can still save your data set just stopping the server, removing the latest command, and restarting Redis again.
AOF disadvantages
AOF files are usually bigger than the equivalent RDB files for the same dataset.
AOF can be slower than RDB depending on the exact fsync policy. In general with fsync set to every second performances are still very high, and with fsync disabled it should be exactly as fast as RDB even under high load. Still RDB is able to provide more guarantees about the maximum latency even in the case of an huge write load.
In the past we experienced rare bugs in specific commands (for instance there was one involving blocking commands like BRPOPLPUSH) causing the AOF produced to not reproduce exactly the same dataset on reloading. This bugs are rare and we have tests in the test suite creating random complex datasets automatically and reloading them to check everything is ok, but this kind of bugs are almost impossible with RDB persistence. To make this point more clear: the Redis AOF works incrementally updating an existing state, like MySQL or MongoDB does, while the RDB snapshotting creates everything from scratch again and again, that is conceptually more robust. However - 1) It should be noted that every time the AOF is rewritten by Redis it is recreated from scratch starting from the actual data contained in the data set, making resistance to bugs stronger compared to an always appending AOF file (or one rewritten reading the old AOF instead of reading the data in memory). 2) We never had a single report from users about an AOF corruption that was detected in the real world

10) Redis数据库RDBMS的不同点有哪些?

  • Redis是非关系型数据库的成员而RDBMS是关系型数据库.
  • Redis支持key-value的结构而RDBMS支持表的结构.
  • Redis速度极快RDBMS相对较慢.
  • Redis是内存型数据,将所有数据存放到内存 而RDBMS存储数据到磁盘.
  • Redis用来存储小的频繁使用的的文件而RDBMS 用来存放较大的文件
  • Redis仅仅对Linux, BSD, Mac OS X, Solaris提供官方的支持. 当前对 Windows不提供官方支持,而RDBMS 支持所有的操作系统.

【1】 https://redis.io/topics/introduction

【2】https://redis.io/topics/whos-using-redis

【3】https://yq.aliyun.com/articles/531067

【4】https://redis.io/topics/persistence

【5】https://www.javatpoint.com/redis-interview-questions-and-answers

【6】https://redis.io/clients

redis 面试问题问答Top 10的更多相关文章

  1. 电话面试问答Top 50 --[伯乐在线]

    今年是2015年,在过去几年中,电面(电话面试)是筛选程序员职位候选人的最流行的方式.它让雇佣双方很容易互相了解对方,候选人不需要去未来雇主的所在地,面试官也不用做额外的安排.这是我介绍程序员面试问题 ...

  2. Redis面试热点之底层实现篇

    通过本文你将了解到以下内容: Redis的作者.发展演进和江湖地位 Redis面试问题的概况 Redis底层实现相关的问题包括:常用数据类型底层实现.SDS的原理和优势.字典的实现原理.跳表和有序集合 ...

  3. Redis面试大全

    1. 什么是Redis Redis是由意大利人Salvatore Sanfilippo(网名:antirez)开发的一款内存高速缓存数据库.Redis全称为:Remote Dictionary Ser ...

  4. 2018 年度码云热门项目排行榜 TOP 10

    2016 年度码云热门项目排行榜 TOP 10 是通过开源项目2016年在码云上的 Watch.Star.Fork 数量来评定的榜单.码云平台发展至今,涌现了越来越多优秀的开源项目,越来越多的开源作者 ...

  5. Redis面试热点之底层实现篇(续)

    0.题外话 接着昨天的[决战西二旗]|Redis面试热点之底层实现篇继续来了解一下ziplist压缩列表这个数据结构. 你可能会抱有疑问:我只是使用Redis的功能并且公司的运维同事都已经搭建好了平台 ...

  6. 浅谈Redis面试热点之工程架构篇[1]

    前言 前面用两篇文章大致介绍了Redis热点面试中的底层实现相关的问题,感兴趣的可以回顾一下:[决战西二旗]|Redis面试热点之底层实现篇[决战西二旗]|Redis面试热点之底层实现篇(续) 接下来 ...

  7. Redis面试专题

    Redis面试专题 1. 什么是redis? Redis 是一个基于内存的高性能key-value数据库. (有空再补充,有理解错误或不足欢迎指正) 2. Reids的特点 Redis本质上是一个Ke ...

  8. Favorites of top 10 rules for success

    Dec. 31, 2015 Stayed up to last minute of 2015, 12:00am, watching a few of videos about top 10 rules ...

  9. Top 10 Methods for Java Arrays

    作者:X Wang 出处:http://www.programcreek.com/2013/09/top-10-methods-for-java-arrays/ 转载文章,转载请注明作者和出处 The ...

随机推荐

  1. Java学习笔记 DbUtils数据库查询和log4j日志输出 使用

    DbUtils使用 QueryRunner DbUtils中定义了一个数据库操作类QueryRunner,所有的数据库操作CRUD都是通过此类来完成. 此类是线程安全的 方法名 对应sql语句 exc ...

  2. python基础(27):类成员的修饰符、类的特殊成员

    1. 类成员的修饰符 类的所有成员在上一步骤中已经做了详细的介绍,对于每一个类的成员而言都有两种形式: 公有成员,在任何地方都能访问 私有成员,只有在类的内部才能方法 私有成员和公有成员的定义不同:私 ...

  3. 网上售卖几百一月的微信机器,Python几十行代码就能搞定

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 故事胶片 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...

  4. c++11 C++14 C++17

    Since C++11, WG21, the ISO designation for the C++ standard,  try to shipped the standard every 3 ye ...

  5. toUpperCase(),toLowerCase()将字符串中的英文转换为全大写或全小写

    package seday01;/** * String toUpperCase() * String toLowerCase() * 将字符串中的英文转换为全大写或全小写 * @author xin ...

  6. u盘 安装 centOS 7

    实际上, 对于服务器的安装, 最好是能够远程批量安装(可能有些难度, 不是专业运维) 镜像下载地址: http://59.80.44.49/isoredirect.centos.org/centos/ ...

  7. Google在情报搜集中的基础技巧

    Google在情报搜集中的基础技巧 作者:王宇阳 时间:2019-06-06 作者笔记 ​ Google Hacking 是指使用特定的高级的google搜索语法,收集渗透测试目标的信息,查找目标的配 ...

  8. 使用android日志工具

    Log的级别? 日志级别按照高低排序为:ERROR,WARN,INFO,DEBUG,VERBOSE, 日志输出: Log.e()输出ERROR级别的日志信息 Log.w()输出WARN,ERROR级别 ...

  9. CODING 告诉你硅谷项目经理的项目管理之道

    写在前面 优秀的项目管理者是怎么工作的,如何把一个研发团队的绩效激发到最大? 我们精心挑选了几篇硅谷科技公司研发管理者的 README 进行翻译. README 主要用来向团队成员展示项目管理者的工作 ...

  10. C# 第三方库

    基本上选用的都是 https://www.nuget.org 分类中最流行的那个库 1. 日志工具库 NLOG Stackify.com 简单入门文章  https://stackify.com/nl ...