Skip to content

about

Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库,它的主要特点:

  • 高性能Key-Value服务器
  • 支持多种数据结构
  • 丰富的功能:pipeline、慢查询、发布订阅
  • 高可用分布式支持

Redis的前世今生

在2008年北京开奥运会的时候,意大利一个叫做塞尔瓦托的技术大佬, 做了一个基于MySQL的的网站实时统计系统LLOOGG.com。但不久,这个大佬, 对MySQL的性能感到失望,于是Redis慢慢就诞生了.

谁在使用Redis

嗯~~,试问,现在还有谁没有在用Redis?

Redis八大特性

速度快

官方说redis能达到十万OPS(operation per second)每秒操作的次数。

这是因为redis是由C语言实现,并且redis的数据存储在内存中。

持久化

redis的所有数据保存在内存中,对数据的更新将异步的保存在磁盘上。

多种数据结构

redis支持字符串、哈希、链表、集合和有序集合五种数据类型。

衍生的其他数据结构:

  • 基于字符串实现:

    • BitMaps:位图
    • HyperLogLog:超小内存唯一值计数
  • 基于集合实现:

    • GEO:地理位置

支持多种客户端语言

Python、Java........

功能丰富

发布订阅、事务、Lua脚本、Pipeline....

简单

Redis的单机源码大约只有23000行代码,所以,你可以去阅读它的源码,甚至自定义.....

Redis不依赖外部库

单线程模型

主从复制

Redis有主服务器和从服务器是实现高可用的基础。

高可用、分布式

Redis从v2.8开始使用Redis-Sentinel支持高可用。

Redis从v3.0开始使用Redis-Cluster支持分布式。

Redis典型应用场景

  • 缓存系统,在项目架构中,实现缓存层功能。

  • 计数器,例如微博的转发数和评论数

  • 消息队列,简单的消息队列可以用Redis来实现。

  • 排行榜,有序集合可以实现各种排行榜,如音乐、视频排行榜等。

  • 社交网络,粉丝数、关注数、最新粉丝、共同关注、时间轴等。

  • 实时系统,垃圾邮件处理。

版本选择

1832670441395716096.png

2.x		非常老
3.x		主流,开始支持redis-cluster
4.x		过渡版本,支持混合持久化
5.x		稳定版,增加了流处理类型
6.x		
7.x

redis的监听端口为啥默认是6379?

1832670441894838272.png

Details

Today on Twitter I saw a tweet related to the ability to remember the Redis port number. There is a trick, the Redis port number, 6379, is MERZ at the phone keyboard.

Is it a coincidence that it sounds not random enough? Actually not 😉 I selected 6379 because of MERZ, and not the other way around.

Everything started with Alessia Merz, an Italian Showgirl (make sure to check some (not safe for work) photo as well).

I and my friends are used to create our own slang, that is evolving since... 20 or 25 years. Well one adjective that we use consistently since 10 years is "merz", but the meaning of the word changed so much in the course of the time.

Initially it started because we were really delighted by the stupidity of the sentences that the showgirl was able to state in the italian TV. So we started using "MERZ" when something was... stupid. "Hey, that's merz!". And so forth. But then with some time the meaning shifted in something stupid as pointless, but with very technical value, or with an impressive amount of skills and patience and work involved, but still... stupid.

For instance creating a 3D map of your hometown by sampling the points with a GPS and a broken car going around for the whole night, or analyzing tons of lottery data searching for biases, perfectly knowing that we'll never spend a single penny in a lottery ticket anyway, and so forth. "Merz" basically means... hack value, but is also referred to people not just things, people that act in a funny way just for hack value, or to be fun, and so forth.

So when I had to pick a port number for Redis I had no troubles, whatever number MERZ was at the phone, it was the Redis port number.

was at the phone, it was the Redis port number.

:::