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.
145 lines
4.8 KiB
Go
145 lines
4.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hanzokv/go/v9"
|
|
"github.com/hanzokv/go/v9/maintnotifications"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
|
|
// Example 0: Explicitly disable maintenance notifications
|
|
fmt.Println("=== Example 0: Explicitly Enabled ===")
|
|
rdb0 := kv.NewClient(&kv.Options{
|
|
Addr: "localhost:6379",
|
|
|
|
// Explicitly disable maintenance notifications
|
|
// This prevents the client from sending CLIENT MAINT_NOTIFICATIONS ON
|
|
MaintNotificationsConfig: &maintnotifications.Config{
|
|
Mode: maintnotifications.ModeEnabled,
|
|
},
|
|
})
|
|
defer rdb0.Close()
|
|
|
|
// Test the connection
|
|
if err := rdb0.Ping(ctx).Err(); err != nil {
|
|
fmt.Printf("Failed to connect: %v\n\n", err)
|
|
}
|
|
fmt.Println("When ModeEnabled, the client will return an error if the server doesn't support maintenance notifications.")
|
|
fmt.Printf("ModeAuto will silently disable the feature.\n\n")
|
|
|
|
// Example 1: Explicitly disable maintenance notifications
|
|
fmt.Println("=== Example 1: Explicitly Disabled ===")
|
|
rdb1 := kv.NewClient(&kv.Options{
|
|
Addr: "localhost:6379",
|
|
|
|
// Explicitly disable maintenance notifications
|
|
// This prevents the client from sending CLIENT MAINT_NOTIFICATIONS ON
|
|
MaintNotificationsConfig: &maintnotifications.Config{
|
|
Mode: maintnotifications.ModeDisabled,
|
|
},
|
|
})
|
|
defer rdb1.Close()
|
|
|
|
// Test the connection
|
|
if err := rdb1.Ping(ctx).Err(); err != nil {
|
|
fmt.Printf("Failed to connect: %v\n\n", err)
|
|
return
|
|
}
|
|
fmt.Println("✓ Connected successfully (maintenance notifications disabled)")
|
|
|
|
// Perform some operations
|
|
if err := rdb1.Set(ctx, "example:key1", "value1", 0).Err(); err != nil {
|
|
fmt.Printf("Failed to set key: %v\n\n", err)
|
|
return
|
|
}
|
|
fmt.Println("✓ SET operation successful")
|
|
|
|
val, err := rdb1.Get(ctx, "example:key1").Result()
|
|
if err != nil {
|
|
fmt.Printf("Failed to get key: %v\n\n", err)
|
|
return
|
|
}
|
|
fmt.Printf("✓ GET operation successful: %s\n\n", val)
|
|
|
|
// Example 2: Using nil config (defaults to ModeAuto)
|
|
fmt.Printf("\n=== Example 2: Default Behavior (ModeAuto) ===\n")
|
|
rdb2 := kv.NewClient(&kv.Options{
|
|
Addr: "localhost:6379",
|
|
// MaintNotifications: nil means ModeAuto (enabled for KV Cloud)
|
|
})
|
|
defer rdb2.Close()
|
|
|
|
if err := rdb2.Ping(ctx).Err(); err != nil {
|
|
fmt.Printf("Failed to connect: %v\n\n", err)
|
|
return
|
|
}
|
|
fmt.Println("✓ Connected successfully (maintenance notifications auto-enabled)")
|
|
|
|
// Example 4: Comparing behavior with and without maintenance notifications
|
|
fmt.Printf("\n=== Example 4: Performance Comparison ===\n")
|
|
|
|
// Client with auto-enabled notifications
|
|
startauto := time.Now()
|
|
for i := 0; i < 1000; i++ {
|
|
key := fmt.Sprintf("test:auto:%d", i)
|
|
if err := rdb2.Set(ctx, key, i, time.Minute).Err(); err != nil {
|
|
fmt.Printf("Failed to set key: %v\n", err)
|
|
return
|
|
}
|
|
}
|
|
autoDuration := time.Since(startauto)
|
|
fmt.Printf("✓ 1000 SET operations (auto): %v\n", autoDuration)
|
|
|
|
// print pool stats
|
|
fmt.Printf("Pool stats (auto): %+v\n", rdb2.PoolStats())
|
|
|
|
// give the server a moment to take chill
|
|
fmt.Println("---")
|
|
time.Sleep(time.Second)
|
|
|
|
// Client with disabled notifications
|
|
start := time.Now()
|
|
for i := 0; i < 1000; i++ {
|
|
key := fmt.Sprintf("test:disabled:%d", i)
|
|
if err := rdb1.Set(ctx, key, i, time.Minute).Err(); err != nil {
|
|
fmt.Printf("Failed to set key: %v\n", err)
|
|
return
|
|
}
|
|
}
|
|
disabledDuration := time.Since(start)
|
|
fmt.Printf("✓ 1000 SET operations (disabled): %v\n", disabledDuration)
|
|
fmt.Printf("Pool stats (disabled): %+v\n", rdb1.PoolStats())
|
|
|
|
// performance comparison note
|
|
fmt.Printf("\nNote: The pool stats and performance are identical because there is no background processing overhead.\n")
|
|
fmt.Println("Since the server doesn't support maintenance notifications, there is no difference in behavior.")
|
|
fmt.Printf("The only difference is that the \"ModeDisabled\" client doesn't send the CLIENT MAINT_NOTIFICATIONS ON command.\n\n")
|
|
fmt.Println("p.s. reordering the execution here makes it look like there is a small performance difference, but it's just noise.")
|
|
|
|
// Cleanup
|
|
fmt.Printf("\n=== Cleanup ===\n")
|
|
if err := rdb1.FlushDB(ctx).Err(); err != nil {
|
|
fmt.Printf("Failed to flush DB: %v\n", err)
|
|
return
|
|
}
|
|
fmt.Println("✓ Database flushed")
|
|
|
|
fmt.Printf("\n=== Summary ===\n")
|
|
fmt.Println("Maintenance notifications can be disabled by setting:")
|
|
fmt.Println(" MaintNotifications: &maintnotifications.Config{")
|
|
fmt.Println(" Mode: maintnotifications.ModeDisabled,")
|
|
fmt.Println(" }")
|
|
fmt.Printf("\nThis is useful when:\n")
|
|
fmt.Println(" - Connecting to non-KV Cloud instances")
|
|
fmt.Println(" - You want to handle failovers manually")
|
|
fmt.Println(" - You want to minimize client-side overhead")
|
|
fmt.Println(" - The KV server doesn't support CLIENT MAINT_NOTIFICATIONS")
|
|
fmt.Printf("\nFor more information, see:\n")
|
|
fmt.Println(" https://github.com/hanzokv/go/tree/master/maintnotifications")
|
|
}
|