mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
KV lives in its own org now, like hanzokms / hanzos3 / hanzo-ds. The repo moved hanzoai/kv-go -> hanzokv/go, so the module path follows: a Go module path must match where the repo actually is, or the proxy cannot resolve it. The name is `go`, not `kv-go`, following the hanzo-ds convention — that org holds go, mock, native, sqlbuilder, sqlparser, each named for its language or concern with the ORG supplying the product noun. Repeating "kv" inside a repo that already lives under hanzokv is the compound-word habit we are dropping. 349 occurrences across 188 files: the root module, all four extra/* modules, every example module, imports throughout the tree, and the docs. Builds clean. The package is still `package redis` and the extra dirs are still named redis*. That rename is deliberately NOT bundled here: it is 5,771 occurrences, it breaks all 11 consumers at once, and a large share are WIRE CONTRACTS rather than branding — the redis:// scheme parser, the "redis: nil" error string, RESP command names. Renaming those breaks protocol compatibility with the Valkey server. It needs the same our-vocabulary-vs-the-wire split the argo sweep used, as its own change. GitHub keeps the old path redirecting, and versions already published under github.com/hanzoai/kv-go/v9 stay resolvable, so nothing breaks the moment this lands. Consumers move on their own schedule.
93 lines
1.8 KiB
Go
93 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"sync"
|
|
"time"
|
|
|
|
"go.opentelemetry.io/otel"
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
"github.com/uptrace/uptrace-go/uptrace"
|
|
|
|
"github.com/hanzokv/go/extra/redisotel/v9"
|
|
"github.com/hanzokv/go/v9"
|
|
)
|
|
|
|
var tracer = otel.Tracer("github.com/hanzokv/go/example/otel")
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
|
|
uptrace.ConfigureOpentelemetry(
|
|
// copy your project DSN here or use UPTRACE_DSN env var
|
|
uptrace.WithDSN("http://project1_secret@localhost:14318/2?grpc=14317"),
|
|
|
|
uptrace.WithServiceName("myservice"),
|
|
uptrace.WithServiceVersion("v1.0.0"),
|
|
)
|
|
defer uptrace.Shutdown(ctx)
|
|
|
|
rdb := redis.NewClient(&redis.Options{
|
|
Addr: ":6379",
|
|
})
|
|
if err := redisotel.InstrumentTracing(rdb); err != nil {
|
|
panic(err)
|
|
}
|
|
if err := redisotel.InstrumentMetrics(rdb); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for i := 0; i < 1e6; i++ {
|
|
ctx, rootSpan := tracer.Start(ctx, "handleRequest")
|
|
|
|
if err := handleRequest(ctx, rdb); err != nil {
|
|
rootSpan.RecordError(err)
|
|
rootSpan.SetStatus(codes.Error, err.Error())
|
|
}
|
|
|
|
rootSpan.End()
|
|
|
|
if i == 0 {
|
|
fmt.Printf("view trace: %s\n", uptrace.TraceURL(rootSpan))
|
|
}
|
|
|
|
time.Sleep(time.Second)
|
|
}
|
|
}
|
|
|
|
func handleRequest(ctx context.Context, rdb *redis.Client) error {
|
|
if err := rdb.Set(ctx, "First value", "value_1", 0).Err(); err != nil {
|
|
return err
|
|
}
|
|
if err := rdb.Set(ctx, "Second value", "value_2", 0).Err(); err != nil {
|
|
return err
|
|
}
|
|
|
|
var group sync.WaitGroup
|
|
|
|
for i := 0; i < 20; i++ {
|
|
group.Add(1)
|
|
go func() {
|
|
defer group.Done()
|
|
val := rdb.Get(ctx, "Second value").Val()
|
|
if val != "value_2" {
|
|
log.Printf("%q != %q", val, "value_2")
|
|
}
|
|
}()
|
|
}
|
|
|
|
group.Wait()
|
|
|
|
if err := rdb.Del(ctx, "First value").Err(); err != nil {
|
|
return err
|
|
}
|
|
if err := rdb.Del(ctx, "Second value").Err(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|