Key-value imports: Redis, Valkey, Riak KV, RethinkDB and RavenDB
This page is for administrators who keep data in a key-value or document store and want it in Exponential as tables, and for developers who work on the readers. From Exponential 6.0.15 the kernel reads five such stores and copies their records into the site's database or into any data table connection:
| Store | Command | Reached over | Level |
|---|---|---|---|
| Redis 6.2 to 7.4 | exp:redis:import | the Redis protocol (RESP2) in plain PHP, TCP, TLS or a Unix socket | import source |
| Valkey 7.2 to 8.1 | exp:valkey:import | the same | import source; a cache through the extension sevenx_valkey_cache |
| Riak KV 2.2 and 3.0 | exp:riak:import | Riak's HTTP API (PHP's curl extension) | import source |
| RethinkDB 2.4 | exp:rethinkdb:import | RethinkDB's driver protocol (V1_0, JSON, SCRAM-SHA-256) in plain PHP | import source |
| RavenDB 6.0 to 6.2 | exp:ravendb:import | RavenDB's HTTP API (curl), a client certificate for a secured server | import source |
What none of them is. None is a site database and none is a database of data tables: they have no SQL, no joins
and no schema the kernel could keep its tables in. They are import sources. A data table connection of one of these
engines (Engine=redis ...) does not open a database; it names the store, so an import can say --source=<identifier>
instead of repeating the server, the password and the TLS files (Setup > Data tables lists them with "an import source,
read by exp:redis:import").
Caches. Redis and Valkey already serve Exponential as caches through the extension sevenx_valkey_cache; that is their cache role and it is unchanged. Riak KV, RethinkDB and RavenDB get no cache role: a cache backend wants a key expiry and microsecond reads on one round trip, which Riak (no expiry per key on the default backend), RethinkDB (document writes with durability) and RavenDB (documents with indexes) do not give cleanly.
Contents
- Requirements
- How records become tables
- Running an import
- A connection as the source
- Each store
- How it is built
- Tests
Requirements
| What | For |
|---|---|
| PHP 8.0 or later | every reader |
PHP's curl extension | Riak KV and RavenDB |
PHP's openssl extension | TLS to Redis, Valkey or RethinkDB; RavenDB's client certificates |
| A target | the site's database, or a data table connection with write access |
No library and no extension of a store is needed: the Redis protocol and RethinkDB's driver protocol are spoken in
plain PHP (expRedisClient, expRethinkDBClient), Riak and RavenDB over HTTP (expKeyValueHttp).
How records become tables
A store names groups of records; every group becomes a table:
| Store | A group | A record | The key column |
|---|---|---|---|
| Redis, Valkey | the first segment of a key (user:1001 -> user); --depth=2 takes two (shop:order:17 -> shop_order); a key without the separator goes to the table keys | a key | doc_id, the key |
| Riak KV | a bucket of the bucket type | an object | doc_id, the object's key |
| RethinkDB | a table | a document | the table's primary key (id, or the one it was made with) |
| RavenDB | a collection (@hilo left out; @empty becomes empty) | a document | doc_id, the document id (orders/1-A) |
The columns are the fields of a sample of the group's records (500 by default, --sample), in the order they are met:
integers become integer or bigint, numbers double, booleans boolean (written 1 and 0), short text text(255),
long text and nested objects or lists memo (nested values written as JSON). A record that is no document is one
column, value.
What each kind of Redis key gives:
| Type | Record |
|---|---|
| hash | its fields; a field holding an integer or a number is typed as one (Redis keeps only text) |
| string | a JSON object gives its fields; anything else is value |
| JSON (RedisJSON, valkey-json) | the document's fields |
| list, set, sorted set, stream | value, as JSON (a set sorted, a sorted set as member => score) |
Binary data that is no UTF-8 is written as base64. A table name is the group in lower case letters, digits and _;
two groups with the same name get _2, _3.
Running an import
Every command works the same way as exp:couchdb:import and exp:access:import, with the same engine behind it:
# what is there: the tables and their columns
./console exp:redis:import --server=10.0.0.7 --database=2 --list
the plan: the tables it would make, nothing written
./console exp:redis:import --server=10.0.0.7 --pattern='user:*' --secret=env:REDIS_PASSWORD
the import
./console exp:redis:import --server=10.0.0.7 --secret=env:REDIS_PASSWORD --prefix=kv_ --apply
into a data table connection, replacing its rows, machine output
./console exp:rethinkdb:import --source=realtime --connection=archive --mode=replace --apply --format=json| Option | Meaning |
|---|---|
--list | the tables and their columns, then stop |
--apply | make the tables and copy the rows; without it the command shows the plan only |
--connection | the target: site (the default) or a data table connection |
--tables | only these tables (a comma list) |
--prefix | in front of every table name (kv_) |
--mode | create (new tables only), append, replace (delete the rows first) |
--sample | the records the columns are inferred from |
--format | text or json |
--source | a connection naming the store, or --server, --port, --database, --user, --secret |
The password is never given on the command line: --secret names a secret of Setup > Secrets or env:VARIABLE.
Exit code 0 means done (or planned), 1 a table or row failed, 2 wrong options or no connection. A command never
writes to the store it reads.
A connection as the source
A connection in settings/override/datatable.ini.append.php (or made in Setup > Data tables):
[Connection_sessions]
Name=Session store
Engine=valkey
Server=10.0.0.7
Port=6379
Database=0
Secret=env:VALKEY_PASSWORD
TLS=enabled
SSLCA=/etc/ssl/valkey-ca.pemDatabase is the logical database number (Redis, Valkey), the bucket type (Riak, default) or the database
(RethinkDB, RavenDB). TLS, SSLCA, VerifyTLS=disabled, and for RavenDB SSLCert and SSLKey (PEM files) are the
TLS settings. Then:
./console exp:valkey:import --source=sessions --listThe engines are on the list of [ConnectionSettings] Engines[]; take one off to refuse its connections.
Each store
Redis and Valkey. The keys are walked with SCAN (never KEYS, which blocks the server), 500 at a time; the
types and then the values of each batch are read in one pipeline each, so a key costs two commands on two round trips
for 500 keys. A table's rows are scanned with its prefix as the pattern (user:*), so a large keyspace is walked once
per table. --pattern narrows the keys (--pattern='shop:*'), --separator changes : (empty: every key in one
table), --depth sets how many segments name the table. --user is an ACL user; with a password alone the command
sends AUTH password. The server forms: host, host:port, redis://, rediss:// (TLS), valkey://,
unix:///run/redis.sock. Keys that expire are read as they are at the moment of reading, and a key that disappears
between the scan and the read is left out.
Riak KV. Every bucket of the bucket type is a table, its keys are listed and sorted, and every object read. A
JSON object gives its fields, text is value, binary data value in base64. An object with siblings (allow_mult) is
read as its first sibling. Listing buckets and keys walks every key of the cluster, which Riak advises against on a
busy cluster: name the buckets (--buckets=users,orders) and run the import against a quiet node. Riak's own data
types (counters, sets, maps of the datatypes endpoints) are not read.
RethinkDB. The handshake is V1_0 with SCRAM-SHA-256 (user admin with an empty password by default). Every
table is a table with its primary key; the documents are read as one cursor, batch by batch. A time becomes
Y-m-d H:i:s in UTC, binary data base64, a geometry its GeoJSON. TLS: --tls=enabled, --ca.
RavenDB. Every collection is a table, read page by page (1,024 documents a request) in the collection's order;
the document id is doc_id and @metadata is left out. An unsecured server answers over http; a secured one wants a
client certificate with read access to the database: --cert=/etc/exp/raven.pem (and --cert-key when the key is in
a file of its own).
How it is built
| Class | File | Role |
|---|---|---|
expKeyValueReader | kernel/classes/keyvalue/expkeyvaluereader.php | the common reader: groups as tables, the sample, the rows, the connection of the options |
expRedisClient, expRedisReader | kernel/classes/keyvalue/expredisclient.php, expredisreader.php | RESP2, pipelines, SCAN; Redis and Valkey |
expKeyValueHttp | kernel/classes/keyvalue/expkeyvaluehttp.php | the curl client of Riak and RavenDB |
expRiakReader | kernel/classes/keyvalue/expriakreader.php | buckets, keys, objects, siblings |
expRethinkDBClient, expRethinkDBReader | kernel/classes/keyvalue/exprethinkdbclient.php, exprethinkdbreader.php | the driver protocol, SCRAM-SHA-256, ReQL terms, cursors |
expRavenDBReader | kernel/classes/keyvalue/expravendbreader.php | collections and their documents |
| the commands | kernel/private/classes/commands/exp{redis,valkey,riak,rethinkdb,ravendb}import.php | options; the run is exp:couchbase:import's |
The readers speak the vocabulary of expAccessReader, so the import engine expAccessImport (the one of
exp:access:import, exp:couchdb:import and exp:cassandra:import) makes the tables in the target's dialect and
copies the rows.
Tests
| Suite | What |
|---|---|
keyvalue | DB-less: stand-ins of every store; names, documents, the Redis protocol and addresses, SCRAM-SHA-256 against the example of RFC 7677, every reader, an import into SQLite |
keyvalue-live | against live servers: Redis, Valkey, Riak KV, RethinkDB and RavenDB in containers; each test writes its data, imports it into SQLite and reads the rows back |
php vendor/bin/phpunit --testsuite keyvalue
EXP_TEST_REDIS_HOST=127.0.0.1 EXP_TEST_REDIS_PASSWORD=... EXP_TEST_VALKEY_HOST=127.0.0.1 EXP_TEST_VALKEY_PORT=6380 \
EXP_TEST_RIAK_HOST=127.0.0.1 EXP_TEST_RETHINKDB_HOST=127.0.0.1 EXP_TEST_RAVENDB_URL=http://127.0.0.1:8080 \
php vendor/bin/phpunit --testsuite keyvalue-liveThe live tests empty the logical database 3 of the Redis and Valkey servers they are given (FLUSHDB) and make and
drop their own databases in RethinkDB and RavenDB: run them against servers of their own, never a production store.
The GitHub job keyvalue runs both suites on PHP 8.5 and 8.1.
Measured on 2026-11-28 against containers (podman) with PHP 8.5: Redis 7.4.12, Valkey 8.1.12, RethinkDB 2.4.4 and
RavenDB 6.2.22 pass the live tests (each import read and wrote every record, 2,000 Redis keys over several SCAN
steps, 1,500 RethinkDB documents as a cursor, 1,100 RavenDB documents page by page). Riak KV was not measured there:
the basho/riak-kv image does not start under podman ("su: System error"); the GitHub job runs it under Docker.
The import writes the column names in lower case and gives a reserved word an underscore (value becomes value_).