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.
97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
package kv_test
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/hanzokv/go/v9"
|
|
|
|
. "github.com/bsm/ginkgo/v2"
|
|
. "github.com/bsm/gomega"
|
|
)
|
|
|
|
var _ = Describe("Cmd", func() {
|
|
var client *kv.Client
|
|
|
|
BeforeEach(func() {
|
|
client = kv.NewClient(kvOptions())
|
|
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
|
|
})
|
|
|
|
AfterEach(func() {
|
|
Expect(client.Close()).NotTo(HaveOccurred())
|
|
})
|
|
|
|
It("implements Stringer", func() {
|
|
set := client.Set(ctx, "foo", "bar", 0)
|
|
Expect(set.String()).To(Equal("set foo bar: OK"))
|
|
|
|
get := client.Get(ctx, "foo")
|
|
Expect(get.String()).To(Equal("get foo: bar"))
|
|
})
|
|
|
|
It("has val/err", func() {
|
|
set := client.Set(ctx, "key", "hello", 0)
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
get := client.Get(ctx, "key")
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
})
|
|
|
|
It("has helpers", func() {
|
|
set := client.Set(ctx, "key", "10", 0)
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
n, err := client.Get(ctx, "key").Int64()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(n).To(Equal(int64(10)))
|
|
|
|
un, err := client.Get(ctx, "key").Uint64()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(un).To(Equal(uint64(10)))
|
|
|
|
f, err := client.Get(ctx, "key").Float64()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(f).To(Equal(float64(10)))
|
|
})
|
|
|
|
It("supports float32", func() {
|
|
f := float32(66.97)
|
|
|
|
err := client.Set(ctx, "float_key", f, 0).Err()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
val, err := client.Get(ctx, "float_key").Float32()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(val).To(Equal(f))
|
|
})
|
|
|
|
It("supports time.Time", func() {
|
|
tm := time.Date(2019, 1, 1, 9, 45, 10, 222125, time.UTC)
|
|
|
|
err := client.Set(ctx, "time_key", tm, 0).Err()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
s, err := client.Get(ctx, "time_key").Result()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(s).To(Equal("2019-01-01T09:45:10.000222125Z"))
|
|
|
|
tm2, err := client.Get(ctx, "time_key").Time()
|
|
Expect(err).NotTo(HaveOccurred())
|
|
Expect(tm2).To(BeTemporally("==", tm))
|
|
})
|
|
|
|
It("allows to set custom error", func() {
|
|
e := errors.New("custom error")
|
|
cmd := kv.Cmd{}
|
|
cmd.SetErr(e)
|
|
_, err := cmd.Result()
|
|
Expect(err).To(Equal(e))
|
|
})
|
|
})
|