A ing method between RDBMS database tables and Redis models, rdbmsredis

Source: Internet
Author: User
Tags aerospike

A ing method between RDBMS database tables and Redis models, rdbmsredis

Some time ago, in the selection of memory databases, there was still a gap between Aerospike and Redis. Because Redis has already had many successful cases in the industry, and domestic Internet giants are also using BAT, and there are also a wide range of online resources. Aerospike is just open-source, in terms of application cases and technical resources, this is the case.

During this period of migration, I also read a lot of online technical documents of Redis and some open-source ORM implementations, and briefly summarized the ing Between Relational Database Service (RDBMS) tables and Redis models, the record is forgotten here.


Because Redis is only a simple Key-Value storage system and does not have the table and index concepts in RDBMS, You need to implement access to the original database table model in Redis, there must be a transformation method for the model, that is, the ing method between the models. The table and index concepts in RDBMS must be converted into Redis Key-Value objects.

In the following ing method description, the premise is that the relational database model uses a sequence of non-business meaning values as the primary key. This may not match the actual situation and needs to be adjusted as needed. Using numeric values as the primary key mainly aims to save the memory usage of Redis model index data. The memory can save a little bit, and there is no surplus grain in the landlord's house.

All Key-Value creation and maintenance in the Redis model, including the Key-Value creation and maintenance for the corresponding RDBMS table index, and the uniqueness guarantee of the unique index, are completed by the application itself, redis only stores data.


Table Model

In addition, all Key-Value creation and maintenance in the Redis model, including Key-Value creation and maintenance corresponding to the index of the RDBMS database and table, as well as the unique guarantee of the unique index, it is done by the application itself, and Redis is only responsible for data storage.


Table Model

  • RDBMS table model


  • Redis Model
    The RDBMS model in is converted to the Redis model. The Key-Value values are described as follows:

    Key

    Value

    Remarks

    Type

    Value description

    Tab: id

    STRING

    Integer string

    Table Primary Key tab_id value source

    Key name rules:Table Name: Id

    The initial value is 0. Call the INCR command and Add 1 before each new record.

    Tab:Tab_id Value

    HASH

    Column name/column value HASHMAP

    Storage Structure of column values except primary keys for each record in the master table

    Key name rules:Table Name:Record primary key value


  • Example
    For example, the data of the table emp and the data converted into the Redis model are as follows:

    Emp_id

    Ename

    Mgr_id

    1

    SMITH

    8

    2

    ALLEN

    8

    3

    SALESMAN

    7


    Key name

    Value

    Emp: id

    3

    Emp: 1

    {Ename = "SMITH", mgr_id = "8 "}

    Emp: 2

    {Ename = "ALLEN", mgr_id = "8 "}

    Emp: 3

    {Ename = "SALESMAN", mgr_id = "7 "}


Non-unique single-column Index Model

  • RDBMS table model

    The table has a non-unique index on col_idx.

  • Redis Model
    The RDBMS index in the model is converted to the Redis model. The Key-Value values related to the index are described as follows:

    Key

    Value

    Remarks

    Type

    Value description

    Tab: indices: col_idx:Col_idx Value

    SET

    The values of all col_idx columns are equalCol_idx ValueSet of primary key values of the record

    Key-value pairs corresponding to the non-unique index column col_idx In the table

    Key name rules:Table Name: Idices:Index column name:Index column Value

    There may be multiple key-value pairs, and each index column value corresponds to one


  • Example
    For example, the table emp has a non-unique index on mgr_id. The table data and the data converted to the Redis model are as follows:

    Emp_id

    Ename

    Mgr_id

    1

    SMITH

    8

    2

    ALLEN

    8

    3

    SALESMAN

    7


    Key name

    Value

    Emp: id

    3

    Emp: 1

    {Ename = "SMITH", mgr_id = "8 "}

    Emp: 2

    {Ename = "ALLEN", mgr_id = "8 "}

    Emp: 3

    {Ename = "SALESMAN", mgr_id = "7 "}

    Emp: indices: mgr_id: 7

    (3)

    Emp: indices: mgr_id: 8

    (1, 2)


Unique Single Column Index Model

  • RDBMS table model

    The table has a unique index on the column col_uniq.

  • Redis Model

    The RDBMS index in the model is converted to the Redis model. The Key-Value values related to the index are described as follows:

    Key

    Value

    Remarks

    Type

    Value description

    Tab: uniques: col_uniq

    HASH

    Col_uniq column value/corresponding record primary key value

    Key-value pairs corresponding to the non-unique index column col_idx In the table

    Key name rules:Table Name: Uniques:Index column name


  • Example
    For example, the table emp has a unique index on email. The table data and the data converted to the Redis model are as follows:

    Emp_id

    Ename

    Email

    1

    SMITH

    Foo@gmail.com

    2

    ALLEN

    Bar@163.com

    3

    SALESMAN

    Zoo@hotmail.com


    Key name

    Value

    Emp: id

    3

    Emp: 1

    {Ename = "SMITH", email = "foo@gmail.com "}

    Emp: 2

    {Ename = "ALLEN", email = "bar@163.com "}

    Emp: 3

    {Ename = "SALESMAN", email = "zoo@hotmail.com "}

    Emp: uniques: email

    {Foo@gmail.com = "1", bar@163.com = "2 ",

     

    Zoo@hotmail.com = "3"


(Not) unique multi-Column Composite Index Model

  • RDBMS table model

    The table has a non-unique composite index on col_idx1 and col_idx2 columns,
    A unique composite index is created on col_uniq1 and col_uniq2 columns.

  • Redis Model
    The index in the model is converted to the Redis model. The Key-Value values related to the index are described as follows:

    Key

    Value

    Remarks

    Type

    Value description

    Tab: indices: col_idx1:Col_idx1 Value: Col_idx2:Col_idx2 Value

    SET

    A set of primary key values of all records that meet the index column value conditions

    Key-value pairs of non-unique index columns col_idx1 and col_idx2

    Key name rules:Table Name: Idices:Index column 1 Name:Index column 1 Value:Index Column 2 Name:Index Column 2 value:

    There may be multiple key-value pairs, and each group of index columns corresponds to one

    Tab: uniques: col_uniq1: col_uniq2

    HASH

    Col_uniq1 column value, col_uniq2 column value combination/corresponding record primary key value

    Key-value pairs for non-unique index columns col_uniq1 and col_uniq2

    Key name rules:Table Name: Uniques:Index column 1 Name:Index Column 2 Name


  • In fact, the (non) unique multi-Column Composite index is not necessary. It can be replaced by creating a non-unique single-column index for each column in the composite index, because non-unique single-column indexes use SET (SET), all conditional queries on the composite index can be converted into SET operations to achieve SUNION, SDIFF, SINTER, etc.

Association (one-to-many/one-to-one)

  • RDBMS table model


  • Redis Model
    The parent table does not need special processing. The child table is associated with the parent_id column of the parent table as a non-unique index. For more information, see the non-unique Single Column index model.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.