Files
go/example_instrumentation_test.go
zeekay 6994cf05aa kv, not redis: rename the package, the extras and the URL scheme
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.
2026-07-26 08:34:19 -07:00

116 lines
3.2 KiB
Go

package kv_test
import (
"context"
"fmt"
"net"
"github.com/hanzokv/go/v9"
)
type kvHook struct{}
var _ kv.Hook = kvHook{}
func (kvHook) DialHook(hook kv.DialHook) kv.DialHook {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
fmt.Printf("dialing %s %s\n", network, addr)
conn, err := hook(ctx, network, addr)
fmt.Printf("finished dialing %s %s\n", network, addr)
return conn, err
}
}
func (kvHook) ProcessHook(hook kv.ProcessHook) kv.ProcessHook {
return func(ctx context.Context, cmd kv.Cmder) error {
fmt.Printf("starting processing: <%v>\n", cmd.Args())
err := hook(ctx, cmd)
fmt.Printf("finished processing: <%v>\n", cmd.Args())
return err
}
}
func (kvHook) ProcessPipelineHook(hook kv.ProcessPipelineHook) kv.ProcessPipelineHook {
return func(ctx context.Context, cmds []kv.Cmder) error {
names := make([]string, 0, len(cmds))
for _, cmd := range cmds {
names = append(names, fmt.Sprintf("%v", cmd.Args()))
}
fmt.Printf("pipeline starting processing: %v\n", names)
err := hook(ctx, cmds)
fmt.Printf("pipeline finished processing: %v\n", names)
return err
}
}
func Example_instrumentation() {
rdb := kv.NewClient(&kv.Options{
Addr: ":6379",
DisableIdentity: true,
})
rdb.AddHook(kvHook{})
rdb.Ping(ctx)
// Output:
// starting processing: <[ping]>
// dialing tcp :6379
// finished dialing tcp :6379
// starting processing: <[hello 3]>
// finished processing: <[hello 3]>
// starting processing: <[client maint_notifications on moving-endpoint-type internal-fqdn]>
// finished processing: <[client maint_notifications on moving-endpoint-type internal-fqdn]>
// finished processing: <[ping]>
}
func ExamplePipeline_instrumentation() {
rdb := kv.NewClient(&kv.Options{
Addr: ":6379",
DisableIdentity: true,
})
rdb.AddHook(kvHook{})
rdb.Pipelined(ctx, func(pipe kv.Pipeliner) error {
pipe.Ping(ctx)
pipe.Ping(ctx)
return nil
})
// Output:
// pipeline starting processing: [[ping] [ping]]
// dialing tcp :6379
// finished dialing tcp :6379
// starting processing: <[hello 3]>
// finished processing: <[hello 3]>
// starting processing: <[client maint_notifications on moving-endpoint-type internal-fqdn]>
// finished processing: <[client maint_notifications on moving-endpoint-type internal-fqdn]>
// pipeline finished processing: [[ping] [ping]]
}
func ExampleClient_Watch_instrumentation() {
rdb := kv.NewClient(&kv.Options{
Addr: ":6379",
DisableIdentity: true,
})
rdb.AddHook(kvHook{})
rdb.Watch(ctx, func(tx *kv.Tx) error {
tx.Ping(ctx)
tx.Ping(ctx)
return nil
}, "foo")
// Output:
// starting processing: <[watch foo]>
// dialing tcp :6379
// finished dialing tcp :6379
// starting processing: <[hello 3]>
// finished processing: <[hello 3]>
// starting processing: <[client maint_notifications on moving-endpoint-type internal-fqdn]>
// finished processing: <[client maint_notifications on moving-endpoint-type internal-fqdn]>
// finished processing: <[watch foo]>
// starting processing: <[ping]>
// finished processing: <[ping]>
// starting processing: <[ping]>
// finished processing: <[ping]>
// starting processing: <[unwatch]>
// finished processing: <[unwatch]>
}