Skip to content

Instantly share code, notes, and snippets.

@up1
Last active March 23, 2024 17:41
Show Gist options
  • Save up1/64a00cbe7b9271df44093123b81e42b3 to your computer and use it in GitHub Desktop.
Save up1/64a00cbe7b9271df44093123b81e42b3 to your computer and use it in GitHub Desktop.
Hello Garnet from microsoft
// Build
$git clone git@github.com:microsoft/garnet.git
$cd garnet
$dotnet restore
$dotnet build -c Release
$dotnet test -c Release -f net8.0 -l "console;verbosity=detailed"
// Start server
$cd main/GarnetServer
$dotnet run -c Release -f net8.0
Build succeeded in 1.6s
_________
/_||___||_\ Garnet 1.0.1 64 bit; standalone mode
'. \ / .' Port: 3278
'.\ /.' https://aka.ms/GetGarnet
'.'
* Ready to accept connections
package main
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
func main() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:3278",
Password: "", // no password set
DB: 0, // use default DB
})
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)
val2, err := rdb.Get(ctx, "key2").Result()
if err == redis.Nil {
fmt.Println("key2 does not exist")
} else if err != nil {
panic(err)
} else {
fmt.Println("key2", val2)
}
// Output: key value
// key2 does not exist
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment