【问题标题】:How are key-value pairs stored in redis?redis中键值对是如何存储的?
【发布时间】:2015-02-11 16:18:17
【问题描述】:

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

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

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

【问题讨论】:

    标签: redis


    【解决方案1】:

    同一个 Redis DB 中的所有键值对只有一张表。

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

    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;
    

    所有键值对都存储在dict中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 2022-08-05
      相关资源
      最近更新 更多