Redis database backend extension for the Community Solid Server
Store data in your Solid Pod with a Redis Database. Redis is an open source, in-memory data store.
Disclaimer: By default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb
. This library does not alter these default persistence settings and does not include any extra calls to save the database to disk. Read more about persistence in redis.
Implementation details
For data with content type internal/quads
, Solid Redis transforms quads into strings by concatenating their subject, predicate, and object values with the | (pipe) character. These strings are stored in Redis Sets. These Sets serve as the storage of the triples in LDP resources and their keys are the URIs of each resource. Solid Redis uses some special keys to store the metadata, children, and content type of resources.
Because Redis does not support empty Sets, for resources or metadata which should exist but contain no triples, Solid Redis stores a Set with a single dummy value of "1". These dummy values do not get exposed outside of the RedisDataAccessor
class.
All other content types other than internal/quads
are stored as strings. Redis can store any arbitrary binary data as a string up to 512Mb.
How to use Solid Redis
Install
From the npm package registry:
mkdir my-server
cd my-server
npm install @solid/community-server@v4.0.0 @comake/solid-redis
Install Redis
Follow Getting started with Redis to install and run Redis.
Configure
This extension can be used in 3 ways:
- As your CSS's backend to store pod data.
- As your CSS's key-value storage to store internal data (accounts, locks, tokens, etc.).
- As both!
1. As a backend
In your server's root folder (my-server
or whatever the name of your project is) create a config.json
file from this template (config-backend-example.json), and fill out your settings. The only important changes to make to the default config are to add solid-redis
into @context
and to change the backend storage to redis:
-"files-scs:config/storage/backend/*.json",
+"files-csr:config/storage/backend/redis.json",
2. As a key-value store
In your server's root folder create a config.json
file from this template (config-key-value-store-example.json), and fill out your settings. The only important changes to make to the default config are to add solid-redis
into @context
and change the key-value storage to redis:
-"files-scs:config/storage/key-value/*.json",
+"files-csr:config/storage/key-value/redis.json",
3. As both
In your server's root folder create a config.json
file from this template (config-all-storage-example.json), and fill out your settings. The only important changes to make to the default config are to add solid-redis
into @context
and change the backend and key-value storage to the global redis storage:
-"files-scs:config/storage/backend/*.json",
-"files-scs:config/storage/key-value/*.json"
+"files-csr:config/storage/backend/redis.json",
+"files-scs:config/storage/key-value/resource-store.json",
Configure the redis connection
Optionally, you can change the connection settings for your Redis database by adding parameters to the RedisDataAccessor
in the @graph
section of the config.json
file you just created such as:
{
"@id": "urn:solid-redis:default:RedisDataAccessor",
"comment": "The configuration to connect to the Redis instance.",
"RedisDataAccessor:_configuration_host": "52.22.22.22",
"RedisDataAccessor:_configuration_port": "1234",
}
If you do not include this section, host
defaults to localhost
and port
defaults to 6379
, which are the Redis defaults.
You may optionally also include a username
and password
if your database requires them and a dbNumber
if you don't use the default 0 database.
Run CSS
Execute the following command:
npx community-solid-server -c config.json -m .
Or add the command to scripts
inside your package.json like so:
{
"scripts": {
"start": "npx community-solid-server -c config.json -m ."
}
}
How to contribute to Solid Redis
Execute the following commands:
git clone https://github.com/comake/solid-redis.git
cd solid-redis
npm ci
TODO
- [ ] Add support for different Redis modules such as:
- RedisJSON so the json data can be updated & queried as JSON instead of strings
- RediSearch to do full text search over the data in redis
- [ ] Remove the Redis client mock in integration tests and have them run on CI in docker with a real redis instance
License
©2022-present Comake, Inc., MIT License