Redis(Remote Dictionary Server)是一个使用ANSI C编写的支持网络、基于内存分布式、可选持久性键值对存储数据库。根据月度排行网站DB-Engines.com的数据,Redis是最流行的键值对存储数据库。[2]

Redis
開發者Salvatore Sanfilippo英语Salvatore Sanfilippo
首次发布2009年5月10日,​17年前​(2009-05-10
当前版本8.8.0[1]在维基数据编辑(2026年5月25日,22天前)
源代码库 編輯維基數據鏈接
编程语言ANSI C
操作系统跨平台
语言英语
类型非关系型数据库
许可协议Redis Source Available License 或 伺服器端公眾授權條款英语Server Side Public License雙重授權
网站redis.io 编辑维基数据

历史

编辑

Redis始于2009年,最初的开发者是Salvatore Sanfilippo。

Sanfilippo于2010年3月被VMware聘用。[3]

2013年5月,Redis由VMware子公司毕威拓赞助。[4]

2015年6月至,Redis的开发在Redis Labs英语Redis Labs赞助下由Sanfilippo团队维护。[5]

2019年11月,RedisLabs发布了全新的可视化图形用户界面Redis工具RedisInsight。

2020年6月,Sanfilippo辞去Redis维护者职务,退居二线担任“谋士”。Redis转为社区自治模式。[6]

2024年3月,Redis更改主程式碼授權條款,從開源BSD许可证轉為 Redis Source Available License 或 伺服器端公眾授權條款英语Server Side Public License雙重授權,不再属于开源软件。

支持语言

编辑

许多语言都包含Redis支持,包括:[7]

 
Salvatore Sanfilippo在Redis开发者大会(拍摄于2015年)

Python簡單範例

编辑
# coding:utf-8
import redis

# lredis-server保持開啓狀態,如果在客戶端設定了密碼 添加password=密碼即可
pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
r = redis.StrictRedis(connection_pool=pool)
# 字符串
r.set('test', 'aaa')
print r.get('test')
# 列表
# 注意python、lrange兩個range的範圍
x = 0
for x in range(0, 11):
    r.lpush('list', x)
    x = x + 1
print r.lrange('list', '0', '10')

# 雜湊
dict_hash = {'name': 'tang', 'password': 'tang_passwd'}
r.hmset('hash_test', dict_hash)
print r.hgetall('hash_test')

# 集合
r.sadd('set_test', 'aaa', 'bbb')
r.sadd('set_test', 'ccc')
r.sadd('set_test', 'ddd')
print r.smembers('set_test')

# 有序集
r.zadd('zset_test', {'aaa': 1, 'bbb': 1})
r.zadd('zset_test', {'ccc': 1})
r.zadd('zset_test', {'ddd': 1})
print r.zrange('zset_test', 0, 10)

数据模型

编辑

Redis的外围由一个键、值映射的字典构成。与其他非关系型数据库主要不同在于:Redis中值的类型不仅限于字符串,还支持如下抽象数据类型:

值的类型决定了值本身支持的操作。Redis支持不同无序、有序的列表,无序、有序的集合间的交集、并集等高级服务器端原子操作。

持久化

编辑

Redis通常将全部的数据存储在内存中。2.4版本后可配置为使用虚拟内存[9]一部分数据集存储在硬盘上,但这个特性废弃了。

目前通过两种方式实现持久化

  • 使用快照,一种半持久耐用模式。不时的将数据集以异步方式从内存以RDB格式写入硬盘。
  • 1.1版本开始使用更安全的AOF格式替代,一种只能追加的日志类型。将数据集修改操作记录起来。Redis能够在后台对只可追加的记录进行修改,从而避免日志的無限增长。

同步

编辑

Redis支持主从同步。数据可以从主服务器向任意数量的从服务器上同步,从服务器可以是关联其他从服务器的主服务器。这使得Redis可执行单层树复制。从盘可以有意无意的对数据进行写操作。由于完全实现了发布/订阅机制,使得从数据库在任何地方同步树时,可订阅一个频道并接收主服务器完整的消息发布记录。同步对读取操作的可扩展性和数据冗余很有帮助。[10]

性能

编辑

当数据依赖不再需要,Redis这种基于内存的性质,与在执行一个事务时将每个变化都写入硬盘的数据库系统相比就显得执行效率非常高。[11]写与读操作速度没有明显差别。

安全性

编辑

Redis 7.0.0到7.2.6版本及7.4.0到7.4.1版本存在拒绝服务攻击漏洞(CVE-2024-51741),当拥有权限的认证用户创建一个畸形的访问控制列表(ACL)选择器后,访问这个畸形选择器会造成服务器崩溃,并进入拒绝服务状态,通过升级到7.2.7或7.4.2版本可修复这个问题[12]

2024年发现所有开启Lua脚本功能的Redis版本,如果认证过的攻击者编写恶意的Lua脚本来操纵垃圾收集器,可能在服务器上执行任意代码(CVE-2024-46981[13],需要升级到7.2.7或7.4.2以后的版本并限制Lua脚本以修复这个漏洞[12]。2025年发现Redis8.2.1之前的版本(CVE-2025-49844),攻击者可通过构造恶意Lua脚本并提交执行码,触发远程代码执行[14]

参见

编辑

参考资料

编辑
  1. ^ 1.0 1.1 Release 8.8.0. 2026年5月25日 [2026年5月25日]. 
  2. ^ DB-Engines Ranking of Key-value Stores. [2013-06-29]. (原始内容存档于2013-07-07). 
  3. ^ Shapira, Gwen. VMware Hires Redis Key Developer – But Why?. Blog. March 17, 2010 [September 25, 2016]. (原始内容存档于2023-03-14). 
  4. ^ Sanfilippo, Salvatore. Redis Sponsors. Redis.io. Redis Labs. [April 11, 2019]. (原始内容存档于2023-03-14). 
  5. ^ Sanfilippo, Salvatore. Thanks Pivotal, Hello Redis Labs. <antirez>. July 15, 2015 [2019-04-03]. (原始内容存档于2015-07-18). 
  6. ^ Redis之父退出开源项目维护:人生苦短不想上班_工作. www.sohu.com. [2023-11-20]. 
  7. ^ Redis language bindings. [2013-07-01]. (原始内容存档于2014-02-08). 
  8. ^ CRAN - Package rredis. [2013-07-01]. (原始内容存档于2013-06-20). 
  9. ^ Redis documentation "Virtual Memory"页面存档备份,存于互联网档案馆), redis.io, accessed January 18, 2011.
  10. ^ ReplicationHowto - redis - A persistent key-value database with built-in net interface written in ANSI-C for Posix systems - Google Project Hosting. [2013-07-01]. (原始内容存档于2013-05-29). 
  11. ^ FAQ. [2013-07-01]. (原始内容存档于2013-07-16). 
  12. ^ 12.0 12.1 Baran, Guru. Redis Server Vulnerabilities Let Attackers Execute Remote Code. Cyber Security News. 2025-01-07 [2025-12-24]. 
  13. ^ Lua library commands may lead to remote code execution. GitHub. [2025-12-24] (英语). 
  14. ^ Zorz, Zeljka. Redis patches critical "RediShell" RCE vulnerability, update ASAP! (CVE-2025-49844). Help Net Security. 2025-10-07 [2025-12-26]. 

外部链接

编辑

📚 Artikel Terkait di Wikipedia

Bigtable

synergy in an acquisition." YouTube Scalability Talk (页面存档备份,存于互联网档案馆) "How Entities and Indexes are Stored - Google App Engine - Google Code". [2011-04-05]

Heroku

and durable open-source SQL-compliant database, PostgreSQL is the datastore of choice for serious applications. Now it is available in seconds with a single

关系型数据库管理系统比较

(2004) Comparison of geometrical data handling in PostgreSQL, MySQL and DB2 (29/Sep/2003) Open Source Database Software Comparison (Mar/2005) PostgreSQL vs

软件再许可

95% of the source code and no objections from the holders of the other 5%. This, I’m told, is how Mozilla was able to relicense to the GPL in 2003 despite

ScyllaDB

2015, Slashdot Scylla public GitHub repository (页面存档备份,存于互联网档案馆), with source code repository and bug tracker ScyllaDB Inc. homepage (页面存档备份,存于互联网档案馆)

奎宿一

2008. Table 2, Resolved double-lined spectroscopic binaries: A neglected source of hypothesis-free parallaxes and stellar masses, D. Pourbaix, Astronomy

Tcl

维基共享资源上的相关多媒体资源:Tcl 官方网站 Tcl Sources(页面存档备份,存于互联网档案馆), main Tcl and Tk source code download website Tcler's Wiki(页面存档备份,存于互联网档案馆) TkDocs(页面存档备份,存于互联网档案馆)

Waze

(原始内容存档于2013-01-12).  Waze Wiki Source code. Waze.com. 2012-04-29 [2012-09-25]. (原始内容存档于2012-11-15).  Waze 2.4.0.0 iPhone Source code. Waze.com. 2013-06-15 [2013-06-15]