redis

package module
v0.0.0-...-e4d48d5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2013 License: Apache-2.0 Imports: 14 Imported by: 1

README

Build Status

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.

Sample code

package main

import (
	redis "github.com/dotcloud/go-redis-server"
)

type MyHandler struct {
	values map[string][]byte
}

func (h *MyHandler) GET(key string) ([]byte, error) {
	v := h.values[key]
	return v, nil
}

func (h *MyHandler) SET(key string, value []byte) error {
	h.values[key] = value
	return nil
}

func main() {
	handler, _ := redis.NewAutoHandler(&MyHandler{values: make(map[string][]byte)})
	server := &redis.Server{Handler: handler, Addr: ":6389"}
	server.ListenAndServe()
}

Copyright (c) dotCloud 2013

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodNotSupported   = NewError("Method is not supported")
	ErrNotEnoughArgs        = NewError("Not enough arguments for the command")
	ErrTooMuchArgs          = NewError("Too many arguments for the command")
	ErrWrongArgsNumber      = NewError("Wrong number of arguments")
	ErrExpectInteger        = NewError("Expected integer")
	ErrExpectPositivInteger = NewError("Expected positive integer")
	ErrExpectMorePair       = NewError("Expected at least one key val pair")
	ErrExpectEvenPair       = NewError("Got uneven number of key val pairs")
)
View Source
var (
	ErrParseTimeout = errors.New("timeout is not an integer or out of range")
)

Functions

func Debugf

func Debugf(format string, a ...interface{})

Debug function, if the debug flag is set, then display. Do nothing otherwise If Docker is in damon mode, also send the debug info on the socket Convenience debug function, courtesy of http://github.com/dotcloud/docker

func ReplyToString

func ReplyToString(r ReplyWriter) (string, error)

Types

type BulkReply

type BulkReply struct {
	// contains filtered or unexported fields
}

func (*BulkReply) WriteTo

func (r *BulkReply) WriteTo(w io.Writer) (int64, error)

type ChannelWriter

type ChannelWriter struct {
	FirstReply []interface{}
	Channel    chan []interface{}
	// contains filtered or unexported fields
}

func (*ChannelWriter) WriteTo

func (c *ChannelWriter) WriteTo(w io.Writer) (int64, error)

type CheckerFn

type CheckerFn func(request *Request) (reflect.Value, ReplyWriter)

type Config

type Config struct {
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) Handler

func (c *Config) Handler(h interface{}) *Config

func (*Config) Host

func (c *Config) Host(h string) *Config

func (*Config) Port

func (c *Config) Port(p int) *Config

func (*Config) Proto

func (c *Config) Proto(p string) *Config

type Database

type Database struct {
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(parent *Database) *Database

type DefaultHandler

type DefaultHandler struct {
	*Database
	// contains filtered or unexported fields
}

func NewDefaultHandler

func NewDefaultHandler() *DefaultHandler

func (*DefaultHandler) Blpop

func (h *DefaultHandler) Blpop(key string, keys ...string) (data [][]byte, err error)

func (*DefaultHandler) Brpop

func (h *DefaultHandler) Brpop(key string, keys ...string) (data [][]byte, err error)

func (*DefaultHandler) Del

func (h *DefaultHandler) Del(key string, keys ...string) (int, error)

func (*DefaultHandler) Get

func (h *DefaultHandler) Get(key string) ([]byte, error)

func (*DefaultHandler) Hget

func (h *DefaultHandler) Hget(key, subkey string) ([]byte, error)

func (*DefaultHandler) Hgetall

func (h *DefaultHandler) Hgetall(key string) (HashValue, error)

func (*DefaultHandler) Hset

func (h *DefaultHandler) Hset(key, subkey string, value []byte) (int, error)

func (*DefaultHandler) Lindex

func (h *DefaultHandler) Lindex(key string, index int) ([]byte, error)

func (*DefaultHandler) Lpush

func (h *DefaultHandler) Lpush(key string, value []byte, values ...[]byte) (int, error)

func (*DefaultHandler) Lrange

func (h *DefaultHandler) Lrange(key string, start, stop int) ([][]byte, error)

func (*DefaultHandler) Monitor

func (h *DefaultHandler) Monitor() (*MonitorReply, error)

func (*DefaultHandler) Ping

func (h *DefaultHandler) Ping() (*StatusReply, error)

func (*DefaultHandler) Publish

func (h *DefaultHandler) Publish(key string, value []byte) (int, error)

func (*DefaultHandler) Rpush

func (h *DefaultHandler) Rpush(key string, value []byte, values ...[]byte) (int, error)

func (*DefaultHandler) Select

func (h *DefaultHandler) Select(key string) error

func (*DefaultHandler) Set

func (h *DefaultHandler) Set(key string, value []byte) error

func (*DefaultHandler) Subscribe

func (h *DefaultHandler) Subscribe(channels ...[]byte) (*MultiChannelWriter, error)

type ErrorReply

type ErrorReply struct {
	// contains filtered or unexported fields
}

func NewError

func NewError(message string) *ErrorReply

func (*ErrorReply) Error

func (er *ErrorReply) Error() string

func (*ErrorReply) WriteTo

func (er *ErrorReply) WriteTo(w io.Writer) (int64, error)

type HandlerFn

type HandlerFn func(r *Request) (ReplyWriter, error)

type HashBrStack

type HashBrStack map[string]*Stack

type HashHash

type HashHash map[string]HashValue

type HashSub

type HashSub map[string][]*ChannelWriter

type HashValue

type HashValue map[string][]byte

type IntegerReply

type IntegerReply struct {
	// contains filtered or unexported fields
}

func (*IntegerReply) WriteTo

func (r *IntegerReply) WriteTo(w io.Writer) (int64, error)

type MonitorReply

type MonitorReply struct {
	// contains filtered or unexported fields
}

func (*MonitorReply) WriteTo

func (r *MonitorReply) WriteTo(w io.Writer) (int64, error)

type MultiBulkReply

type MultiBulkReply struct {
	// contains filtered or unexported fields
}

for nil reply in multi bulk just set []byte as nil

func MultiBulkFromMap

func MultiBulkFromMap(m map[string]interface{}) *MultiBulkReply

func (*MultiBulkReply) WriteTo

func (r *MultiBulkReply) WriteTo(w io.Writer) (int64, error)

type MultiChannelWriter

type MultiChannelWriter struct {
	Chans []*ChannelWriter
}

func (*MultiChannelWriter) WriteTo

func (c *MultiChannelWriter) WriteTo(w io.Writer) (n int64, err error)

type ReplyWriter

type ReplyWriter io.WriterTo

type Request

type Request struct {
	Name       string
	Args       [][]byte
	Host       string
	ClientChan chan struct{}
	Body       io.ReadCloser
}

func (*Request) ExpectArgument

func (r *Request) ExpectArgument(index int) ReplyWriter

func (*Request) GetInteger

func (r *Request) GetInteger(index int) (int, ReplyWriter)

func (*Request) GetMap

func (r *Request) GetMap(index int) (map[string][]byte, ReplyWriter)

func (*Request) GetPositiveInteger

func (r *Request) GetPositiveInteger(index int) (int, ReplyWriter)

func (*Request) GetString

func (r *Request) GetString(index int) (string, ReplyWriter)

func (*Request) GetStringSlice

func (r *Request) GetStringSlice(index int) ([]string, ReplyWriter)

func (*Request) HasArgument

func (r *Request) HasArgument(index int) bool

type Server

type Server struct {
	Proto        string
	Addr         string // TCP address to listen on, ":6389" if empty
	MonitorChans []chan string
	// contains filtered or unexported fields
}

func NewServer

func NewServer(c *Config) (*Server, error)

func (*Server) Apply

func (srv *Server) Apply(r *Request) (ReplyWriter, error)

func (*Server) ApplyString

func (srv *Server) ApplyString(r *Request) (string, error)

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

func (*Server) Register

func (srv *Server) Register(name string, fn HandlerFn)

func (*Server) RegisterFct

func (srv *Server) RegisterFct(key string, f interface{}) error

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the Listener l, creating a new service goroutine for each. The service goroutines read requests and then call srv.Handler to reply to them.

func (*Server) ServeClient

func (srv *Server) ServeClient(conn net.Conn) (err error)

Serve starts a new redis session, using `conn` as a transport. It reads commands using the redis protocol, passes them to `handler`, and returns the result.

type Stack

type Stack struct {
	sync.Mutex
	Key string

	Chan chan *Stack
	// contains filtered or unexported fields
}

func NewStack

func NewStack(key string) *Stack

func (*Stack) GetIndex

func (s *Stack) GetIndex(index int) []byte

GetIndex return the element at the requested index. If no element correspond, return nil.

func (*Stack) Len

func (s *Stack) Len() int

func (*Stack) PopBack

func (s *Stack) PopBack() []byte

func (*Stack) PopFront

func (s *Stack) PopFront() []byte

func (*Stack) PushBack

func (s *Stack) PushBack(val []byte)

func (*Stack) PushFront

func (s *Stack) PushFront(val []byte)

type StatusReply

type StatusReply struct {
	// contains filtered or unexported fields
}

func (*StatusReply) WriteTo

func (r *StatusReply) WriteTo(w io.Writer) (int64, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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