server

package
v0.0.0-...-ec867fc Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2019 License: MIT Imports: 39 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 := config.NewConfigDefault()
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 write ahead log and replicate from it. You must notice that use_replication must be set true if you want to use it.

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 (
	KV   ledis.DataType = ledis.KV
	LIST                = ledis.LIST
	HASH                = ledis.HASH
	SET                 = ledis.SET
	ZSET                = ledis.ZSET
)
View Source
const (
	KVName   = ledis.KVName
	ListName = ledis.ListName
	HashName = ledis.HashName
	SetName  = ledis.SetName
	ZSetName = ledis.ZSetName
)
View Source
const (
	GB uint64 = 1024 * 1024 * 1024
	MB uint64 = 1024 * 1024
	KB uint64 = 1024
)

Variables

View Source
var (
	ErrEmptyCommand          = errors.New("empty command")
	ErrNotFound              = errors.New("command not found")
	ErrNotAuthenticated      = errors.New("not authenticated")
	ErrAuthenticationFailure = errors.New("authentication failure")
	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"
	NOKEY = "NOKEY"
)

Functions

func Publish

func Publish(app *App, key, value []byte) int64

Types

type App

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

func NewApp

func NewApp(cfg *config.Config, build string) (*App, error)

func (*App) Address

func (app *App) Address() string

func (*App) Close

func (app *App) Close()

func (*App) Ledis

func (app *App) Ledis() *ledis.Ledis

func (*App) Run

func (app *App) Run()

type CommandFunc

type CommandFunc func(c *client) error

type LedisClientDriver

type LedisClientDriver struct {
	server.ClientHandlingDriver
	RootPath string // Base directory from which to server file
	// contains filtered or unexported fields
}

ClientDriver defines a very basic client driver

func (*LedisClientDriver) AsyncListFiles

func (driver *LedisClientDriver) AsyncListFiles(cc server.ClientContext, cfiles chan<- os.FileInfo)

ListFiles lists the files of a directory

func (*LedisClientDriver) CanAllocate

func (driver *LedisClientDriver) CanAllocate(cc server.ClientContext, size int) (bool, error)

CanAllocate gives the approval to allocate some data

func (*LedisClientDriver) ChangeDirectory

func (driver *LedisClientDriver) ChangeDirectory(cc server.ClientContext, path string) error

ChangeDirectory changes the current working directory

func (*LedisClientDriver) ChmodFile

func (driver *LedisClientDriver) ChmodFile(cc server.ClientContext, path string, mode os.FileMode) error

ChmodFile changes the attributes of the file

func (*LedisClientDriver) DeleteFile

func (driver *LedisClientDriver) DeleteFile(cc server.ClientContext, path string) error

DeleteFile deletes a file or a directory

func (*LedisClientDriver) GetAtr

func (driver *LedisClientDriver) GetAtr(rpath []byte, isdir bool) (os.FileInfo, error)

func (*LedisClientDriver) GetFileInfo

func (driver *LedisClientDriver) GetFileInfo(cc server.ClientContext, path string) (os.FileInfo, error)

GetFileInfo gets some info around a file or a directory

func (*LedisClientDriver) ListFiles

func (driver *LedisClientDriver) ListFiles(cc server.ClientContext) ([]os.FileInfo, error)

ListFiles lists the files of a directory

func (*LedisClientDriver) MakeDirectory

func (driver *LedisClientDriver) MakeDirectory(cc server.ClientContext, path string) error

MakeDirectory creates a directory

func (*LedisClientDriver) OpenFile

func (driver *LedisClientDriver) OpenFile(cc server.ClientContext, path string, flag int) (server.FileStream, error)

OpenFile opens a file in 3 possible modes: read, write, appending write (use appropriate flags)

func (*LedisClientDriver) RenameFile

func (driver *LedisClientDriver) RenameFile(cc server.ClientContext, from, to string) error

RenameFile renames a file or a directory

type LedisDriver

type LedisDriver struct {
	server.MainDriver
	Ldb     *ledis.Ledis
	BaseDir string // Base directory from which to serve file
	// contains filtered or unexported fields
}

func (*LedisDriver) AuthUser

func (driver *LedisDriver) AuthUser(cc server.ClientContext, user, pass string) (server.ClientHandlingDriver, error)

AuthUser authenticates the user and selects an handling driver

func (*LedisDriver) GetSettings

func (driver *LedisDriver) GetSettings() (*server.Settings, error)

func (*LedisDriver) UserLeft

func (driver *LedisDriver) UserLeft(cc server.ClientContext)

UserLeft is called when the user disconnects, even if he never authenticated

func (*LedisDriver) WelcomeUser

func (driver *LedisDriver) WelcomeUser(cc server.ClientContext) (string, error)

type LedisVirtualFile

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

The virtual file is an example of how you can implement a purely virtual file

func (*LedisVirtualFile) Close

func (f *LedisVirtualFile) Close() error

func (*LedisVirtualFile) Read

func (f *LedisVirtualFile) Read(buffer []byte) (int, error)

func (*LedisVirtualFile) Seek

func (f *LedisVirtualFile) Seek(n int64, w int) (int64, error)

func (*LedisVirtualFile) Write

func (f *LedisVirtualFile) Write(buffer []byte) (int, error)

type VirtualFileInfo

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

func (*VirtualFileInfo) IsDir

func (f *VirtualFileInfo) IsDir() bool

func (*VirtualFileInfo) ModTime

func (f *VirtualFileInfo) ModTime() time.Time

func (*VirtualFileInfo) Mode

func (f *VirtualFileInfo) Mode() os.FileMode

func (*VirtualFileInfo) Name

func (f *VirtualFileInfo) Name() string

func (*VirtualFileInfo) Size

func (f *VirtualFileInfo) Size() int64

func (*VirtualFileInfo) Sys

func (f *VirtualFileInfo) Sys() interface{}

Jump to

Keyboard shortcuts

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