### Redis Client Cache Tracking Example Source: https://github.com/smallnest/resp3/blob/master/README.md Demonstrates how to use the resp3 library to implement client-side caching with Redis 6.0's tracking feature. It shows connecting to Redis, enabling tracking, sending commands, and handling pushed invalidation messages. ```Go package main import ( "net" "strconv" "testing" "time" "github.com/smallnest/resp3" ) 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 := resp.NewWriter(conn) r := resp.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// 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 := resp.NewWriter(conn) r := resp.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 == resp.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() } } } ``` -------------------------------- ### RESP3 Data Types Overview Source: https://github.com/smallnest/resp3/blob/master/README.md Lists and describes the various data types supported by the RESP3 protocol, including those inherited from RESP2 and new types introduced in RESP3. This provides a conceptual understanding of the protocol's structure. ```APIDOC RESP3 Data Types: Types equivalent to RESP version 2: - Array: An ordered collection of N other types. - Blob string: Binary safe strings. - Simple string: A space efficient non binary safe string. - Simple error: A space efficient non binary safe error code and message. - Number: An integer in the signed 64 bit range. Types introduced by RESP3: - Null: A single null value replacing RESP v2 null values. - Double: A floating point number. - Boolean: True or false. - Blob error: Binary safe error code and message. - Verbatim string: A binary safe string intended for human display without escaping. - Map: An ordered collection of key-value pairs, where keys and values can be any RESP3 type. - Set: An unordered collection of N other types. - Attribute: Similar to Map, but clients should ignore the attribute type and return it as additional information. - Push: Out-of-band data, formatted like an Array. The first element indicates the push type, potentially triggering a callback. - Hello: Similar to Map, sent upon connection establishment to provide server information (name, version, etc.). - Big number: A large number not representable by the standard Number type. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.