mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
KV lives in its own org now, like hanzokms / hanzos3 / hanzo-ds. The repo moved hanzoai/kv-go -> hanzokv/go, so the module path follows: a Go module path must match where the repo actually is, or the proxy cannot resolve it. The name is `go`, not `kv-go`, following the hanzo-ds convention — that org holds go, mock, native, sqlbuilder, sqlparser, each named for its language or concern with the ORG supplying the product noun. Repeating "kv" inside a repo that already lives under hanzokv is the compound-word habit we are dropping. 349 occurrences across 188 files: the root module, all four extra/* modules, every example module, imports throughout the tree, and the docs. Builds clean. The package is still `package redis` and the extra dirs are still named redis*. That rename is deliberately NOT bundled here: it is 5,771 occurrences, it breaks all 11 consumers at once, and a large share are WIRE CONTRACTS rather than branding — the redis:// scheme parser, the "redis: nil" error string, RESP command names. Renaming those breaks protocol compatibility with the Valkey server. It needs the same our-vocabulary-vs-the-wire split the argo sweep used, as its own change. GitHub keeps the old path redirecting, and versions already published under github.com/hanzoai/kv-go/v9 stay resolvable, so nothing breaks the moment this lands. Consumers move on their own schedule.
102 lines
2.6 KiB
Go
102 lines
2.6 KiB
Go
package proto_test
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/hanzokv/go/v9/internal/proto"
|
|
)
|
|
|
|
func BenchmarkReader_ParseReply_Status(b *testing.B) {
|
|
benchmarkParseReply(b, "+OK\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Int(b *testing.B) {
|
|
benchmarkParseReply(b, ":1\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Float(b *testing.B) {
|
|
benchmarkParseReply(b, ",123.456\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Bool(b *testing.B) {
|
|
benchmarkParseReply(b, "#t\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_BigInt(b *testing.B) {
|
|
benchmarkParseReply(b, "(3492890328409238509324850943850943825024385\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Error(b *testing.B) {
|
|
benchmarkParseReply(b, "-Error message\r\n", true)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Nil(b *testing.B) {
|
|
benchmarkParseReply(b, "_\r\n", true)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_BlobError(b *testing.B) {
|
|
benchmarkParseReply(b, "!21\r\nSYNTAX invalid syntax", true)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_String(b *testing.B) {
|
|
benchmarkParseReply(b, "$5\r\nhello\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Verb(b *testing.B) {
|
|
benchmarkParseReply(b, "$9\r\ntxt:hello\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Slice(b *testing.B) {
|
|
benchmarkParseReply(b, "*2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Set(b *testing.B) {
|
|
benchmarkParseReply(b, "~2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Push(b *testing.B) {
|
|
benchmarkParseReply(b, ">2\r\n$5\r\nhello\r\n$5\r\nworld\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Map(b *testing.B) {
|
|
benchmarkParseReply(b, "%2\r\n$5\r\nhello\r\n$5\r\nworld\r\n+key\r\n+value\r\n", false)
|
|
}
|
|
|
|
func BenchmarkReader_ParseReply_Attr(b *testing.B) {
|
|
benchmarkParseReply(b, "%1\r\n+key\r\n+value\r\n+hello\r\n", false)
|
|
}
|
|
|
|
func TestReader_ReadLine(t *testing.T) {
|
|
original := bytes.Repeat([]byte("a"), 8192)
|
|
original[len(original)-2] = '\r'
|
|
original[len(original)-1] = '\n'
|
|
r := proto.NewReader(bytes.NewReader(original))
|
|
read, err := r.ReadLine()
|
|
if err != nil && err != io.EOF {
|
|
t.Errorf("Should be able to read the full buffer: %v", err)
|
|
}
|
|
|
|
if !bytes.Equal(read, original[:len(original)-2]) {
|
|
t.Errorf("Values must be equal: %d expected %d", len(read), len(original[:len(original)-2]))
|
|
}
|
|
}
|
|
|
|
func benchmarkParseReply(b *testing.B, reply string, wanterr bool) {
|
|
buf := new(bytes.Buffer)
|
|
for i := 0; i < b.N; i++ {
|
|
fmt.Fprint(buf, reply)
|
|
}
|
|
p := proto.NewReader(buf)
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := p.ReadReply()
|
|
if !wanterr && err != nil {
|
|
b.Fatal(err)
|
|
}
|
|
}
|
|
}
|