/postgredis

A Redis-compatible server with PostgreSQL storage backend

Primary LanguageGoMIT LicenseMIT

postgredis

A wild idea of having Redis-compatible server with PostgreSQL backend.

Getting started

As a binary:

./postgredis -addr=:6380 -db=postgres://postgres:postgres@localhost:5432/postgredis -table=postgredis

As a docker container:

docker run -it postgredis:latest -addr=:6380 -db=postgres://postgres:postgres@db:5432/postgredis -table=postgredis

Note: it was intended to run inside docker network with postgres in a container on the same network, see docker-compose.yml

You can use redis-cli and play around with supported commands (see below):

> redis-cli -p 6380
127.0.0.1:6380> set x 123
OK
127.0.0.1:6380> set x 1
OK
127.0.0.1:6380> get x
"1"

or connect with various redis-compatible libraries (see example/example.go).

Why

I like how Redis interface works. It is easy to understand and you can bootstrap new projects quickly without dealing with persistant storage. I also don't have to deal with migrations management and sql-related libraries. But Redis itself is not good as a persistent storage.

I like PostgreSQL, it is my goto database. I have a couple of web services using it at the moment. And I try to stick with PostgreSQL when any of the self-hosted appliances provide it as a storage choice.

I've been using bitcask a lot recently, and I liked how you can start bitcask server and use libraries like redigo to interact with the server. I then found out that writing Redis interfaces for any storage backend is quite easy with redcon library. I even looked at solutions like LedisDB, but it seemed unmaintained and too bloated for my use cases.

So I decided to implement PostgreSQL backend for Redis' interface.

How it works

When you first start postgredis, it will create a table with two columns: unique key and value. They both are in text format. Unique key helps with concise "upsert" queries. Thanks to pgx I don't have think about how to maintain a connection, I just start a pool. There is also a logging of sql queries, which is good for debugging.

Supported commands

See COMMANDS.md.

Future plans

Disclaimer

This is an MIT licensed code, which uses open sourced software. The name of the package is a work-in-progress and I am willing to change it. PostgreSQL and Redis are registered names and I am not affiliated with them.