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.
110 lines
3.3 KiB
Go
110 lines
3.3 KiB
Go
package kv_test
|
|
|
|
import (
|
|
. "github.com/bsm/ginkgo/v2"
|
|
. "github.com/bsm/gomega"
|
|
|
|
"github.com/hanzokv/go/v9"
|
|
)
|
|
|
|
var _ = Describe("UniversalClient", func() {
|
|
var client kv.UniversalClient
|
|
|
|
AfterEach(func() {
|
|
if client != nil {
|
|
Expect(client.Close()).To(Succeed())
|
|
}
|
|
})
|
|
|
|
It("should connect to failover servers", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
MasterName: sentinelName,
|
|
Addrs: sentinelAddrs,
|
|
})
|
|
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
|
})
|
|
|
|
It("should connect to failover cluster", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
MasterName: sentinelName,
|
|
RouteRandomly: true,
|
|
Addrs: sentinelAddrs,
|
|
})
|
|
_, ok := client.(*kv.ClusterClient)
|
|
Expect(ok).To(BeTrue(), "expected a ClusterClient")
|
|
})
|
|
|
|
It("should connect to simple servers", func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
Addrs: []string{kvAddr},
|
|
})
|
|
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
|
})
|
|
|
|
It("should connect to clusters", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
Addrs: cluster.addrs(),
|
|
})
|
|
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
|
})
|
|
|
|
It("connect to clusters with UniversalClient and UnstableResp3", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
Addrs: cluster.addrs(),
|
|
Protocol: 3,
|
|
UnstableResp3: true,
|
|
})
|
|
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
|
a := func() { client.FTInfo(ctx, "all").Result() }
|
|
Expect(a).ToNot(Panic())
|
|
})
|
|
|
|
It("connect to clusters with ClusterClient and UnstableResp3", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewClusterClient(&kv.ClusterOptions{
|
|
Addrs: cluster.addrs(),
|
|
Protocol: 3,
|
|
UnstableResp3: true,
|
|
})
|
|
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
|
a := func() { client.FTInfo(ctx, "all").Result() }
|
|
Expect(a).ToNot(Panic())
|
|
})
|
|
|
|
It("should connect to failover servers on slaves when readonly Options is ok", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
MasterName: sentinelName,
|
|
Addrs: sentinelAddrs,
|
|
ReadOnly: true,
|
|
})
|
|
Expect(client.Ping(ctx).Err()).NotTo(HaveOccurred())
|
|
|
|
roleCmd := client.Do(ctx, "ROLE")
|
|
role, err := roleCmd.Result()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
roleSlice, ok := role.([]interface{})
|
|
Expect(ok).To(BeTrue())
|
|
Expect(roleSlice[0]).To(Equal("slave"))
|
|
|
|
err = client.Set(ctx, "somekey", "somevalue", 0).Err()
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("should connect to clusters if IsClusterMode is set even if only a single address is provided", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
Addrs: []string{cluster.addrs()[0]},
|
|
IsClusterMode: true,
|
|
})
|
|
_, ok := client.(*kv.ClusterClient)
|
|
Expect(ok).To(BeTrue(), "expected a ClusterClient")
|
|
})
|
|
|
|
It("should return all slots after instantiating UniversalClient with IsClusterMode", Label("NonKVEnterprise"), func() {
|
|
client = kv.NewUniversalClient(&kv.UniversalOptions{
|
|
Addrs: []string{cluster.addrs()[0]},
|
|
IsClusterMode: true,
|
|
})
|
|
Expect(client.ClusterSlots(ctx).Val()).To(HaveLen(3))
|
|
})
|
|
})
|