Skip to content

khareyash05/redis-packet-decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}]}]
}

About

A Redis Packet Decoder into a format that is simple to understand

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages