postgredis

command module
v0.0.0-...-c4a6f99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 8 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL