Redis Packet Decoder
Redis follows RESP protocol https://redis.io/docs/latest/develop/reference/protocol-spec/
There are two major versions of RESP being followed (Version 2 and 3)
- In RESP2, the protocol starts with ping,+PONG request and response packets
- In RESP3/RESP2(newer format), the protocol starts with and initial handshake, (hello and the protocol version)
Special Things about Redis,
- Redis follows a string format for the packets(every item in the packet is in form of a string), and the string uses various symbols to denote the type of data coming in
- After the symbol, we have the size of the data (in case of Strings, Maps and Arrays), and then the value of the data
- Each character ends with CRLF which helps denote the end
This module, helps in decoding Redis Packets into a Readable Format(for info about the models https://github.com/khareyash05/redis-packet-decoder/tree/main/models)
Examples -
import (
"fmt"
"log"
rpd "github.com/khareyash05/redis-packet-decoder"
)
func main() {
packetToBeProcessed := "*2\r\n$5\r\nhello\r\n$1\r\n3\r\n" // the initial packet in case of RESP3
decodedPacket, err := rpd.ParseRedis(packetToBeProcessed)
if err != nil {
log.Fatal(err)
}
fmt.Println("Here is the Decoded Packet", decodedPacket) // output [{Type:array Size:2 Data:[{Type:string Size:5 Data:hello} {Type:string Size:1 Data:3}]}]
}