Reputation: 308
Suppose in redis, there are the following key-value pairs of type string : key1 val1 key2 val2 I know that they are stored internally in table.
Are these key-value pairs stored in one single table? or are there different tables for each key-value pair?
i.e., does only a single table contain both the key-value pairs or does one table store key1-val1 and another table store key2-val2?
Upvotes: 3
Views: 2434
Reputation: 578
There is only one single table for all key-value pairs in the same Redis DB.
Actually, key-value pair is stored in a big hash table.
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;
All key-value pairs are stored in dict.
Upvotes: 5