Created
August 14, 2022 17:05
-
-
Save kirillshevch/3031bede220681b4db470d1bf39723f7 to your computer and use it in GitHub Desktop.
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 ( | |
"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