Redis: under the hood
How does the Redis server work?
I was curious to learn more about Redis’s internals, so I’ve been familiarizing myself with the source, largely by reading and jumping around in Emacs. After I had peeled back enough of the onion’s layers, I realized I was trying to keep track of too many details in my head, and it wasn’t clear how it all hung together. I decided to write out in narrative form how an instance of the Redis server starts up and initializes itself, and how it handles the request/response cycle with a client, as a way of explaining it to myself, hopefully in a clear fashion. Luckily, Redis has a nice, clean code base that is easy to read and follow along. Armed with a TAGSfile, my $EDITOR
, and GDB, I set out to see how it all works under the hood. (Incidentally, I was working with the Redis code base as ofcommit b4f2e41. Of course, internals such as I outline below are subject to change. However, the broad architecture of the server is unlikely to change very much, and I tried to keep that in mind as I went along.)
This article examines server startup and takes a high-level view of the request/response processing cycle. In a subsequent article, I’ll dive in to greater detail and trace a simple SET
/GET
command pair as they make their way through Redis.
Startup
Let’s begin with the main()
function in redis.c
.
Beginning global server state initialization
First, initServerConfig()
is called. This partially initializes a variable server
, which has the type struct redisServer
, that serves as the global server state.
// redis.h:338
struct redisServer {
pthread_t mainthread;
int port;
int fd;
redisDb *db;
// ...
};
// redis.c:69
struct redisServer server; /* server global state */
There are a huge number of members in this struct, but they generally fall into the following categories:
- general server state
- statistics
- configuration from config file
- replication
- sort parameters
- virtual memory config, state, I/O threads, & stats
- zip structure
- event loop helpers
- pub/sub
分享到:
相关推荐
redis:7.0.8 docker镜像
docker 镜像 redis:7.0.15
Redis:6.2.7版本的配置文件redis.conf
它没有网络模块,因此您可以自由配置自己的模块,也可以使用默认模块( )例cpp_redis :: client cpp_redis::client client;client.connect();client.set( " hello " , " 42 " );client.get( " hello " , [](cpp_...
ubuntu下docker安装redis:6.2.14
centos8 的Docker redis:7.2资源包
Redis-sentinel是Redis的作者antirez完成的,因为Redis实例在各个大公司的应用,每个公司都需要一个Redis集群的管理工具,被迫都自己写管理工具来管理Redis集群,antirez考虑到社区的急迫需要(详情),花了几个星期写...
接下来,我们需要编译和安装 Redis: `make install` 这将将 Redis 编译并安装到系统中。 配置 Redis 安装完成后,我们需要配置 Redis,以便它能够正确地运行。我们需要修改 `redis.conf` 文件,以添加密码认证...
使用redis:encode/1函数以Redis数据格式编码Erlang术语: % integer redis : encode ( 1 ). % simple string redis : encode (<< " test " >>). % bulk string redis : encode ({ bulk_string , << " ...
安装npm install --save keyv ioredis @microlink/keyv-redis用法const Keyv = require ( 'keyv' )const keyv = new Keyv ( 'redis://user:pass@localhost:6379' ) 任何有效的选项都将直接通过。 const keyv = new ...
docker镜像redis:latest,离线加载包 放到这里方便大家使用 亲测这个redis镜像非常好用 下载后请先解压,解压密码123456789,获得redis.tar文件 加载方式为 docker load -i redis.tar 非常方便
Redis 是一个高性能的键值对数据库,常被用于构建数据缓存、消息队列和数据库。在Linux系统中,Redis的安装通常涉及下载源码、编译和配置等步骤。这里我们将详细介绍如何处理"最新版linux redis-6.2.1.tar.gz"这个...
Redis命名空间Redis的::命名空间提供了一个接口,您的命名空间的子集密钥空间(例如,具有共同的开始键),并要求宝石。 require 'redis-namespace'# => trueredis_connection = Redis . new# => #<Redis>namespaced...
Redis 6.2.1 现已发布,该版本升级迫切性程度为低:修复了编译问题。具体更新内容如下: Bug 修复 修复带有已删除记录的 stream 的 sanitize-dump-payload(#8568) 防止将 client-query-buffer-limit 配置设置为...
独库redis dokku 的官方 redis 插件。 当前默认安装 。...redis:backup <service> <bucket> [--use-iam] # creates a backup of the redis service to an existing s3 bucket redis:backup-auth <service>
redis:6.0.4镜像
wallproxy Errno 10054 解决方法
Maven坐标:org.springframework.data:spring-data-redis:2.0.9.RELEASE; 标签:springframework、data、spring、redis、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”...
它没有网络模块,因此您可以自由配置自己的模块,也可以使用默认模块( )例cpp_redis :: client cpp_redis::client client;client.connect();client.set( " hello " , " 42 " );client.get( " hello " , [](cpp_...
Redis 是一个开源的内存数据结构存储系统,常被用作数据库、缓存和消息代理。在Windows环境下,Redis 的安装和使用与在Linux系统中有所不同。这里我们将详细讨论Windows版Redis 5.0.14的相关知识点。 1. **Redis ...