4.3. TablesΒΆ

A table represents a permanent or temporary set of records. Table are not always public, they can also be intermediately steps during a query. This module provides ways to manipulate tables - abstracted away from Redis.

Tables are stored in Redis as a sorted set. Where the score is an integer representing the record ID. This presents two problems:

  1. Scores in Redis are not required to be unique so it’s possible to add a record with the same score making it very difficult to remove or manipulate a single record.
  2. Values (the raw JSON records) must be unique in Redis. It is quite possible for records to contain the same data.

To get around both of those issues we set some basic rules for how tables are stored:

  1. Each table has a separate associated key in Redis that acts as a incrementer to provide guaranteed unique scores for each row. This is incremented as it’s needed. However, the table does not need to have a continuous set of IDs (such as when records are removed the IDs will also be removed forever.)

  2. Each of the records includes a secret key that contains the record ID. For example the following record:

    123 -> {"foo": "bar"}
    

    Is actually stored internally as:

    123 -> {":id": 123, "foo": "bar"}
    

    This guarantees that the records are unique and also means that the scores do not need to be retrieved when records are iterated.