Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
github.com/smallnest/resp3
The first redis RESP3 protocol library, written in Go.
You can use it to communicte with Redis 6 via RESP3, or you can wrap it as redis client lib.
Value
represents a redis command or an redis response, which supports all RESP3 types:
Reader
is used to read a Value
object from the connection. It can be used by both redis clients and redis servers.
you can use it to test the client cache feature in Redis 6.0.
func TestReader_IT_Tracking(t *testing.T) {
conn, err := net.DialTimeout("tcp", "127.0.0.1:6379", 5*time.Second)
if err != nil {
t.Logf("can't found one of redis 6.0 server")
return
}
defer conn.Close()
w := NewWriter(conn)
r := NewReader(conn)
w.WriteCommand("HELLO", "3")
helloResp, _, err := r.ReadValue()
if err != nil {
t.Fatalf("failed to send a HELLO 3")
}
if helloResp.KV.Size() == 0 {
t.Fatalf("expect some info but got %+v", helloResp)
}
t.Logf("hello response: %c, %v", helloResp.Type, helloResp.SmartResult())
w.WriteCommand("CLIENT", "TRACKING", "on")
resp, _, err := r.ReadValue()
if err != nil {
t.Fatalf("failed to TRACKING: %v", err)
}
t.Logf("TRACKING result: %c, %+v", resp.Type, resp.SmartResult())
w.WriteCommand("GET", "a")
resp, _, err = r.ReadValue()
if err != nil {
t.Fatalf("failed to GET: %v", err)
}
t.Logf("GET result: %c, %+v", resp.Type, resp.SmartResult())
go func() {
conn, err := net.DialTimeout("tcp", "127.0.0.1:9999", 5*time.Second)
if err != nil {
t.Logf("can't found one of redis 6.0 server")
return
}
defer conn.Close()
w := NewWriter(conn)
r := NewReader(conn)
for i := 0; i < 10; i++ {
//PUBLISH
w.WriteCommand("set", "a", strconv.Itoa(i))
resp, _, err = r.ReadValue()
if err != nil {
t.Fatalf("failed to set: %v", err)
}
t.Logf("set result: %c, %+v", resp.Type, resp.SmartResult())
time.Sleep(200 * time.Millisecond)
}
}()
for i := 0; i < 10; i++ {
resp, _, err = r.ReadValue()
if err != nil {
t.Fatalf("failed to receive a message: %v", err)
}
if resp.Type == TypePush && len(resp.Elems) >= 2 && resp.Elems[0].SmartResult().(string) == "invalidate" {
t.Logf("received TRACKING result: %c, %+v", resp.Type, resp.SmartResult())
// refresh cache "a"
w.WriteCommand("GET", "a")
resp, _, err = r.ReadValue()
}
}
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.