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.
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
"github.com/hanzokv/go/v9"
|
|
)
|
|
|
|
type Model struct {
|
|
Str1 string `kv:"str1"`
|
|
Str2 string `kv:"str2"`
|
|
Str3 *string `kv:"str3"`
|
|
Bytes []byte `kv:"bytes"`
|
|
Int int `kv:"int"`
|
|
Int2 *int `kv:"int2"`
|
|
Bool bool `kv:"bool"`
|
|
Bool2 *bool `kv:"bool2"`
|
|
Ignored struct{} `kv:"-"`
|
|
}
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
|
|
rdb := kv.NewClient(&kv.Options{
|
|
Addr: ":6379",
|
|
})
|
|
_ = rdb.FlushDB(ctx).Err()
|
|
|
|
// Set some fields.
|
|
if _, err := rdb.Pipelined(ctx, func(rdb kv.Pipeliner) error {
|
|
rdb.HSet(ctx, "key", "str1", "hello")
|
|
rdb.HSet(ctx, "key", "str2", "world")
|
|
rdb.HSet(ctx, "key", "str3", "")
|
|
rdb.HSet(ctx, "key", "int", 123)
|
|
rdb.HSet(ctx, "key", "int2", 0)
|
|
rdb.HSet(ctx, "key", "bool", 1)
|
|
rdb.HSet(ctx, "key", "bool2", 0)
|
|
rdb.HSet(ctx, "key", "bytes", []byte("this is bytes !"))
|
|
return nil
|
|
}); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
var model1, model2 Model
|
|
|
|
// Scan all fields into the model.
|
|
if err := rdb.HGetAll(ctx, "key").Scan(&model1); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
// Or scan a subset of the fields.
|
|
if err := rdb.HMGet(ctx, "key", "str1", "int").Scan(&model2); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
spew.Dump(model1)
|
|
// Output:
|
|
// (main.Model) {
|
|
// Str1: (string) (len=5) "hello",
|
|
// Str2: (string) (len=5) "world",
|
|
// Bytes: ([]uint8) (len=15 cap=16) {
|
|
// 00000000 74 68 69 73 20 69 73 20 62 79 74 65 73 20 21 |this is bytes !|
|
|
// },
|
|
// Int: (int) 123,
|
|
// Bool: (bool) true,
|
|
// Ignored: (struct {}) {
|
|
// }
|
|
// }
|
|
|
|
spew.Dump(model2)
|
|
// Output:
|
|
// (main.Model) {
|
|
// Str1: (string) (len=5) "hello",
|
|
// Str2: (string) "",
|
|
// Bytes: ([]uint8) <nil>,
|
|
// Int: (int) 123,
|
|
// Bool: (bool) false,
|
|
// Ignored: (struct {}) {
|
|
// }
|
|
// }
|
|
}
|