mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
Update module path from github.com/redis/go-redis/v9 to github.com/hanzoai/kv-go/v9 for use as the Hanzo KV Go SDK. - Update go.mod module declaration - Update all Go imports across 260 files - Update all submodule go.mod files (extra/*, example/*, internal/customvet)
51 lines
878 B
Go
51 lines
878 B
Go
// EXAMPLE: set_and_get
|
|
// HIDE_START
|
|
package example_commands_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/kv-go/v9"
|
|
)
|
|
|
|
func ExampleClient_Set_and_get() {
|
|
ctx := context.Background()
|
|
|
|
rdb := redis.NewClient(&redis.Options{
|
|
Addr: "localhost:6379",
|
|
Password: "", // no password docs
|
|
DB: 0, // use default DB
|
|
})
|
|
|
|
// HIDE_END
|
|
|
|
// REMOVE_START
|
|
// start with fresh database
|
|
rdb.FlushDB(ctx)
|
|
errFlush := rdb.FlushDB(ctx).Err() // Clear the database before each test
|
|
if errFlush != nil {
|
|
panic(errFlush)
|
|
}
|
|
// REMOVE_END
|
|
|
|
err := rdb.Set(ctx, "bike:1", "Process 134", 0).Err()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println("OK")
|
|
|
|
value, err := rdb.Get(ctx, "bike:1").Result()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
fmt.Printf("The name of the bike is %s", value)
|
|
// HIDE_START
|
|
|
|
// Output: OK
|
|
// The name of the bike is Process 134
|
|
}
|
|
|
|
// HIDE_END
|