Skip to content

Instantly share code, notes, and snippets.

@kirillshevch
Last active August 14, 2022 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirillshevch/0e798d5ebeb71e454612a09a43053cbc to your computer and use it in GitHub Desktop.
Save kirillshevch/0e798d5ebeb71e454612a09a43053cbc to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
)
func main() {
var ctx = context.Background()
rdb := redis.NewClient(&redis.Options{})
err := rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(ctx, "key").Result()
if err == redis.Nil {
fmt.Println("key does not exist")
} else if err != nil {
panic(err)
} else {
fmt.Println(val)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment