go-redis icon indicating copy to clipboard operation
go-redis copied to clipboard

Document possible integration with miniredis for unit testing

Open ghost opened this issue 7 years ago • 3 comments

Library can be easily used with miniredis for unit testing. I think it's worth mentioning in Readme

Example:

package main

import (
	"github.com/alicebob/miniredis"
	"github.com/go-redis/redis"
	"fmt"
	"os"
)


func main() {
	mini, err := miniredis.Run()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	goredis := redis.NewClient(&redis.Options{
		Addr:mini.Addr(),
	})
	fmt.Println(mini.Addr())

	data, err := goredis.Set("test", "Zażółć gęślą jaźń", 0).Result()
	fmt.Println(data, err)

	resp, err := goredis.Get("test").Result()
	fmt.Println(resp, err)
}

ghost avatar Jun 09 '18 06:06 ghost

Sounds good - do you want to send a PR?

vmihailenco avatar Jun 09 '18 08:06 vmihailenco

This is neat, and very helpful. I'll try to get to prepare a PR for this in a few days. Thanks @piotr-srebniak-limango

eranharel avatar Aug 02 '20 12:08 eranharel

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar May 06 '24 00:05 github-actions[bot]