Introducing RediSQL
Brought to you by RedBeardLab

Redis + SQLite = RediSQL

Today, RedBeardLab is glad to announces it’s first redis module, RediSQL.


We love the simplicity and flexibility of Redis, we love to keep the data we need the most into a redis instance for fast lookup and use and we love that data are persistent on disk.

However, sometimes, we wish to have the simplicity of redis and a more structured approach to the data we save.

From this wish, RediSQL is born.


Technically RediSQL is a redis module, a piece of software that expose some API defined by Redis itself.

When you start redis you can pass the module as input parameter, redis will call the function RedisModule_OnLoad that in our code looks like this:

int RedisModule_OnLoad(RedisModuleCtx *ctx) {
  if (RedisModule_Init(ctx, "rediSQL__", 1, REDISMODULE_APIVER_1) ==

  int rc;
  // we open a connection to an in memory database
  rc = sqlite3_open(":memory:", &db);
  if (rc != SQLITE_OK)

  // we create a new command, the command "rediSQL.exec",
  // when the command is executed the function ExecCommand in invoked.
  if (RedisModule_CreateCommand(ctx, "rediSQL.exec", ExecCommand, 
	"deny-oom random no-cluster", 1, 1, 1) == REDISMODULE_ERR){


Now Redis is able to interpretate a new custom command: “rediSQL.exec”. When the new command is invoked Redis will call the function ExecCommand.

The function ExecCommand does nothing more than execute the SQL statement passed as input against the SQLite database opened before. Finally the result is return in the form of a simple string or like a list of list in case of more complex selects.

If you would like to explore deeply how the whole software works I encourage you to check out the code, it is less than 200 lines of fairly readable, albeit not comment, C code.


The module is extremely simple and small and it can already provides a lot of value in specific case. If you are managing unimportant data but you need complex queries and velocity this module can provide quite a solution.

If your data are fundamental for your application and you can’t afford to loose them, then this module is not quite ready for you.


The very first step will be to add data persistency that we believe to be fundamental even if option for some use cases optional.

Then we would like to move following the necessity of the community, so ideas and use cases are extremely welcome.

We do have already a couple of ideas:

  1. Introducing concurrency and non-blocking queries.

  2. Stream all the statements that modify the data, everything but SELECTs.

  3. A cache system to store the result of the more complex select.

But please share your thoughts.

PRO version

We believe in Open Source but we also believe that the work of developers must be adequately compensate. On this premise we are planning to offer a more simple but complete Open Source version of the module and a more complex, feature rich PRO version. It is important to understand that the funds from the PRO version will support the time working on rediSQL. Without those fund the project won’t have a monetary meaning and we will be forced to use our time in a more productive way.

A little tour

You can get started simply downloading the git repo:

$ git clone
Cloning into 'rediSQL'...
remote: Counting objects: 1404, done.
remote: Total 1404 (delta 0), reused 0 (delta 0), pack-reused 1404
Receiving objects: 100% (1404/1404), 7.28 MiB | 487.00 KiB/s, done.
Resolving deltas: 100% (513/513), done.
Checking connectivity... done.

Then move inside the directory and compile the module:

$ cd rediSQL/
$ make sqlite 
gcc -fPIC -c -o sqlite3.o sqlite3.c
$ make
gcc -c -Wpedantic -fPIC -IRedisModulesSDK/ -Bstatic rediSQL.c -o rediSQL.o
ld -o rediSQL.o sqlite3.o RedisModulesSDK/rmutil/librmutil.a -shared -lc

At this point you can launch your redis instance loading the module:

$ ~/redis-4.0-rc1/src/redis-server --loadmodule ./ 
6833:M 15 Dec 16:25:53.195 * Increased maximum number of open files to 10032 (it was originally set to 1024).
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.9.101 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6833
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |         
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           

6833:M 15 Dec 16:25:53.196 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6833:M 15 Dec 16:25:53.196 # Server started, Redis version 3.9.101
6833:M 15 Dec 16:25:53.196 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
6833:M 15 Dec 16:25:53.196 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
6833:M 15 Dec 16:25:53.197 * Module 'rediSQL__' loaded from ./
6833:M 15 Dec 16:25:53.197 * The server is now ready to accept connections on port 6379

Now the redis instance will be just the redis you learn to love:

$ ~/redis-4.0-rc1/src/redis-cli>> SET A 3

But it will also able to accept SQL statements:> 
# Start creating a table> REDISQL.EXEC "CREATE TABLE foo(A INT, B TEXT);"
# Insert some data into the table> REDISQL.EXEC "INSERT INTO foo VALUES(3, 'bar');"
# Retrieve the data you just inserted> REDISQL.EXEC "SELECT * FROM foo;"
1) 1) (integer) 3
   2) "bar"
# Of course you can make multiple tables> REDISQL.EXEC "CREATE TABLE baz(C INT, B TEXT);"
# And of course you can use joins> REDISQL.EXEC "SELECT * FROM foo, baz WHERE foo.A = baz.C;"

1) 1) (integer) 3
   2) "bar"
   3) (integer) 3
   4) "aaa"
2) 1) (integer) 3
   2) "bar"
   3) (integer) 3
   4) "bbb"
3) 1) (integer) 3
   2) "bar"
   3) (integer) 3
   4) "ccc"> 

Of course also errors are managed:> REDISQL.EXEC "INSERT INTO baz VALUES("aaa", "bbb");"
Invalid argument(s)>> REDISQL.EXEC "CREATE TABLE baz(f INT, k TEXT);"
(error) ERR - table baz already exists | Query: CREATE TABLE baz(f INT, k TEXT);


Right now I see this module perfect for small dataset of unimportant data.

You could try to use it in your next side project or if you are writing microservices to avoid bothering the master of DB with your need ephemeral needs of structured database.

If you have any question you may directly write to myself, the author at

Or you may start

or fork

the project on github.

About us

RedBeardLab is focused on building distributed, highly scalable fault tolerant system. We are based in Milan, Italy and we collaborate with our clients mainly remotely.

If you would like to investigate a possible collaboration don’t esitate to contact us on the form in the bottom left or via email at

If you subscribe to our very sporadic mail list (bottom right), you will also receive our “Little introduction to distributed, highly scalable, fault tolerant system.”

Interested in Collaborating?

Contact Us

Subscribe to our maillist

Do you want to receive for free the "Little introduction to distributed, highly-scalable, fault-tolerant systems" ?

Leave your email address, subscribe, and I will send you a copy