redis-packet-decoder

command module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

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)

  1. In RESP2, the protocol starts with ping,+PONG request and response packets
  2. In RESP3/RESP2(newer format), the protocol starts with and initial handshake, (hello and the protocol version)

Special Things about Redis,

  1. 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
  2. After the symbol, we have the size of the data (in case of Strings, Maps and Arrays), and then the value of the data
  3. 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}]}]
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL