https://github.com/mashingan/localredis
Ephemeral redis in memory used for ease of testing.
https://github.com/mashingan/localredis
Last synced: 9 months ago
JSON representation
Ephemeral redis in memory used for ease of testing.
- Host: GitHub
- URL: https://github.com/mashingan/localredis
- Owner: mashingan
- License: mit
- Created: 2021-04-28T07:34:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T14:08:31.000Z (about 5 years ago)
- Last Synced: 2025-03-31T02:35:33.919Z (about 1 year ago)
- Language: Go
- Size: 58.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# localredis
[](https://github.com/mashingan/localredis/actions/workflows/go.yml)
Local implementation of redis protocol. The storage in entirely put in the memory and will be lost
when the app/program is quitting.
This implementation usually used for integration testing without having
to run actual redis server as this is easy to run and close as the test starts and ends.
It's main usage why re-invented the wheel is for ease of mock testing without having fully-blown
redis server installation. Mostly the usage can be summarized as below example:
```go
package testing
import (
"APP-ROOT/app"
"testing"
"os"
"github.com/mashingan/localredis"
)
func checkAppStates(t *testing.T, app.App) {
// implementation
}
func TestOurApp(t *testing.T) {
redisAddr := ":8099"
os.Setenv("REDIS_ADDR", redisAddr)
go localredis.ListenAndServe(redisAddr)
apprun := app.Start()
checkAppStates(t, apprun)
localredis.Close()
}
```
Above example taking assumption that the app would connect to redis from `REDIS_ADDR` environment variable value.
So instead of connecting to actual redis server, the app connect to our in memory redis.
Currently, it's in alpha-state with only basic `set`, `get` and `ping` handler implemented.
# Install
Using go modules, simply importing the path [`github.com/mashingan/localredis`](github.com/mashingan/localredis)
will automatically put it on `go.mod` dependencies entry.
# Contributing
Adding supports for the new command by adding it to [`commandMap`](commands.go#L48).
# License
MIT