Last active
March 6, 2020 02:17
-
-
Save islishude/28a1f77f0e1c6ac9a295a99400783258 to your computer and use it in GitHub Desktop.
golang: test for redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/alicebob/miniredis" | |
"github.com/go-redis/redis" | |
) | |
func main() { | |
mini, err := miniredis.Run() | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
defer mini.Close() | |
goredis := redis.NewClient(&redis.Options{Addr: mini.Addr()}) | |
fmt.Println(mini.Addr()) | |
defer goredis.Close() | |
data, err := goredis.Set("key", "value", 0).Result() | |
fmt.Println(data, err) | |
resp, err := goredis.Get("key").Result() | |
fmt.Println(resp, err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment