redis - Redis 中的键值对是如何存储的?

标签 redis

假设在redis中,有以下字符串类型的键值对: 键1 值1 键2 值2 我知道它们内部存储在表中。

这些键值对是否存储在一个表中? 还是每个键值对都有不同的表?

即,是只有一个表包含两个键值对,还是一个表存储 key1-val1 而另一个表存储 key2-val2?

最佳答案

在同一个 Redis 数据库中,所有键值对只有一张表。

实际上,键值对存储在一个大的哈希表中。

https://github.com/antirez/redis/blob/unstable/src/redis.h#L469

/* Redis database representation. There are multiple databases identified
* by integers from 0 (the default database) up to the max configured
* database. The database number is the 'id' field in the structure. */
typedef struct redisDb {
    dict *dict;                 /* The keyspace for this DB */
    dict *expires;              /* Timeout of keys with a timeout set */
    dict *blocking_keys;        /* Keys with clients waiting for data (BLPOP) */
    dict *ready_keys;           /* Blocked keys that received a PUSH */
    dict *watched_keys;         /* WATCHED keys for MULTI/EXEC CAS */
    struct evictionPoolEntry *eviction_pool;    /* Eviction pool of keys */
    int id;                     /* Database ID */
    long long avg_ttl;          /* Average TTL, just for stats */
} redisDb;

所有键值对都存储在字典中。

关于redis - Redis 中的键值对是如何存储的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28449106/

相关文章:

redis - 基于其成员的特定哈希值的查询集

java - Jedis - 简单程序缺少 HostPort 类

node.js - 为棋盘游戏 session 数据保留数据时,redisJSON 是否比普通 redis 更好?

database - Yii2 + Redis 作为数据库

Python Redis 交互

ruby-on-rails - 使用 redis 作为 rails 应用程序的数据库来处理大量 api 请求

redis - StackExchange.Redis 事务方法卡住

redis - 如何在Redis v2.4.6中使Redis从站只读?

symfony - 如何在 Symfony 应用程序中为 Doctrine 配置 Redis 缓存

c# - 使用 ServiceStack.Redis C# .Net 在 Redis 服务器中从第 m 行到第 n 行搜索数据