redis/redis
Other primitives
A grab-bag of smaller, self-contained data structures and utilities used across the codebase. Most are < 5 KB of source.
Generic structures
| Primitive | Source | Purpose |
|---|---|---|
| Linked list | src/adlist.c, src/adlist.h |
Doubly-linked list. Used for client lists, blocked client queues, deferred reply chunks. |
| Mstr | src/mstr.c, src/mstr.h |
Variable-length micro-strings used by entry.c (hash field+value with optional TTL). |
| Entry | src/entry.c, src/entry.h |
Field/value pair used by hash field expiration. |
| Fenwick tree | src/fwtree.c, src/fwtree.h |
Binary indexed tree used for hot-key tracking and a few percentile estimations. |
| Sparkline | src/sparkline.c, src/sparkline.h |
ASCII sparkline used by LATENCY GRAPH. |
| Vector | src/vector.c, src/vector.h |
Generic dynamic array. |
| Pqsort | src/pqsort.c, src/pqsort.h |
Partial qsort — sort just the K smallest/largest elements, used by SORT LIMIT. |
| Sort | src/sort.c |
The SORT and SORT_RO command implementation. |
Time and randomness
| Primitive | Source | Purpose |
|---|---|---|
| Monotonic time | src/monotonic.c, src/monotonic.h |
Wraps clock_gettime(CLOCK_MONOTONIC) with a fast getter cached per cron tick. |
| Local time | src/localtime.c |
Async-signal-safe gmtime_r/localtime_r for the crash handler. |
| Random | src/rand.c, src/rand.h, src/mt19937-64.c |
Pseudo-random generators. mt19937 is used where reproducibility matters; rand is used for general randomness. |
Crypto / hashing
| Primitive | Source | Purpose |
|---|---|---|
| SHA1 | src/sha1.c, src/sha1.h |
Used by SCRIPT LOAD to hash scripts and by some auth paths. |
| SHA256 | src/sha256.c, src/sha256.h |
Used to hash ACL passwords. |
| SipHash | src/siphash.c |
The default hash for dict. Seeded at startup. |
| CRC64 | src/crc64.c, src/crc64.h, src/crcspeed.c, src/crccombine.c |
Checksum for RDB files. |
| CRC16 | src/crc16.c, src/crc16_slottable.h |
Cluster slot computation (CRC16(key) % 16384). |
Compression
| Primitive | Source | Purpose |
|---|---|---|
| LZF | src/lzf_c.c, src/lzf_d.c, src/lzf.h, src/lzfP.h |
Compresses RDB strings (rdbcompression yes) and middle quicklist nodes. |
Numbers
| Primitive | Source | Purpose |
|---|---|---|
| Fast float strtod | src/fast_float_strtod.c, src/fast_float_strtod.h |
A heavily-optimised float parser used by command-argument parsing (ZADD scores, SET EX, …). Replaces the slower libc strtod. |
| Util | src/util.c, src/util.h |
String parsing (string2ll, string2ld, ld2string, getRandomBytes, glob match). |
| Strl | src/strl.c |
strlcpy/strlcat portability shim. |
| Endianconv | src/endianconv.c, src/endianconv.h |
Endianness helpers for RDB cross-platform compatibility. |
Misc subsystems
| Primitive | Source | Purpose |
|---|---|---|
| Hot keys | src/hotkeys.c, src/keymeta.h |
Tracks the most-accessed keys via reservoir sampling, surfaced via OBJECT FREQ and --hotkeys. |
| Estore | src/estore.c, src/estore.h |
Per-DB expiration store wrapping ebuckets. See Expiration. |
| Keymeta | src/keymeta.c, src/keymeta.h |
Per-key metadata: minimum hash-field TTL, plus extension points. |
| Hyperloglog | src/hyperloglog.c |
Probabilistic cardinality counter. |
| GCRA | src/gcra.c |
Generic Cell Rate Algorithm. Token-bucket primitive used internally and exposed via GCRA* commands. |
| Geohash | src/geohash.c, src/geohash_helper.c, src/geo.c |
Geospatial encoding (52-bit interleaved coordinates) plus radius/box queries. |
| Bio | src/bio.c, src/bio.h |
Background IO threads (close fd, fsync, lazy free). See Memory management. |
| Threads manager | src/threads_mngr.c, src/threads_mngr.h |
Cross-thread stack capture. Used by the watchdog and DEBUG STACK-TRACE. |
| Memtest | src/memtest.c |
RAM consistency test invoked by the crash handler and --test-memory. |
| Setproctitle | src/setproctitle.c |
Portable setproctitle(3) replacement. |
| Setcpuaffinity | src/setcpuaffinity.c |
Portable affinity setter for server-cpulist / bio-cpulist etc. |
| Syscheck | src/syscheck.c, src/syscheck.h |
Startup checks for the OS (transparent huge pages, swap, atomic ops). Surfaces warnings in the log. |
| Childinfo | src/childinfo.c |
Pipe-based child→parent communication for COW accounting. |
| Memory prefetch | src/memory_prefetch.c, src/memory_prefetch.h |
Software prefetching used in dict lookups to hide L1/L2 latency. |
| Logreqres | src/logreqres.c |
When built with LOG_REQ_RES, captures every request/reply pair to JSON for schema validation. |
These primitives are deliberately small and self-contained. Most can be grokked in a single read of their .c and .h.
Where to start
- Add a hashing function — pattern after
siphash.c. Register on adictType. - Add a benchmark utility —
redis-benchmark.cis the right host for synthetic load tests. - Add a system check —
src/syscheck.cruns at startup and logs warnings; extend the table.
Related pages
- Persistence — uses CRC64, LZF.
- Cluster — uses CRC16.
- Memory management — uses bio threads.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.