Skip to content

Commit 2042ece

Browse files
committed
doc: support postgres
1 parent 65bacd9 commit 2042ece

File tree

6 files changed

+89
-33
lines changed

6 files changed

+89
-33
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
<img alt="Redka" src="logo.svg" height="80" align="center">
22

3-
Redka aims to reimplement the core parts of Redis with SQLite, while remaining compatible with Redis API.
3+
Redka aims to reimplement the core parts of Redis with SQL, while remaining compatible with Redis API.
44

55
Notable features:
66

7-
- Data does not have to fit in RAM.
8-
- ACID transactions.
9-
- SQL views for better introspection and reporting.
10-
- Both in-process (Go API) and standalone (RESP) servers.
11-
- Redis-compatible commands and wire protocol.
7+
- Data doesn't have to fit in RAM.
8+
- Supports ACID transactions.
9+
- SQL views for easier analysis and reporting.
10+
- Works with both SQLite and PostgreSQL (coming v0.6.0) backends.
11+
- Runs in-process (Go API) or as a standalone server.
12+
- Redis-compatible commands and wire protocol (RESP).
1213

1314
Redka is [functionally ready](docs/roadmap.md) for 1.0. Feel free to try it in non-critical production scenarios and provide feedback in the issues.
1415

16+
## Use cases
17+
18+
Here are some situations where Redka might be helpful:
19+
20+
_Embedded cache for Go applications_. If your Go app already uses SQLite or just needs a simple, built-in key-value store, Redka is a natural fit. It gives you Redis-like features without the hassle of running a separate server. The cache persists across application restarts, and backup is as easy as copying a file.
21+
22+
_Lightweight testing environment_. Your app uses Redis in production, but setting up a Redis server for local development or integration tests can be a hassle. Redka, when used with an in-memory SQLite database, gives you a fast alternative with complete isolation for each test run.
23+
24+
_Postgres-first data structures_. If you prefer to use PostgreSQL for everything but need Redis-like data structures (like lists and sorted sets), Redka can use your existing database as the backend. This way, you can manage both relational data and specialized data structures with the same tools and transactional guarantees.
25+
1526
## Commands
1627

1728
Redka supports five core Redis data types:
@@ -31,17 +42,21 @@ Redka comes in two flavors:
3142
- Standalone Redis-compatible server: [installation](docs/install-standalone.md), [usage](docs/usage-standalone.md).
3243
- Go module for in-process use: [installation](docs/install-module.md), [usage](docs/usage-module.md).
3344

45+
## Storage
46+
47+
Redka can use either SQLite or PostgreSQL as its backend. It stores data in a [SQL database](docs/persistence.md) with a simple schema and provides views for better introspection.
48+
3449
## Performance
3550

36-
According to the [benchmarks](docs/performance.md), Redka is several times slower than Redis. Still, it can do up to 100K op/sec on a Macbook Air, which is pretty good if you ask me (and probably 10x more than most applications will ever need).
51+
Redka is not about raw performance. You can't beat a specialized data store like Redis with a general-purpose relational backend like SQLite. However, Redka can still handle tens of thousands of operations per second, which should be more than enough for many apps.
3752

38-
Redka stores data in a [SQLite database](docs/persistence.md) with a simple schema and provides views for better introspection.
53+
See the [benchmarks](docs/performance.md) for more details.
3954

4055
## Contributing
4156

4257
Contributions are welcome. For anything other than bugfixes, please first open an issue to discuss what you want to change.
4358

44-
Be sure to add or update tests as appropriate.
59+
Make sure to add or update tests as needed.
4560

4661
## Acknowledgements
4762

docs/install-module.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ Install the module as follows:
66
go get github.com/nalgeon/redka
77
```
88

9-
You'll also need an SQLite driver. Use one of the following:
9+
You'll also need an SQLite or PostgreSQL driver.
10+
11+
Use one of the following for SQLite:
1012

1113
- `github.com/mattn/go-sqlite3` (CGO, fastest)
1214
- `github.com/ncruces/go-sqlite3` (pure Go, WASM)
13-
- `github.com/tursodatabase/go-libsql` (CGO)
14-
- `modernc.org/sqlite` (pure Go)
15+
- `modernc.org/sqlite` (pure Go, libc port)
16+
17+
Or one of the following for PostgreSQL:
18+
19+
- `github.com/lib/pq`
20+
- `github.com/jackc/pgx/v5`
1521

1622
Install a driver with `go get` like this:
1723

docs/performance.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,72 @@ I've compared Redka with Redis using [redis-benchmark](https://redis.io/docs/man
77
- 10000 randomized keys
88
- GET/SET commands
99

10-
SQLite settings:
11-
12-
```
13-
pragma journal_mode = wal;
14-
pragma synchronous = normal;
15-
pragma temp_store = memory;
16-
pragma mmap_size = 268435456;
17-
pragma foreign_keys = on;
18-
```
19-
20-
Hardware: Apple M1 8-core CPU, 16GB RAM
10+
## Results
2111

2212
Redis:
2313

24-
```
14+
```text
2515
redis-server --appendonly no
2616
redis-benchmark -p 6379 -q -c 10 -n 1000000 -r 10000 -t get,set
2717
2818
SET: 133262.25 requests per second, p50=0.055 msec
2919
GET: 139217.59 requests per second, p50=0.055 msec
3020
```
3121

32-
Redka (in-memory):
22+
Redka (SQLite, in-memory):
3323

34-
```
24+
```text
3525
./redka -p 6380
3626
redis-benchmark -p 6380 -q -c 10 -n 1000000 -r 10000 -t get,set
3727
3828
SET: 36188.62 requests per second, p50=0.167 msec
3929
GET: 104405.93 requests per second, p50=0.063 msec
4030
```
4131

42-
Redka (persisted to disk):
32+
Redka (SQLite, persisted to disk):
4333

44-
```
45-
./redka -p 6380 data.db
34+
```text
35+
./redka -p 6380 redka.db
4636
redis-benchmark -p 6380 -q -c 10 -n 1000000 -r 10000 -t get,set
4737
4838
SET: 26773.76 requests per second, p50=0.215 msec
4939
GET: 103092.78 requests per second, p50=0.063 msec
5040
```
5141

52-
So while Redka is 2-5 times slower than Redis (not surprising, since we are comparing a relational database to a key-value data store), it can still do 26K writes/sec and 94K reads/sec, which is pretty good if you ask me.
42+
Redka (PostgreSQL):
43+
44+
```text
45+
./redka -p 6380 "postgres://redka:redka@localhost:5432/redka?sslmode=disable"
46+
redis-benchmark -p 6380 -q -c 10 -n 100000 -r 10000 -t get,set
47+
48+
SET: 11941.72 requests per second, p50=0.775 msec
49+
GET: 25766.55 requests per second, p50=0.359 msec
50+
```
51+
52+
So while Redka is noticeably slower than Redis (not surprising, since we are comparing a relational database to a key-value data store), it can still handle tens of thousands of operations per second. That should be more than enough for many apps.
53+
54+
## Environment
55+
56+
Hardware: Apple M1 8-core CPU, 16GB RAM
57+
58+
SQLite settings:
59+
60+
```text
61+
pragma journal_mode = wal;
62+
pragma synchronous = normal;
63+
pragma temp_store = memory;
64+
pragma mmap_size = 268435456;
65+
pragma foreign_keys = on;
66+
```
67+
68+
PostgreSQL settings:
69+
70+
```text
71+
checkpoint_completion_target=0.9
72+
effective_cache_size=4GB
73+
maintenance_work_mem=512MB
74+
max_wal_size=1GB
75+
random_page_cost=1.1
76+
shared_buffers=1GB
77+
wal_buffers=16MB
78+
```

docs/persistence.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Persistence
22

3-
Redka stores data in a SQLite database using the following tables:
3+
Redka stores data in a SQL database using the following tables:
44

55
```
66
rkey

docs/usage-module.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ Redka supports the following SQLite drivers:
9696

9797
- `github.com/mattn/go-sqlite3` ([example](../example/simple/main.go))
9898
- `github.com/ncruces/go-sqlite3` ([example](../example/ncruces/main.go))
99-
- `github.com/tursodatabase/go-libsql` ([example](../example/libsql/main.go))
10099
- `modernc.org/sqlite` ([example](../example/modernc/main.go))

docs/usage-standalone.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ redka [-h host] [-p port] [-s unix-socket] [db-path]
99
For example:
1010

1111
```shell
12+
# use in-memory sqlite database
1213
./redka
14+
15+
# use file sqlite database
1316
./redka data.db
17+
18+
# listen on all network interfaces
1419
./redka -h 0.0.0.0 -p 6379 data.db
20+
21+
# listen on unix socket
1522
./redka -s /tmp/redka.sock data.db
23+
24+
# use postgres database
25+
./redka -p 6379 "postgres://redka:redka@localhost:5432/redka?sslmode=disable"
1626
```
1727

1828
Server defaults are host `localhost`, port `6379` and empty DB path. The unix socket path, if given, overrides the host/port arguments.
@@ -42,7 +52,7 @@ Once the server is running, connect to it using `redis-cli` or an API client lik
4252
redis-cli -h localhost -p 6379
4353
```
4454

45-
```
55+
```text
4656
127.0.0.1:6379> echo hello
4757
"hello"
4858
127.0.0.1:6379> set name alice

0 commit comments

Comments
 (0)