GithubHelp home page GithubHelp logo

r0123r / go-redis-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from platinasystems/go-redis-server

0.0 0.0 0.0 138 KB

A Go implementation of the Redis server protocol

License: Apache License 2.0

Makefile 0.27% Go 99.73%

go-redis-server's Introduction

Redis server protocol library

There are plenty of good client implementations of the redis protocol, but not many server implementations.

go-redis-server is a helper library for building server software capable of speaking the redis protocol. This could be an alternate implementation of redis, a custom proxy to redis, or even a completely different backend capable of "masquerading" its API as a redis database.

Support standart redis-cli.

Sample code

package main

import (
	"fmt"
	"log"

	redis "github.com/r0123r/go-redis-server"
)

type MyHandler struct {
	*redis.DefaultHandler
}

func NewMyHandler() *MyHandler {
	h := redis.NewDefaultHandler()
	return &MyHandler{h}
}

// Test implement a new command. Non-redis standard, but it is possible.
func (h *MyHandler) Test() ([]byte, error) {
	return []byte("Awesome custom redis command!"), nil
}

// Get override the DefaultHandler's method.
func (h *MyHandler) Set(key string, args ...[]byte) error {
	// However, we still can call the DefaultHandler GET method and use it.
	err := h.DefaultHandler.Set(key, args...)
	if err != nil {
		return err
	}
	notify := fmt.Sprint("__keyspace@", h.DefaultHandler.CurrentDb, "__:", key)
	log.Print(notify)
	h.Publish(notify, []byte("set"))
	return nil
}

// Test2 implement a new command. Non-redis standard, but it is possible.
// This function needs to be registered.
func Test2() ([]byte, error) {
	return []byte("Awesome custom redis command via function!"), nil
}

func main() {
	myhandler := NewMyHandler()
	srv, err := redis.NewServer(redis.DefaultConfig().Proto("tcp").Port(88).Host("localhost").Handler(myhandler))
	if err != nil {
		log.Println(err)
	}
	if err := srv.RegisterFct("test2", Test2); err != nil {
		log.Println(err)
	}
	if err := srv.Start(); err != nil {
		log.Println(err)
	}
}

Compatible Redis commands

  • Pub/Sub
    • Subscribe
    • Publish
  • Connection
    • Ping
    • Select
  • Hashes
    • HGet
    • HGetAll
    • HSet
    • HMSet
    • Hlen
  • Keys
    • Del
    • Keys
    • Exists
    • Expire
    • Rename
    • Ttl
    • Type
    • Scan
  • Lists
    • Rpush
    • Brpop
    • Blpop
    • Lrange
    • Lindex
    • Lpush
    • Llen
    • Lset
    • Lrem
  • Server
    • Config get
    • DBsize
    • FlushDb
    • FlushAll
    • Info
    • Monitor
    • Time
  • Strings
    • Get
    • MGet
    • Set
    • MSet
    • Decr
    • Incr
  • Sorted Sets
    • ZAdd
    • Zrange
    • Zrangebyscore
    • Zrem
    • Zremrangebyscore
    • Zcard
    • Zscore

go-redis-server's People

Contributors

creack avatar dim avatar jharlap avatar klizhentas avatar kph avatar r0123r avatar schumajs avatar tgrennan avatar tsanyen avatar vieux 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.