server

package
v0.0.0-...-9121635 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2014 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package server supplies a way to use ledis as service. Server implements the redis protocol called RESP (REdis Serialization Protocol). For more information, please see http://redis.io/topics/protocol.

You can use ledis with many available redis clients directly, for example, redis-cli. But I also supply some ledis client at client folder, and have been adding more for other languages.

Usage

Start a ledis server is very simple:

cfg := new(Config)
cfg.Addr = "127.0.0.1:6380"
cfg.DataDir = "/tmp/ledis"
app := server.NewApp(cfg)
app.Run()

Replication

You can start a slave ledis server for replication, open slave is simple too, you can set slaveof in config or run slaveof command in shell.

For example, if you start a slave server, and the master server's address is 127.0.0.1:6380, you can start replication in shell:

ledis-cli -p 6381
ledis 127.0.0.1:6381 > slaveof 127.0.0.1 6380

After you send slaveof command, the slave will start to sync master's binlog and replicate from binlog.

HTTP Interface

LedisDB provides http interfaces for most commands(except the replication commands)

curl http://127.0.0.1:11181/SET/hello/world
→ {"SET":[true,"OK"]}

curl http://127.0.0.1:11181/0/GET/hello?type=json
→ {"GET":"world"}

Index

Constants

View Source
const (
	MAX_DEVICE_NUM     = 8
	DEFALUT_MEMBER_NUM = 5
)
View Source
const (
	API_URL_REGISTER = "api/member/register.json"
)
View Source
const (
	MYCHAT_MAX_MESSAGE = 100
)

Variables

View Source
var (
	ErrEmptyCommand = errors.New("empty command")
	ErrNotFound     = errors.New("command not found")
	ErrCmdParams    = errors.New("invalid command param")
	ErrValue        = errors.New("value is not an integer or out of range")
	ErrSyntax       = errors.New("syntax error")
	ErrOffset       = errors.New("offset bit is not an natural number")
	ErrBool         = errors.New("value is not 0 or 1")
)
View Source
var (
	Delims = []byte("\r\n")

	NullBulk  = []byte("-1")
	NullArray = []byte("-1")

	PONG = "PONG"
	OK   = "OK"
)

Functions

func ReadBulkTo

func ReadBulkTo(rb *bufio.Reader, w io.Writer) error

func ReadLine

func ReadLine(rb *bufio.Reader) ([]byte, error)

Types

type App

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

func NewApp

func NewApp(cfg *Config) (*App, error)

func (*App) Close

func (app *App) Close()

func (*App) LoadAllFamily

func (app *App) LoadAllFamily() error

func (*App) LoadAllNodeId

func (app *App) LoadAllNodeId(family *Family) error

func (*App) LoadFamily

func (app *App) LoadFamily(hostname string, uuid string) error

func (*App) Run

func (app *App) Run()

type CommandFunc

type CommandFunc func(req *requestContext) error

type Config

type Config struct {
	Addr string `json:"addr"`

	HttpAddr string `json:"http_addr"`

	DataDir string `json:"data_dir"`

	AccessLog string `json:"access_log"`

	MysqlConf dbConfig `json:"mysqldb"`
}

func NewConfig

func NewConfig(data json.RawMessage) (*Config, error)

func NewConfigWithFile

func NewConfigWithFile(fileName string) (*Config, error)

type Family

type Family struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

family

func (*Family) DeviceLoginOut

func (this *Family) DeviceLoginOut(devname string)

func (*Family) GetAllMemberInfo

func (this *Family) GetAllMemberInfo() []byte

func (*Family) GetAllNodeInfo

func (this *Family) GetAllNodeInfo() []byte

func (*Family) GetDevice

func (this *Family) GetDevice(devname string) *Node

func (*Family) GetMember

func (this *Family) GetMember(username string) *Node

func (*Family) InsertDevice

func (this *Family) InsertDevice(db *sql.DB, devname string) (*Node, error)

func (*Family) InsertMember

func (this *Family) InsertMember(db *sql.DB, name, pasword string) (*Node, error)

func (*Family) MemberLoginOut

func (this *Family) MemberLoginOut(username string)

func (*Family) NewDevice

func (this *Family) NewDevice(devname string) (*Node, bool)

func (*Family) NewMember

func (this *Family) NewMember(username string) (*Node, bool)

func (*Family) SendMsgToAll

func (this *Family) SendMsgToAll(msg []byte)

func (*Family) SendMsgToOtherMembers

func (this *Family) SendMsgToOtherMembers(msg []byte, c *Node)

type FamilyMgr

type FamilyMgr struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*FamilyMgr) GetFamilyByHostName

func (this *FamilyMgr) GetFamilyByHostName(hostname string) *Family

func (*FamilyMgr) GetFamilyByNodeName

func (this *FamilyMgr) GetFamilyByNodeName(nodename string) *Family

func (*FamilyMgr) GetFamilyByUUID

func (this *FamilyMgr) GetFamilyByUUID(uuid string) *Family

func (*FamilyMgr) GetMember

func (this *FamilyMgr) GetMember(username string) *Node

func (*FamilyMgr) NewFamily

func (this *FamilyMgr) NewFamily(hostname string) (*Family, bool)

type Node

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

func (*Node) Off

func (this *Node) Off()

func (*Node) On

func (this *Node) On(c *requestContext)

type NodeType

type NodeType uint8
const (
	NODE_MEMBER NodeType = iota + 1
	NODE_DEVICE
)

type RegisterError

type RegisterError uint8

func (RegisterError) Error

func (er RegisterError) Error() string

Jump to

Keyboard shortcuts

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