Giter Club home page Giter Club logo

goredis's Introduction

goredis

In-memory redis database implementation in Go

Goals:

  • Write parsers to handle RESP protocol messages
  • Handly multiple connections with goroutines
  • Use append only files to persist data
SET user jp # The key > string,  value serialized 
GET user  
    >> "jp"
SET user jp
*3\r\n$3\r\nset\r\n$4\r\nuser\r\n$2\r\njp
---------
*3
$3
set
$4
user
$2
jp
*3 indicates that we have an array with a size of 3. 
We will read 6 lines. 
Each pair of lines represents the type and size of the object, 
Second line contains the value of that object.

$ indicates that it is a string with a length of 5. So the next line will contain exactly 5 characters.

Similarly, when we say `GET user`, it returns the same object structure with different values
$2\r\jp\r\n

Ref: RESP: https://redis.io/docs/reference/protocol-spec/ Redis serialization protocol (RESP) is the wire protocol that clients implement

To communicate with the Redis server, Redis clients use a protocol called REdis Serialization Protocol (RESP). While the protocol was designed specifically for Redis, you can use it for other client-server software projects.

RESP can serialize different data types including integers, strings, and arrays. It also features an error-specific type. A client sends a request to the Redis server as an array of strings. The array's contents are the command and its arguments that the server should execute. The server's reply type is command-specific.

RESP is binary-safe and uses prefixed length to transfer bulk data so it does not require processing bulk data transferred from one process to another.

A client connects to a Redis server by creating a TCP connection to its port (the default is 6379) The following table summarizes the RESP data types that Redis supports:


| RESP data type    | Minimal protocol version | Category | First byte |
|-------------------|--------------------------|----------|------------|
| Simple strings    | RESP2                    | Simple   | +          |
| Simple Errors     | RESP2                    | Simple   | -          |
| Integers          | RESP2                    | Simple   | :          |
| Bulk strings      | RESP2                    | Aggregate| $          |
| Arrays            | RESP2                    | Aggregate| *          |
| Nulls             | RESP3                    | Simple   | _          |
| Booleans          | RESP3                    | Simple   | #          |
| Doubles           | RESP3                    | Simple   | ,          |
| Big numbers       | RESP3                    | Simple   | (          |
| Bulk errors       | RESP3                    | Aggregate| !          |
| Verbatim strings  | RESP3                    | Aggregate| =          |
| Maps              | RESP3                    | Aggregate| %          |
| Sets              | RESP3                    | Aggregate| ~          |
| Pushes            | RESP3                    | Aggregate| >          |

goredis's People

Contributors

jakubpluta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.