{"id":17081677,"url":"https://github.com/yongman/redis-cluster","last_synced_at":"2026-04-24T21:31:36.547Z","repository":{"id":68263567,"uuid":"86429898","full_name":"yongman/redis-cluster","owner":"yongman","description":null,"archived":false,"fork":false,"pushed_at":"2017-09-28T06:34:40.000Z","size":8800,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"hotreload","last_synced_at":"2025-06-13T04:39:43.479Z","etag":null,"topics":["hot-reload","hot-update","hotfix","redis","redis-cluster","redis-database","redis-distribution","redis-server"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yongman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING","funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-28T07:42:22.000Z","updated_at":"2019-03-20T01:15:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b7834b1-c6a2-41d9-b45b-5eaa84487a6d","html_url":"https://github.com/yongman/redis-cluster","commit_stats":null,"previous_names":[],"tags_count":157,"template":false,"template_full_name":null,"purl":"pkg:github/yongman/redis-cluster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongman%2Fredis-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongman%2Fredis-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongman%2Fredis-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongman%2Fredis-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yongman","download_url":"https://codeload.github.com/yongman/redis-cluster/tar.gz/refs/heads/hotreload","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yongman%2Fredis-cluster/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32241576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hot-reload","hot-update","hotfix","redis","redis-cluster","redis-database","redis-distribution","redis-server"],"created_at":"2024-10-14T12:55:37.439Z","updated_at":"2026-04-24T21:31:36.532Z","avatar_url":"https://github.com/yongman.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"This README is just a fast *quick start* document. You can find more detailed documentation at http://redis.io.\n\nWhat is Redis?\n--------------\n\nRedis is often referred as a *data structures* server. What this means is that Redis provides access to mutable data structures via a set of commands, which are sent using a *server-client* model with TCP sockets and a simple protocol. So different processes can query and modify the same data structures in a shared way.\n\nData structures implemented into Redis have a few special properties:\n\n* Redis cares to store them on disk, even if they are always served and modified into the server memory. This means that Redis is fast, but that is also non-volatile.\n* Implementation of data structures stress on memory efficiency, so data structures inside Redis will likely use less memory compared to the same data structure modeled using an high level programming language.\n* Redis offers a number of features that are natural to find in a database, like replication, tunable levels of durability, cluster, high availability.\n\nAnother good example is to think of Redis as a more complex version of memcached, where the operations are not just SETs and GETs, but operations to work with complex data types like Lists, Sets, ordered data structures, and so forth.\n\nIf you want to know more, this is a list of selected starting points:\n\n* Introduction to Redis data types. http://redis.io/topics/data-types-intro\n* Try Redis directly inside your browser. http://try.redis.io\n* The full list of Redis commands. http://redis.io/commands\n* There is much more inside the Redis official documentation. http://redis.io/documentation\n\nBuilding Redis\n--------------\n\nRedis can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD.\nWe support big endian and little endian architectures, and both 32 bit\nand 64 bit systems.\n\nIt may compile on Solaris derived systems (for instance SmartOS) but our\nsupport for this platform is *best effort* and Redis is not guaranteed to\nwork as well as in Linux, OSX, and \\*BSD there.\n\nIt is as simple as:\n\n    % make\n\nYou can run a 32 bit Redis binary using:\n\n    % make 32bit\n\nAfter building Redis, it is a good idea to test it using:\n\n    % make test\n\nFixing build problems with dependencies or cached build options\n---------\n\nRedis has some dependencies which are included into the `deps` directory.\n`make` does not automatically rebuild dependencies even if something in\nthe source code of dependencies changes.\n\nWhen you update the source code with `git pull` or when code inside the\ndependencies tree is modified in any other way, make sure to use the following\ncommand in order to really clean everything and rebuild from scratch:\n\n    make distclean\n\nThis will clean: jemalloc, lua, hiredis, linenoise.\n\nAlso if you force certain build options like 32bit target, no C compiler\noptimizations (for debugging purposes), and other similar build time options,\nthose options are cached indefinitely until you issue a `make distclean`\ncommand.\n\nFixing problems building 32 bit binaries\n---------\n\nIf after building Redis with a 32 bit target you need to rebuild it\nwith a 64 bit target, or the other way around, you need to perform a\n`make distclean` in the root directory of the Redis distribution.\n\nIn case of build errors when trying to build a 32 bit binary of Redis, try\nthe following steps:\n\n* Install the packages libc6-dev-i386 (also try g++-multilib).\n* Try using the following command line instead of `make 32bit`:\n  `make CFLAGS=\"-m32 -march=native\" LDFLAGS=\"-m32\"`\n\nAllocator\n---------\n\nSelecting a non-default memory allocator when building Redis is done by setting\nthe `MALLOC` environment variable. Redis is compiled and linked against libc\nmalloc by default, with the exception of jemalloc being the default on Linux\nsystems. This default was picked because jemalloc has proven to have fewer\nfragmentation problems than libc malloc.\n\nTo force compiling against libc malloc, use:\n\n    % make MALLOC=libc\n\nTo compile against jemalloc on Mac OS X systems, use:\n\n    % make MALLOC=jemalloc\n\nVerbose build\n-------------\n\nRedis will build with a user friendly colorized output by default.\nIf you want to see a more verbose output use the following:\n\n    % make V=1\n\nRunning Redis\n-------------\n\nTo run Redis with the default configuration just type:\n\n    % cd src\n    % ./redis-server\n\nIf you want to provide your redis.conf, you have to run it using an additional\nparameter (the path of the configuration file):\n\n    % cd src\n    % ./redis-server /path/to/redis.conf\n\nIt is possible to alter the Redis configuration by passing parameters directly\nas options using the command line. Examples:\n\n    % ./redis-server --port 9999 --slaveof 127.0.0.1 6379\n    % ./redis-server /etc/redis/6379.conf --loglevel debug\n\nAll the options in redis.conf are also supported as options using the command\nline, with exactly the same name.\n\nPlaying with Redis\n------------------\n\nYou can use redis-cli to play with Redis. Start a redis-server instance,\nthen in another terminal try the following:\n\n    % cd src\n    % ./redis-cli\n    redis\u003e ping\n    PONG\n    redis\u003e set foo bar\n    OK\n    redis\u003e get foo\n    \"bar\"\n    redis\u003e incr mycounter\n    (integer) 1\n    redis\u003e incr mycounter\n    (integer) 2\n    redis\u003e\n\nYou can find the list of all the available commands at http://redis.io/commands.\n\nInstalling Redis\n-----------------\n\nIn order to install Redis binaries into /usr/local/bin just use:\n\n    % make install\n\nYou can use `make PREFIX=/some/other/directory install` if you wish to use a\ndifferent destination.\n\nMake install will just install binaries in your system, but will not configure\ninit scripts and configuration files in the appropriate place. This is not\nneeded if you want just to play a bit with Redis, but if you are installing\nit the proper way for a production system, we have a script doing this\nfor Ubuntu and Debian systems:\n\n    % cd utils\n    % ./install_server.sh\n\nThe script will ask you a few questions and will setup everything you need\nto run Redis properly as a background daemon that will start again on\nsystem reboots.\n\nYou'll be able to stop and start Redis using the script named\n`/etc/init.d/redis_\u003cportnumber\u003e`, for instance `/etc/init.d/redis_6379`.\n\nCode contributions\n-----------------\n\nNote: by contributing code to the Redis project in any form, including sending\na pull request via Github, a code fragment or patch via private email or\npublic discussion groups, you agree to release your code under the terms\nof the BSD license that you can find in the [COPYING][1] file included in the Redis\nsource distribution.\n\nPlease see the [CONTRIBUTING][2] file in this source distribution for more\ninformation.\n\n[1]: https://github.com/antirez/redis/blob/unstable/COPYING\n[2]: https://github.com/antirez/redis/blob/unstable/CONTRIBUTING\n\nRedis internals\n===\n\nIf you are reading this README you are likely in front of a Github page\nor you just untarred the Redis distribution tar ball. In both the cases\nyou are basically one step away from the source code, so here we explain\nthe Redis source code layout, what is in each file as a general idea, the\nmost important functions and structures inside the Redis server and so forth.\nWe keep all the discussion at a high level without digging into the details\nsince this document would be huge otherwise and our code base changes\ncontinuously, but a general idea should be a good starting point to\nunderstand more. Moreover most of the code is heavily commented and easy\nto follow.\n\nSource code layout\n---\n\nThe Redis root directory just contains this README, the Makefile which\ncalls the real Makefile inside the `src` directory and an example\nconfiguration for Redis and Sentinel. You can find a few shell\nscripts that are used in order to execute the Redis, Redis Cluster and\nRedis Sentinel unit tests, which are implemented inside the `tests`\ndirectory.\n\nInside the root are the following important directories:\n\n* `src`: contains the Redis implementation, written in C.\n* `tests`: contains the unit tests, implemented in Tcl.\n* `deps`: contains libraries Redis uses. Everything needed to compile Redis is inside this directory; your system just needs to provide `libc`, a POSIX compatible interface and a C compiler. Notably `deps` contains a copy of `jemalloc`, which is the default allocator of Redis under Linux. Note that under `deps` there are also things which started with the Redis project, but for which the main repository is not `anitrez/redis`. An exception to this rule is `deps/geohash-int` which is the low level geocoding library used by Redis: it originated from a different project, but at this point it diverged so much that it is developed as a separated entity directly inside the Redis repository.\n\nThere are a few more directories but they are not very important for our goals\nhere. We'll focus mostly on `src`, where the Redis implementation is contained,\nexploring what there is inside each file. The order in which files are\nexposed is the logical one to follow in order to disclose different layers\nof complexity incrementally.\n\nNote: lately Redis was refactored quite a bit. Function names and file\nnames have been changed, so you may find that this documentation reflects the\n`unstable` branch more closely. For instance in Redis 3.0 the `server.c`\nand `server.h` files were named to `redis.c` and `redis.h`. However the overall\nstructure is the same. Keep in mind that all the new developments and pull\nrequests should be performed against the `unstable` branch.\n\nserver.h\n---\n\nThe simplest way to understand how a program works is to understand the\ndata structures it uses. So we'll start from the main header file of\nRedis, which is `server.h`.\n\nAll the server configuration and in general all the shared state is\ndefined in a global structure called `server`, of type `struct redisServer`.\nA few important fields in this structure are:\n\n* `server.db` is an array of Redis databases, where data is stored.\n* `server.commands` is the command table.\n* `server.clients` is a linked list of clients connected to the server.\n* `server.master` is a special client, the master, if the instance is a slave.\n\nThere are tons of other fields. Most fields are commented directly inside\nthe structure definition.\n\nAnother important Redis data structure is the one defining a client.\nIn the past it was called `redisClient`, now just `client`. The structure\nhas many fields, here we'll just show the main ones:\n\n    struct client {\n        int fd;\n        sds querybuf;\n        int argc;\n        robj **argv;\n        redisDb *db;\n        int flags;\n        list *reply;\n        char buf[PROTO_REPLY_CHUNK_BYTES];\n        ... many other fields ...\n    }\n\nThe client structure defines a *connected client*:\n\n* The `fd` field is the client socket file descriptor.\n* `argc` and `argv` are populated with the command the client is executing, so that functions implementing a given Redis command can read the arguments.\n* `querybuf` accumulates the requests from the client, which are parsed by the Redis server according to the Redis protocol and executed by calling the implementations of the commands the client is executing.\n* `reply` and `buf` are dynamic and static buffers that accumulate the replies the server sends to the client. These buffers are incrementally written to the socket as soon as the file descriptor is writable.\n\nAs you can see in the client structure above, arguments in a command\nare described as `robj` structures. The following is the full `robj`\nstructure, which defines a *Redis object*:\n\n    typedef struct redisObject {\n        unsigned type:4;\n        unsigned encoding:4;\n        unsigned lru:LRU_BITS; /* lru time (relative to server.lruclock) */\n        int refcount;\n        void *ptr;\n    } robj;\n\nBasically this structure can represent all the basic Redis data types like\nstrings, lists, sets, sorted sets and so forth. The interesting thing is that\nit has a `type` field, so that it is possible to know what type a given\nobject has, and a `refcount`, so that the same object can be referenced\nin multiple places without allocating it multiple times. Finally the `ptr`\nfield points to the actual representation of the object, which might vary\neven for the same type, depending on the `encoding` used.\n\nRedis objects are used extensively in the Redis internals, however in order\nto avoid the overhead of indirect accesses, recently in many places\nwe just use plain dynamic strings not wrapped inside a Redis object.\n\nserver.c\n---\n\nThis is the entry point of the Redis server, where the `main()` function\nis defined. The following are the most important steps in order to startup\nthe Redis server.\n\n* `initServerConfig()` setups the default values of the `server` structure.\n* `initServer()` allocates the data structures needed to operate, setup the listening socket, and so forth.\n* `aeMain()` starts the event loop which listens for new connections.\n\nThere are two special functions called periodically by the event loop:\n\n1. `serverCron()` is called periodically (according to `server.hz` frequency), and performs tasks that must be performed from time to time, like checking for timedout clients.\n2. `beforeSleep()` is called every time the event loop fired, Redis served a few requests, and is returning back into the event loop.\n\nInside server.c you can find code that handles other vital things of the Redis server:\n\n* `call()` is used in order to call a given command in the context of a given client.\n* `activeExpireCycle()` handles eviciton of keys with a time to live set via the `EXPIRE` command.\n* `freeMemoryIfNeeded()` is called when a new write command should be performed but Redis is out of memory according to the `maxmemory` directive.\n* The global variable `redisCommandTable` defines all the Redis commands, specifying the name of the command, the function implementing the command, the number of arguments required, and other properties of each command.\n\nnetworking.c\n---\n\nThis file defines all the I/O functions with clients, masters and slaves\n(which in Redis are just special clients):\n\n* `createClient()` allocates and initializes a new client.\n* the `addReply*()` family of functions are used by commands implementations in order to append data to the client structure, that will be transmitted to the client as a reply for a given command executed.\n* `writeToClient()` transmits the data pending in the output buffers to the client and is called by the *writable event handler* `sendReplyToClient()`.\n* `readQueryFromClient()` is the *readable event handler* and accumulates data from read from the client into the query buffer.\n* `processInputBuffer()` is the entry point in order to parse the client query buffer according to the Redis protocol. Once commands are ready to be processed, it calls `processCommand()` which is defined inside `server.c` in order to actually execute the command.\n* `freeClient()` deallocates, disconnects and removes a client.\n\naof.c and rdb.c\n---\n\nAs you can guess from the names these files implement the RDB and AOF\npersistence for Redis. Redis uses a persistence model based on the `fork()`\nsystem call in order to create a thread with the same (shared) memory\ncontent of the main Redis thread. This secondary thread dumps the content\nof the memory on disk. This is used by `rdb.c` to create the snapshots\non disk and by `aof.c` in order to perform the AOF rewrite when the\nappend only file gets too big.\n\nThe implementation inside `aof.c` has additional functions in order to\nimplement an API that allows commands to append new commands into the AOF\nfile as clients execute them.\n\nThe `call()` function defined inside `server.c` is responsible to call\nthe functions that in turn will write the commands into the AOF.\n\ndb.c\n---\n\nCertain Redis commands operate on specific data types, others are general.\nExamples of generic commands are `DEL` and `EXPIRE`. They operate on keys\nand not on their values specifically. All those generic commands are\ndefined inside `db.c`.\n\nMoreover `db.c` implements an API in order to perform certain operations\non the Redis dataset without directly accessing the internal data structures.\n\nThe most important functions inside `db.c` which are used in many commands\nimplementations are the following:\n\n* `lookupKeyRead()` and `lookupKeyWrite()` are used in order to get a pointer to the value associated to a given key, or `NULL` if the key does not exist.\n* `dbAdd()` and its higher level counterpart `setKey()` create a new key in a Redis database.\n* `dbDelete()` removes a key and its associated value.\n* `emptyDb()` removes an entire single database or all the databases defined.\n\nThe rest of the file implements the generic commands exposed to the client.\n\nobject.c\n---\n\nThe `robj` structure defining Redis objects was already described. Inside\n`object.c` there are all the functions that operate with Redis objects at\na basic level, like functions to allocate new objects, handle the reference\ncounting and so forth. Notable functions inside this file:\n\n* `incrRefcount()` and `decrRefCount()` are used in order to increment or decrement an object reference count. When it drops to 0 the object is finally freed.\n* `createObject()` allocates a new object. There are also specialized functions to allocate string objects having a specific content, like `createStringObjectFromLongLong()` and similar functions.\n\nThis file also implements the `OBJECT` command.\n\nreplication.c\n---\n\nThis is one of the most complex files inside Redis, it is recommended to\napproach it only after getting a bit familiar with the rest of the code base.\nIn this file there is the implementation of both the master and slave role\nof Redis.\n\nOne of the most important functions inside this file is `replicationFeedSlaves()` that writes commands to the clients representing slave instances connected\nto our master, so that the slaves can get the writes performed by the clients:\nthis way their data set will remain synchronized with the one in the master.\n\nThis file also implements both the `SYNC` and `PSYNC` commands that are\nused in order to perform the first synchronization between masters and\nslaves, or to continue the replication after a disconnection.\n\nOther C files\n---\n\n* `t_hash.c`, `t_list.c`, `t_set.c`, `t_string.c` and `t_zset.c` contains the implementation of the Redis data types. They implement both an API to access a given data type, and the client commands implementations for these data types.\n* `ae.c` implements the Redis event loop, it's a self contained library which is simple to read and understand.\n* `sds.c` is the Redis string library, check http://github.com/antirez/sds for more information.\n* `anet.c` is a library to use POSIX networking in a simpler way compared to the raw interface exposed by the kernel.\n* `dict.c` is an implementation of a non-blocking hash table which rehashes incrementally.\n* `scripting.c` implements Lua scripting. It is completely self contained from the rest of the Redis implementation and is simple enough to understand if you are familar with the Lua API.\n* `cluster.c` implements the Redis Cluster. Probably a good read only after being very familiar with the rest of the Redis code base. If you want to read `cluster.c` make sure to read the [Redis Cluster specification][3].\n\n[3]: http://redis.io/topics/cluster-spec\n\nAnatomy of a Redis command\n---\n\nAll the Redis commands are defined in the following way:\n\n    void foobarCommand(client *c) {\n        printf(\"%s\",c-\u003eargv[1]-\u003eptr); /* Do something with the argument. */\n        addReply(c,shared.ok); /* Reply something to the client. */\n    }\n\nThe command is then referenced inside `server.c` in the command table:\n\n    {\"foobar\",foobarCommand,2,\"rtF\",0,NULL,0,0,0,0,0},\n\nIn the above example `2` is the number of arguments the command takes,\nwhile `\"rtF\"` are the command flags, as documented in the command table\ntop comment inside `server.c`.\n\nAfter the command operates in some way, it returns a reply to the client,\nusually using `addReply()` or a similar function defined inside `networking.c`.\n\nThere are tons of commands implementations inside th Redis source code\nthat can serve as examples of actual commands implementations. To write\na few toy commands can be a good exercise to familiarize with the code base.\n\nThere are also many other files not described here, but it is useless to\ncover everything. We want to just help you with the first steps.\nEventually you'll find your way inside the Redis code base :-)\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyongman%2Fredis-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyongman%2Fredis-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyongman%2Fredis-cluster/lists"}