redis

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LocalHost   = "localhost"
	DefaultPort = 6379
	OK          = "OK"
)
View Source
const (
	Version = "v0.9.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Arguments added in v1.0.0

type Arguments = *proto.Array

type CommandHandler

CommandHandler represents a command hander interface for user commands.

type DBContext

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

DBContext represents a database connection context.

func (*DBContext) ID

func (ctx *DBContext) ID() int

ID returns the current selected database ID.

type Executor added in v1.0.0

type Executor func(*DBContext, string, Arguments) (*Message, error)

type Executors added in v1.0.0

type Executors map[string]Executor

type ExpireOption added in v1.0.0

type ExpireOption struct {
	Time time.Time
	NX   bool
	XX   bool
	GT   bool
	LT   bool
}

type GenericCommandHandler added in v1.0.0

type GenericCommandHandler interface {
	// 1.0.0
	Del(ctx *DBContext, keys []string) (*Message, error)
	Exists(ctx *DBContext, keys []string) (*Message, error)
	Expire(ctx *DBContext, key string, opt ExpireOption) (*Message, error)
	Keys(ctx *DBContext, pattern string) (*Message, error)
	Rename(ctx *DBContext, key string, newkey string, opt RenameOption) (*Message, error)
	Type(ctx *DBContext, key string) (*Message, error)
	TTL(ctx *DBContext, key string) (*Message, error)
}

GenericCommandHandler represents a hander interface for genelic commands.

type HSetOption added in v1.0.0

type HSetOption struct {
	NX bool
}

type HashCommandHandler added in v1.0.0

type HashCommandHandler interface {
	HDel(ctx *DBContext, key string, fields []string) (*Message, error)
	HSet(ctx *DBContext, key string, field string, val string, opt HSetOption) (*Message, error)
	HGet(ctx *DBContext, key string, field string) (*Message, error)
	HGetAll(ctx *DBContext, key string) (*Message, error)
	HMSet(ctx *DBContext, key string, dict map[string]string) (*Message, error)
	HMGet(ctx *DBContext, key string, fields []string) (*Message, error)
}

HashCommandHandler represents a core command hander interface for hash commands.

type MSetOption added in v1.0.0

type MSetOption struct {
	NX bool
}

type Message

type Message = proto.Message

Message represents a message of Redis serialization protocol.

func NewArrayMessage added in v1.0.0

func NewArrayMessage() *Message

NewArrayMessage creates an empty array message.

func NewBulkMessage

func NewBulkMessage(msg string) *Message

NewBulkMessage creates a bulk string message.

func NewErrorMessage

func NewErrorMessage(err error) *Message

NewErrorMessage creates an error message.

func NewIntegerMessage

func NewIntegerMessage(val int) *Message

NewIntegerMessage creates an integer message.

func NewNilMessage

func NewNilMessage() *Message

NewNilMessage creates a nil bulk string message.

func NewOKMessage

func NewOKMessage() *Message

NewOKMessage creates a OK string message.

func NewStringArrayMessage added in v1.0.0

func NewStringArrayMessage(strs []string) *Message

NewStringArrayMessage creates an array message with the specified strings.

func NewStringMessage

func NewStringMessage(msg string) *Message

NewStringMessage creates a string message.

type RenameOption added in v1.0.0

type RenameOption struct {
	NX bool
}

type Server

type Server struct {
	Addr string
	Port int
	// contains filtered or unexported fields
}

Server is an instance for Redis protocols.

func NewServer

func NewServer() *Server

NewServer returns a new server instance.

func (*Server) Echo

func (server *Server) Echo(ctx *DBContext, arg string) (*Message, error)

func (*Server) Ping

func (server *Server) Ping(ctx *DBContext, arg string) (*Message, error)

func (*Server) Quit

func (server *Server) Quit(ctx *DBContext) (*Message, error)

func (*Server) RegisterExexutor added in v1.0.0

func (server *Server) RegisterExexutor(cmd string, executor Executor)

RegisterExexutor sets a command executor.

func (*Server) Restart

func (server *Server) Restart() error

Restart restarts the server.

func (*Server) Select

func (server *Server) Select(ctx *DBContext, index int) (*Message, error)

func (*Server) SetCommandHandler

func (server *Server) SetCommandHandler(handler CommandHandler)

SetCommandHandler sets a user handler to handle user commands.

func (*Server) Start

func (server *Server) Start() error

Start starts the server.

func (*Server) Stop

func (server *Server) Stop() error

Stop stops the server.

type SetOption

type SetOption struct {
	EX      time.Duration
	PX      time.Duration
	EXAT    time.Time
	PXAT    time.Time
	NX      bool
	XX      bool
	KEEPTTL bool
	GET     bool
}

type StringCommandHandler added in v1.0.0

type StringCommandHandler interface {
	Set(ctx *DBContext, key string, val string, opt SetOption) (*Message, error)
	Get(ctx *DBContext, key string) (*Message, error)
	MSet(ctx *DBContext, dict map[string]string, opt MSetOption) (*Message, error)
	MGet(ctx *DBContext, keys []string) (*Message, error)
}

StringHandler represents a core command hander interface for string commands.

type SystemCommandHandler

type SystemCommandHandler interface {
	Ping(ctx *DBContext, arg string) (*Message, error)
	Echo(ctx *DBContext, arg string) (*Message, error)
	Select(ctx *DBContext, index int) (*Message, error)
	Quit(ctx *DBContext) (*Message, error)
}

SystemCommandHandler represents a hander interface for system commands.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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