Query redis with SQL

BuildStatus Go Report Card codecov

reqlite

reqlite makes it possible to query data in Redis with SQL. Queries are executed client-side with SQLite (not on the redis server). This project is distributed as a SQLite run-time loadable extension and (soon) as a standalone binary (CLI).

This project is experimental for the time being. It's made possible by a great library for building SQLite extensions in go.

The JSON1 extension is also included by default as a convenience.

Use Cases

What can or should I use this for? This project is pretty experimental and part of that is exploring use-cases to understand what's possible and interesting!

A common situation is a task queue in Redis. If you're using a LIST as a queue holding JSON objects, reqlite + the SQLite json1 extension could be used to issue basic "slicing and dicing" queries against your task queue.

-- what are the most common tasks currently in the queue?
SELECT count(*), json_extract(value, '$.task') as task
FROM LRANGE('my-queue', 0, 100)
GROUP BY task
ORDER BY count(*) DESC

In general, Redis is fairly accessible from many programming languages, and any query using reqlite could probably be implemented in a language of your choice using a Redis client. However, sometimes declarative SQL can be a better choice to express what you're looking for, and that's where this project may be most useful. Since reqlite is distributed as a run-time loadable SQLite extension, it can be loaded into a language using a SQLite driver as well, which would allow you to mix SQL and the "host" language to access data in Redis.

Getting Started

To build a run-time loadable extension, run make in the root of the source tree. The reqlite.so file should be in .build/reqlite.so, which you can use immediately in a SQLite shell:

sqlite3
sqlite> .load .build/reqlite.so
sqlite> SELECT * FROM LRANGE('some-key', 0, 10);

Connecting to Redis

Currently, the Redis connection can only be set via the following env variables:

ENV Default Description
REQLITE_NET tcp Network type - either tcp or udp
REQLITE_ADDR localhost:6379 Network address of the redis instance
REQLITE_USER (none) Redis username
REQLITE_PASS (none) Redis password

TODO - Implement another mechanism (SQLite UDFs?) for setting up the connection information.

Commands

Currently, only read operations are targeted to be implemented as SQLite scalar functions or table-valued functions. In the examples below, you'll see how a SQLite scalar or table-valued function maps to a corresponding Redis command, based on the response type. Note that there won't always be an exact correspondence, and currently not all Redis commands are targeted to be implemented (read-only for now).

SELECT * FROM some_table_valued_function('param', 1, 2) -- function that returns a table
SELECT some_scalar_function('param', 1, 2) -- function that returns a scalar value

Available functions are listed below. For a full list of Redis commands and corresponding SQLite functions, see here.

LRANGE

SELECT * FROM LRANGE('some-key', 0, 10)

HGETALL

SELECT * FROM HGETALL('myhash')

BITCOUNT

SELECT BITCOUNT('some-key')
SELECT BITCOUNT('some-key', 1, 1)

BITPOS

SELECT BITPOS('some-key', 0)
SELECT BITPOS('some-key', 1, 2)

CLIENT ID

SELECT CLIENT_ID()

CONFIG GET

SELECT * FROM CONFIG_GET('*max-*-entries*')
SELECT * FROM CONFIG_GET -- equivalent to CONFIG GET *

DBSIZE

SELECT DBSIZE()

LLEN

SELECT LLEN('some-list')

RedisJSON (link)

JSON_GET

SELECT JSON_GET('my-json-key')
SELECT JSON_GET('my-json-key', 'some.path[2]')

JSON_MGET

SELECT * FROM JSON_MGET('some.path', 'key1,key2,key3')
Similar Resources

Use SQL to query instances, domains and more from Prometheus.

Use SQL to query instances, domains and more from Prometheus.

Use SQL to instantly query Prometheus metrics, alerts, labels and more. Open source CLI. No DB required.

Nov 28, 2022

Use SQL to instantly query Hypothesis resources. Open source CLI. No DB required.

Hypothesis Plugin for Steampipe Prerequisites Steampipe Golang Build $ git clone https://github.com/judell/steampipe-plugin-hypothesis.git $ cd steam

Dec 11, 2022

Use SQL to instantly query resources, data sources and more from Terraform code. Open source CLI. No DB required.

Use SQL to instantly query resources, data sources and more from Terraform code. Open source CLI. No DB required.

Terraform Plugin for Steampipe Use SQL to query data from Terraform configuration files. Get started → Documentation: Table definitions & examples Com

Dec 22, 2022

Use SQL to instantly query Algolia indexes and configuration. Open source CLI. No DB required

Use SQL to instantly query Algolia indexes and configuration. Open source CLI. No DB required

Oct 1, 2022

Use SQL to query databases, logs and more from PlanetScale

Use SQL to instantly query PlanetScale databases, branches and more. Open source CLI. No DB required.

Sep 30, 2022

This is the code example how to use SQL to query data from any relational databases in Go programming language.

Go with SQL example This is the code example how to use SQL to query data from any relational databases in Go programming language. To start, please m

Mar 12, 2022

WAL-G is an archival restoration tool for PostgreSQL, MySQL/MariaDB, and MS SQL Server (beta for MongoDB and Redis).

WAL-G is an archival restoration tool for PostgreSQL, MySQL/MariaDB, and MS SQL Server (beta for MongoDB and Redis).

Jan 1, 2023

Go library that stores data in Redis with SQL-like schema

Go library that stores data in Redis with SQL-like schema. The goal of this library is we can store data in Redis with table form.

Mar 14, 2022

Devcloud-go provides a sql-driver for mysql which named devspore driver and a redis client which named devspore client,

Devcloud-go Devcloud-go provides a sql-driver for mysql which named devspore driver and a redis client which named devspore client, you can use them w

Jun 9, 2022
Comments
  • Missing .load command under SQLite

    Missing .load command under SQLite

    I followed the README instruction and try the run following sqlite command:

    sqlite3   
    SQLite version 3.28.0 2019-04-15 14:49:49
    Enter ".help" for usage hints.
    Connected to a transient in-memory database.
    Use ".open FILENAME" to reopen on a persistent database.
    sqlite> .load .build/reqlite.so
    Error: unknown command or invalid arguments:  "load". Enter ".help" for help
    

    The .load command doesn't exist. May I know which version of SQLite did you use?

    Here's my test environment details:

    • Installed SQLite3 using brew on MacOS
    • Verified if.load command exist or not by running the below CLI:
    ajeetraina@Ajeets-MacBook-Pro reqlite % sqlite3
    SQLite version 3.28.0 2019-04-15 14:49:49
    Enter ".help" for usage hints.
    Connected to a transient in-memory database.
    Use ".open FILENAME" to reopen on a persistent database.
    sqlite> .help
    .auth ON|OFF             Show authorizer callbacks
    .backup ?DB? FILE        Backup DB (default "main") to FILE
    .bail on|off             Stop after hitting an error.  Default OFF
    .binary on|off           Turn binary output on or off.  Default OFF
    .cd DIRECTORY            Change the working directory to DIRECTORY
    .changes on|off          Show number of rows changed by SQL
    .check GLOB              Fail if output since .testcase does not match
    .clone NEWDB             Clone data into NEWDB from the existing database
    .databases               List names and files of attached databases
    .dbconfig ?op? ?val?     List or change sqlite3_db_config() options
    .dbinfo ?DB?             Show status information about the database
    .dump ?TABLE? ...        Render all database content as SQL
    .echo on|off             Turn command echo on or off
    .eqp on|off|full|...     Enable or disable automatic EXPLAIN QUERY PLAN
    .excel                   Display the output of next command in a spreadsheet
    .exit ?CODE?             Exit this program with return-code CODE
    .expert                  EXPERIMENTAL. Suggest indexes for specified queries
    .fullschema ?--indent?   Show schema and the content of sqlite_stat tables
    .headers on|off          Turn display of headers on or off
    .help ?-all? ?PATTERN?   Show help text for PATTERN
    .import FILE TABLE       Import data from FILE into TABLE
    .imposter INDEX TABLE    Create imposter table TABLE on index INDEX
    .indexes ?TABLE?         Show names of indexes
    .limit ?LIMIT? ?VAL?     Display or change the value of an SQLITE_LIMIT
    .lint OPTIONS            Report potential schema issues.
    .log FILE|off            Turn logging on or off.  FILE can be stderr/stdout
    .mode MODE ?TABLE?       Set output mode
    .nullvalue STRING        Use STRING in place of NULL values
    .once (-e|-x|FILE)       Output for the next SQL command only to FILE
    .open ?OPTIONS? ?FILE?   Close existing database and reopen FILE
    .output ?FILE?           Send output to FILE or stdout if FILE is omitted
    .parameter CMD ...       Manage SQL parameter bindings
    .print STRING...         Print literal STRING
    .progress N              Invoke progress handler after every N opcodes
    .prompt MAIN CONTINUE    Replace the standard prompts
    .quit                    Exit this program
    .read FILE               Read input from FILE
    .restore ?DB? FILE       Restore content of DB (default "main") from FILE
    .save FILE               Write in-memory database into FILE
    .scanstats on|off        Turn sqlite3_stmt_scanstatus() metrics on or off
    .schema ?PATTERN?        Show the CREATE statements matching PATTERN
    .selftest ?OPTIONS?      Run tests defined in the SELFTEST table
    .separator COL ?ROW?     Change the column and row separators
    .session ?NAME? CMD ...  Create or control sessions
    .sha3sum ...             Compute a SHA3 hash of database content
    .shell CMD ARGS...       Run CMD ARGS... in a system shell
    .show                    Show the current values for various settings
    .stats ?on|off?          Show stats or turn stats on or off
    .system CMD ARGS...      Run CMD ARGS... in a system shell
    .tables ?TABLE?          List names of tables matching LIKE pattern TABLE
    .testcase NAME           Begin redirecting output to 'testcase-out.txt'
    .timeout MS              Try opening locked tables for MS milliseconds
    .timer on|off            Turn SQL timer on or off
    .trace ?OPTIONS?         Output each SQL statement as it is run
    .vfsinfo ?AUX?           Information about the top-level VFS
    .vfslist                 List all available VFSes
    .vfsname ?AUX?           Print the name of the VFS stack
    .width NUM1 NUM2 ...     Set column widths for "column" mode
    sqlite> 
    
Go-Postgresql-Query-Builder - A query builder for Postgresql in Go

Postgresql Query Builder for Go This query builder aims to make complex queries

Nov 17, 2022
OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.

OctoSQL OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases, streaming sources and file formats using

Dec 29, 2022
A Go SQL query builder and struct mapper.

godb - a Go query builder and struct mapper godb is a simple Go query builder and struct mapper, not a full-featured ORM. godb does not manage relatio

Dec 6, 2022
Use SQL to query host, DNS and exploit information using Shodan. Open source CLI. No DB required.

Shodan Plugin for Steampipe Query Shodan with SQL Use SQL to query host, DNS and exploit information using Shodan. For example: select * from shod

Nov 10, 2022
Query and Provision Cloud Infrastructure using an extensible SQL based grammar
Query and Provision Cloud Infrastructure using an extensible SQL based grammar

Deploy, Manage and Query Cloud Infrastructure using SQL [Documentation] [Developer Guide] Cloud infrastructure coding using SQL InfraQL allows you to

Oct 25, 2022
Use SQL to instantly query file, domain, URL and IP scanning results from VirusTotal.
Use SQL to instantly query file, domain, URL and IP scanning results from VirusTotal.

VirusTotal Plugin for Steampipe Use SQL to query file, domain, URL and IP scanning results from VirusTotal. Get started → Documentation: Table definit

Nov 10, 2022
Use SQL to instantly query users, groups, applications and more from Okta. Open source CLI. No DB required.
Use SQL to instantly query users, groups, applications and more from Okta. Open source CLI. No DB required.

Okta Plugin for Steampipe Use SQL to query infrastructure including users, groups, applications and more from Okta. Get started → Documentation: Table

Nov 10, 2022
Use SQL to instantly query instances, networks, databases, and more from Scaleway. Open source CLI. No DB required.
Use SQL to instantly query instances, networks, databases, and more from Scaleway. Open source CLI. No DB required.

Scaleway Plugin for Steampipe Use SQL to query infrastructure servers, networks, databases and more from your Scaleway project. Get started → Document

Nov 16, 2022
Use SQL to instantly query Datadog resources across accounts. Open source CLI. No DB required.

steampipe-plugin-datadog Datadog Plugin for Steampipe Use SQL to query dashboards, users, roles and more from Datadog. Get started → Documentation: Ta

Dec 17, 2022
Use SQL to query information including Users, Groups, Clients, Roles and more from Keycloak.

Keycloak Plugin for Steampipe [WIP] THIS IS NOT ACTIVE NOR WORKING YET - DO NOT USE Use SQL to query information including Users, Groups, Clients, Rol

Jan 6, 2023