Skip to content

Instantly share code, notes, and snippets.

@kirillshevch
Created August 14, 2022 17:05
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/3031bede220681b4db470d1bf39723f7 to your computer and use it in GitHub Desktop.
Save kirillshevch/3031bede220681b4db470d1bf39723f7 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"protobuftest/storage"
"github.com/go-redis/redis/v8"
"google.golang.org/protobuf/proto"
)
func main() {
var ctx = context.Background()
rdb := redis.NewClient(&redis.Options{})
review := storage.Review{Comment: "Great Product!"}
data, err := proto.Marshal(&review)
if err != nil {
panic(err)
}
rdb.Set(ctx, "key", data, 0)
val, err := rdb.Get(ctx, "key").Result()
if err == redis.Nil {
fmt.Println("key does not exist")
} else if err != nil {
panic(err)
}
rev := storage.Review{}
err = proto.Unmarshal([]byte(val), &rev)
if err != nil {
panic(err)
}
fmt.Println(rev.Comment)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment