mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
We do not use Redis. The client was a go-redis fork and still said so
everywhere: `package redis`, `redis.NewClient`, `redis://`, `extra/redisotel`.
Consumers wrote `redis.Client` against a Valkey-backed store called KV.
package redis -> package kv (93 decls)
redis.X -> kv.X (2,794 call sites)
"redis: …" errors -> "kv: …" (206)
extra/redis{otel,cmd,prometheus,census} -> extra/kv{otel,cmd,prometheus,census}
redis:// , rediss:// -> kv:// , kvs:// (ParseURL)
Redis*/*Redis* idents -> KV*/*KV*
REDIS_VERSION, REDIS_ENDPOINTS_CONFIG_PATH -> KV_*
I previously argued this rename was unsafe because much of it was "wire
contract". That was wrong, and the categorisation shows why: RESP command names
are GET/SET/HSET — they never contain the word. Of 5,771 occurrences only two
kinds were server-visible at all: the ParseURL scheme (we choose what we pass;
our configs already use kv://) and the CLIENT SETINFO lib-name label, which the
server merely records. Nothing here changes a byte of protocol.
Two things deliberately keep the old spelling:
RediSearch — names a specific external module the FT.* commands map to.
StoreDist — contains the letters by accident (sto-reDis-t), not the word.
Breaking for consumers by design: every import site must move redis.X -> kv.X.
Minor bump, never a major — this module stays v9 forever.
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/kvotel/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 := kv.NewClient(&kv.Options{
|
|
Addr: ":6379",
|
|
})
|
|
if err := kvotel.InstrumentTracing(rdb); err != nil {
|
|
panic(err)
|
|
}
|
|
if err := kvotel.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 *kv.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
|
|
}
|