Skip to content

Instantly share code, notes, and snippets.

@r14152
Created August 16, 2021 13:20
Show Gist options
  • Save r14152/4a62c1ad5d30aa59ef814cd00adfd5c2 to your computer and use it in GitHub Desktop.
Save r14152/4a62c1ad5d30aa59ef814cd00adfd5c2 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
)
var (
ctx = context.Background()
rdb *redis.Client
)
func init() {
var err error
rdb = redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
}
func checkConnectionStatus() {
err = rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(ctx, "key").Result()
if err != nil {
panic(err)
}
fmt.Println("key", val)
}
func main() {
fmt.Println("Redis Setup Done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment