Skip to content

alexwith/lettuce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🥬 Lettuce

Lettuce is a redis server written in Go. It implements the RESP protocol and should therefore work with any redis client.

Notes

  • This is just a fun project for learning about Golang and TCP-based protocols, but I do attempt to make it as fast and functional as possible.
  • There is no persistence implemented, so Lettuce should only be utilised as a cache or pub/sub.
  • This implementation is based on the RESP3 version of the protocol released with Redis 6

Getting Started

If you want to use the pre-existing Lettuce server, navigate to it's location and execute: go run . This will start the lettuce server on port 6380.

You can also create your own custom redis server. Execute go get github.com/alexwith/lettuce in your own project, then initiate the server. The following example will also register a custom command:

package main

import (
  "github.com/alexwith/lettuce/command"
  "github.com/alexwith/lettuce/lettuce"
  "github.com/alexwith/lettuce/protocol"
)

const HOST string = "127.0.0.1"
const PORT int16 = 6380

func main()  {
  lettuce.Setup(HOST, PORT, func() {
    registerCommands()
  })
}

func registerCommands()  {
  command.RegisterCommand("CUSTOMPING", -1, func(connection *protocol.Connection, context *command.CommandContext)  {
    if len(context.Args) <= 0 {
      connection.WriteSimpleString("CUSTOMPONG")
      return
    }

    response := context.StringArg(0)
    connection.WriteBulkString(response)
  })
}

Features

RESP (REdis Serialization Protocol)

  • Simple Strings
  • Errors
  • Integers
  • Bulk Strings
  • Arrays
  • Null Array and Bulk Strings
  • Telnet commands
  • Pipelining

Commands

I will only be implementing the most important commands, as I will not have time to implement the 450+ redis commands that exist.

  • PING
  • KEYS
  • SET
  • GET
  • APPEND
  • DEL
  • TTL
  • EXPIRE
  • PERSIST
  • EXISTS
  • STRLEN
  • INCR

Pub/Sub

  • PUBLISH
  • SUBSCRIBE
  • UNSUBSCRIBE
  • PSUBSCRIBE
  • PUNSUBSCRIBE

The Lettuce server has been built based on documentation from the following sources:

License

Lettuce is free and open source software. The software is released under the terms of the GPL-3.0 license.

About

A redis server-side implemention in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages