Updated on 2025-01-03 GMT+08:00

Enabling and Using Memory Acceleration

Enable memory acceleration.

Step 1: Create a GeminiDB instance.

Step 2: Create a mapping rule.

Step 3: Use the memory acceleration module.

Precautions

  • After memory acceleration is enabled, commands such as RESET MASTER and FLUSH LOGS used to delete binlogs on MySQL instances are not allowed.
  • Currently, only hash data from MySQL can be converted to GeminiDB Redis API.
  • A Redis key prefix and a delimiter in a new rule can neither include those nor be included in those specified for an existing rule. For example, if the key prefix in a new rule is pre1: and is separated by a comma (,) and the key prefix in an existing rule is pre1 and is separated by a colon (:), the new rule cannot be created.
  • Currently, the ENUM, SET, and JSON data cannot be synchronized.

Procedure

Using the Memory Acceleration Module

  1. Create database db1 in the source MySQL instance and create table students in db1.
    mysql> CREATE DATABASE db1;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> CREATE TABLE db1.students(
           sid INT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL,
           sname VARCHAR(20),
           sclass INT,
           sgender VARCHAR(10),
           sbirthday DATE
           );
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> DESC db1.students;
    +-----------+--------------+------+-----+---------+----------------+
    | Field     | Type         | Null | Key | Default | Extra          |
    +-----------+--------------+------+-----+---------+----------------+
    | sid       | int unsigned | NO   | PRI | NULL    | auto_increment |
    | sname     | varchar(20)  | YES  |     | NULL    |                |
    | sclass    | int          | YES  |     | NULL    |                |
    | sgender   | varchar(10)  | YES  |     | NULL    |                |
    | sbirthday | date         | YES  |     | NULL    |                |
    +-----------+--------------+------+-----+---------+----------------+
    5 rows in set (0.00 sec)
  2. After the table is created, on the memory acceleration page, create a mapping rule to convert each row in the students table into a Redis hash. The key of a hash is in the format of Database name:Data table name:sid:<sid value>. The selected fields are sname, sclass, sgender, and sbirthday.
    Figure 8 Configuring a mapping rule
  3. After a mapping rule is created, check the mapping rule and information.
    Figure 9 Mapping information
  4. Insert a new data record to the students table in the MySQL instance.
    mysql> INSERT INTO db1.students (sname, sclass, sgender, sbirthday) VALUES ('zhangsan', 1, 'male', '2015-05-20');
    Query OK, 1 row affected (0.01 sec)
    
    mysql> SELECT * FROM db1.students;
    +-----+----------+--------+---------+------------+
    | sid | sname    | sclass | sgender | sbirthday  |
    +-----+----------+--------+---------+------------+
    |   1 | zhangsan |      1 | male    | 2015-05-20 |
    +-----+----------+--------+---------+------------+
    1 row in set (0.00 sec)
  5. After the mapping rule is created, the data is automatically synchronized to the GeminiDB instance. Run commands in the GeminiDB instance to query the data.
    127.0.0.1:6379> KEYS *
    1) "db1:students:sid:1"
    
    127.0.0.1:6379> HGETALL db1:students:sid:1
    1) "sbirthday"
    2) "2015-05-20"
    3) "sclass"
    4) "1"
    5) "sgender"
    6) "male"
    7) "sname"
    8) "zhangsan"
  6. Insert a new data record to the students table in the MySQL instance.
    mysql> INSERT INTO db1.students (sname, sclass, sgender, sbirthday) VALUES ('lisi', 10, 'male', '2015-05-22');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> SELECT * FROM db1.students;
    +-----+----------+--------+---------+------------+
    | sid | sname    | sclass | sgender | sbirthday  |
    +-----+----------+--------+---------+------------+
    |   1 | zhangsan |      1 | male    | 2015-05-20 |
    |   2 | lisi     |     10 | male    | 2015-05-22 |
    +-----+----------+--------+---------+------------+
    2 rows in set (0.00 sec)
  7. Check whether the new data is synchronized to the GeminiDB instance.
    127.0.0.1:6379> KEYS *
    1) "db1:students:sid:1"
    2) "db1:students:sid:2"
    
    127.0.0.1:6379> HGETALL db1:students:sid:2
    1) "sbirthday"
    2) "2015-05-22"
    3) "sclass"
    4) "10"
    5) "sgender"
    6) "male"
    7) "sname"
  8. Update data in the students table in the MySQL instance.
    mysql> UPDATE db1.students SET sclass=12, sname='wangwu' WHERE sid = 1;
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> SELECT * FROM db1.students;
    +-----+--------+--------+---------+------------+
    | sid | sname  | sclass | sgender | sbirthday  |
    +-----+--------+--------+---------+------------+
    |   1 | wangwu |     12 | male    | 2015-05-20 |
    |   2 | lisi   |     10 | male    | 2015-05-22 |
    +-----+--------+--------+---------+------------+
    2 rows in set (0.00 sec)
  9. Check whether the data is updated in the GeminiDB instance.
    127.0.0.1:6379> KEYS *
    1) "db1:students:sid:1"
    2) "db1:students:sid:2"
    
    127.0.0.1:6379> HGETALL db1:students:sid:1
    1) "sbirthday"
    2) "2015-05-20"
    3) "sclass"
    4) "12"
    5) "sgender"
    6) "male"
    7) "sname"
    8) "wangwu"
  10. Delete data from the students table in the MySQL instance.
    mysql> DELETE FROM db1.students WHERE sid = 1;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> SELECT * FROM db1.students;
    +-----+-------+--------+---------+------------+
    | sid | sname | sclass | sgender | sbirthday  |
    +-----+-------+--------+---------+------------+
    |   2 | lisi  |     10 | male    | 2015-05-22 |
    +-----+-------+--------+---------+------------+
    1 row in set (0.00 sec)
  11. Check whether the data is deleted from the GeminiDB instance.
    127.0.0.1:6379> KEYS *
    1) "db1:students:sid:2"