replication

package
v0.0.0-...-dd03fda Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package crc64 implements the Jones coefficients with an init value of 0.

Thanks to github.com/cupcake/rdb for providing an early version of deocde

Index

Constants

This section is empty.

Variables

View Source
var (
	CommandTypeMap = map[string]CommandType{
		"ping":             Ping,
		"select":           Select,
		"zadd":             Zadd,
		"sadd":             Sadd,
		"zrem":             Zrem,
		"del":              Delete,
		"lpush":            Lpush,
		"lpushx":           LpushX,
		"rpush":            Rpush,
		"rpushx":           RpushX,
		"rpop":             Rpop,
		"rpoplpush":        RpopLpush,
		"lpop":             Lpop,
		"zremrangebylex":   ZremRangeByLex,
		"zremrangebyrank":  ZremRangeByRank,
		"zremrangebyscore": ZremRangeByScore,
		"zunionstore":      ZunionStore,
		"zincrby":          ZincrBy,
		"sdiffstore":       SdiffStore,
		"sinterstore":      SinterStore,
		"smove":            Smove,
		"sunionstore":      SunionStore,
		"srem":             Srem,
		"set":              Set,
		"setbit":           SetBit,
		"append":           Append,
		"bitfield":         BitField,
		"bitop":            BitOp,
		"decr":             Decr,
		"decrby":           DecrBy,
		"incr":             Incr,
		"incrby":           IncrBy,
		"incrbyfloat":      IncrByFloat,
		"getset":           GetSet,
		"mset":             Mset,
		"msetnx":           MsetNX,
		"setex":            SetEX,
		"setnx":            SetNX,
		"setrange":         SetRange,
		"blpop":            BlPop,
		"brpop":            BrPop,
		"brpoplpush":       BrPopLpush,
		"linsert":          Linsert,
		"lrem":             Lrem,
		"lset":             Lset,
		"ltrim":            Ltrim,
		"expire":           Expire,
		"expireat":         ExpireAt,
		"pexpire":          Pexpire,
		"pexpireat":        PexpireAt,
		"move":             Move,
		"persist":          Persist,
		"rename":           Rename,
		"restore":          Restore,
		"hset":             Hset,
		"hsetnx":           HsetNx,
		"hmset":            HmSet,
		"hincrby":          HincrBy,
		"hincrbyfloat":     HincrByFloat,
		"pfadd":            PfAdd,
		"pfmerge":          PfMerge,
		"psetx":            PsetX,
	}

	CommandNameMap = map[CommandType]string{
		Ping:             "ping",
		Select:           "select",
		Zadd:             "zadd",
		Sadd:             "sadd",
		Zrem:             "zrem",
		Delete:           "del",
		Lpush:            "lpush",
		LpushX:           "lpushx",
		Rpush:            "rpush",
		RpushX:           "rpushx",
		Rpop:             "rpop",
		RpopLpush:        "rpoplpush",
		Lpop:             "lpop",
		ZremRangeByLex:   "zremrangebylex",
		ZremRangeByRank:  "zremrangebyrank",
		ZremRangeByScore: "zremrangebyscore",
		ZunionStore:      "zunionstore",
		ZincrBy:          "zincrby",
		SdiffStore:       "sdiffstore",
		SinterStore:      "sinterstore",
		Smove:            "smove",
		SunionStore:      "sunionstore",
		Srem:             "srem",
		Set:              "set",
		SetBit:           "setbit",
		Append:           "append",
		BitField:         "bitfield",
		BitOp:            "bitop",
		Decr:             "decr",
		DecrBy:           "decrby",
		Incr:             "incr",
		IncrBy:           "incrby",
		IncrByFloat:      "incrbyfloat",
		GetSet:           "getset",
		Mset:             "mset",
		MsetNX:           "msetnx",
		SetEX:            "setex",
		SetNX:            "setnx",
		SetRange:         "setrange",
		BlPop:            "blpop",
		BrPop:            "brpop",
		BrPopLpush:       "brpoplpush",
		Linsert:          "linsert",
		Lrem:             "lrem",
		Lset:             "lset",
		Ltrim:            "ltrim",
		Expire:           "expire",
		ExpireAt:         "expireat",
		Pexpire:          "pexpire",
		PexpireAt:        "pexpireat",
		Move:             "move",
		Persist:          "persist",
		Rename:           "rename",
		Restore:          "restore",
		Hset:             "hset",
		HsetNx:           "hsetnx",
		HmSet:            "hmset",
		HincrBy:          "hincrby",
		HincrByFloat:     "hincrbyfloat",
		PfAdd:            "pfadd",
		PfMerge:          "pfmerge",
		PsetX:            "psetx",
	}
)
View Source
var NilValue = Value{Null: true}
View Source
var OKReply = "OK"

Functions

func Digest

func Digest(b []byte) uint64

func MultiBulkBytes

func MultiBulkBytes(val Value) ([]byte, int)

func New

func New() hash.Hash64

Types

type ByteReader

type ByteReader interface {
	io.Reader
	// io.ByteReader
	io.ByteScanner
}

type Command

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

Command all the command combinations

func NewCommand

func NewCommand(cmdType CommandType, args ...[]byte) Command

func (Command) Data

func (c Command) Data() []byte

func (Command) Name

func (c Command) Name() string

func (Command) Paramters

func (c Command) Paramters() [][]byte

func (Command) Type

func (c Command) Type() []byte

type CommandType

type CommandType string
const (
	RDB CommandType = "rdb"

	Ping CommandType = "ping"
	Pong CommandType = "pong"
	Ok   CommandType = "ok"
	Err  CommandType = "err"

	Empty     CommandType = "empty"
	Undefined CommandType = "undefined"

	Select    CommandType = "select"
	Zadd      CommandType = "zadd"
	Sadd      CommandType = "sadd"
	Zrem      CommandType = "zrem"
	Delete    CommandType = "delete"
	Lpush     CommandType = "lpush"
	LpushX    CommandType = "lpushx"
	Rpush     CommandType = "rpush"
	RpushX    CommandType = "rpushx"
	Rpop      CommandType = "rpop"
	RpopLpush CommandType = "rpoplpush"
	Lpop      CommandType = "lpop"

	ZremRangeByLex   CommandType = "zremrangebylex"
	ZremRangeByRank  CommandType = "zremrangebyrank"
	ZremRangeByScore CommandType = "zremrangebyscore"
	ZunionStore      CommandType = "zunionstore"
	ZincrBy          CommandType = "zincrby"
	SdiffStore       CommandType = "sdiffstore"
	SinterStore      CommandType = "sinterstore"
	Smove            CommandType = "smove"
	SunionStore      CommandType = "sunionstore"
	Srem             CommandType = "srem"
	Set              CommandType = "set"
	SetBit           CommandType = "setbit"

	Append       CommandType = "append"
	BitField     CommandType = "bitfield"
	BitOp        CommandType = "bitop"
	Decr         CommandType = "decr"
	DecrBy       CommandType = "decrby"
	Incr         CommandType = "incr"
	IncrBy       CommandType = "incrby"
	IncrByFloat  CommandType = "incrbyfloat"
	GetSet       CommandType = "getset"
	Mset         CommandType = "mset"
	MsetNX       CommandType = "msetnx"
	SetEX        CommandType = "setex"
	SetNX        CommandType = "setnx"
	SetRange     CommandType = "setrange"
	BlPop        CommandType = "blpop"
	BrPop        CommandType = "brpop"
	BrPopLpush   CommandType = "brpoplpush"
	Linsert      CommandType = "linsert"
	Lrem         CommandType = "lrem"
	Lset         CommandType = "lset"
	Ltrim        CommandType = "ltrim"
	Expire       CommandType = "expire"
	ExpireAt     CommandType = "expireat"
	Pexpire      CommandType = "pexpire"
	PexpireAt    CommandType = "pexpireat"
	Move         CommandType = "move"
	Persist      CommandType = "persist"
	Rename       CommandType = "rename"
	Restore      CommandType = "restore"
	Hset         CommandType = "hset"
	HsetNx       CommandType = "hsetnx"
	HmSet        CommandType = "hmset"
	HincrBy      CommandType = "hincrby"
	HincrByFloat CommandType = "hincrbyfloat"
	PfAdd        CommandType = "pfadd"
	PfMerge      CommandType = "pfmerge"
	PsetX        CommandType = "psetx"
)

type Decoder

type Decoder interface {
	// BeginDatabase is called when database n Begins.
	// Once a database Begins, another database will not Begin until EndDatabase is called.
	BeginDatabase(n int)
	// Set is called once for each string key.
	Set(key, value []byte, expiry int64)
	// BeginHash is called at the beginning of a hash.
	// Hset will be called exactly length times before EndHash.
	BeginHash(key []byte, length, expiry int64)
	// Hset is called once for each field=value pair in a hash.
	Hset(key, field, value []byte)
	// EndHash is called when there are no more fields in a hash.
	EndHash(key []byte)

	// BeginSet is called at the beginning of a set.
	// Sadd will be called exactly cardinality times before EndSet.
	BeginSet(key []byte, cardinality, expiry int64)
	// Sadd is called once for each member of a set.
	Sadd(key, member []byte)
	// EndSet is called when there are no more fields in a set.
	EndSet(key []byte)

	// BeginStream is called at the beginning of a stream.
	// Xadd will be called exactly length times before EndStream.
	BeginStream(key []byte, cardinality, expiry int64)
	// Xadd is called once for each id in a stream.
	Xadd(key, streamID, listpack []byte)
	// EndHash is called when there are no more fields in a hash.
	EndStream(key []byte)

	// BeginList is called at the beginning of a list.
	// Rpush will be called exactly length times before EndList.
	// If length of the list is not known, then length is -1
	BeginList(key []byte, length, expiry int64)
	// Rpush is called once for each value in a list.
	Rpush(key, value []byte)
	// EndList is called when there are no more values in a list.
	EndList(key []byte)

	// BeginZSet is called at the beginning of a sorted set.
	// Zadd will be called exactly cardinality times before EndZSet.
	BeginZSet(key []byte, cardinality, expiry int64)

	// Zadd is called once for each member of a sorted set.
	Zadd(key []byte, score float64, member []byte)

	// EndZSet is called when there are no more members in a sorted set.
	EndZSet(key []byte)

	// EndDatabase is called at the end of a database.
	EndDatabase(n int)

	// BeginRDB is called when parsing of a valid RDB file Begins.
	BeginRDB()
	// EndRDB is called when parsing of the RDB file is complete.
	EndRDB()
	// AUX field
	Aux(key, value []byte)
	// ResizeDB hint
	ResizeDatabase(dbSize, expiresSize uint32)
}

A Decodr must be implemented to parse a RDB io.Reader & parse a command io.Reader

type ErrProtocol

type ErrProtocol struct{ Msg string }

func (ErrProtocol) Error

func (err ErrProtocol) Error() string

type Nop

type Nop struct{}

Nop may be embedded in a real Decoder to avoid implementing methods.

func (Nop) Aux

func (d Nop) Aux(key, value []byte)

func (Nop) BeginDatabase

func (d Nop) BeginDatabase(n int)

func (Nop) BeginHash

func (d Nop) BeginHash(key []byte, length, expiry int64)

func (Nop) BeginList

func (d Nop) BeginList(key []byte, length, expiry int64)

func (Nop) BeginRDB

func (d Nop) BeginRDB()

func (Nop) BeginSet

func (d Nop) BeginSet(key []byte, cardinality, expiry int64)

func (Nop) BeginStream

func (d Nop) BeginStream(key []byte, cardinality, expiry int64)

func (Nop) BeginZSet

func (d Nop) BeginZSet(key []byte, cardinality, expiry int64)

func (Nop) EndDatabase

func (d Nop) EndDatabase(n int)

func (Nop) EndHash

func (d Nop) EndHash(key []byte)

func (Nop) EndList

func (d Nop) EndList(key []byte)

func (Nop) EndRDB

func (d Nop) EndRDB()

func (Nop) EndSet

func (d Nop) EndSet(key []byte)

func (Nop) EndStream

func (d Nop) EndStream(key []byte)

func (Nop) EndZSet

func (d Nop) EndZSet(key []byte)

func (Nop) Hset

func (d Nop) Hset(key, field, value []byte)

func (Nop) ResizeDatabase

func (d Nop) ResizeDatabase(dbSize, expiresSize uint32)

func (Nop) Rpush

func (d Nop) Rpush(key, value []byte)

func (Nop) Sadd

func (d Nop) Sadd(key, member []byte)

func (Nop) Set

func (d Nop) Set(key, value []byte, expiry int64)

func (Nop) Xadd

func (d Nop) Xadd(key, id, listpack []byte)

func (Nop) Zadd

func (d Nop) Zadd(key []byte, score float64, member []byte)

type Outer

type Outer interface {
	Receive(Command)
}

type Reader

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

Reader is a specialized RESP Value type reader.

func NewReader

func NewReader(rd io.Reader) *Reader

NewReader returns a Reader for reading Value types.

func (Reader) ReadLine

func (rd Reader) ReadLine() (line []byte, n int, err error)

func (*Reader) ReadMultiBulk

func (rd *Reader) ReadMultiBulk() (value Value, telnet bool, n int, err error)

ReadMultiBulk reads the next multi bulk Value from Reader. A multi bulk value is a RESP ArrayV that contains one or more bulk strings. For more information on RESP arrays and strings please see http://redis.io/topics/protocol.

func (*Reader) ReadValue

func (rd *Reader) ReadValue() (value Value, n int, err error)

ReadValue reads the next Value from Reader.

type Replication

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

func NewReplication

func NewReplication(t tp.Topologist, stge io.Writer, out Outer) *Replication

func (*Replication) Start

func (r *Replication) Start() (func(), error)

type Type

type Type byte

Type represents a Value type

const (
	SimpleString Type = '+'
	Error        Type = '-'
	Integer      Type = ':'
	BulkString   Type = '$'
	Array        Type = '*'
	Rdb          Type = 'R'
	CRLF         Type = '\r'
)

func (Type) String

func (t Type) String() string

TypeName returns name of the underlying RESP type.

type Value

type Value struct {
	Typ      Type
	IntegerV int
	Str      []byte
	ArrayV   []Value
	Null     bool
	RDB      bool
	Size     int
}

Value represents the data of a valid RESP type.

func AnyValue

func AnyValue(v interface{}) Value

AnyValue returns a RESP value from an interface. This function infers the types. Arrays are not allowed.

func ArrayValue

func ArrayValue(vals []Value) Value

ArrayValue returns a RESP array.

func BoolValue

func BoolValue(t bool) Value

BoolValue returns a RESP integer representation of a bool.

func BytesValue

func BytesValue(b []byte) Value

BytesValue returns a RESP bulk string. A bulk string can represent any data.

func ErrorValue

func ErrorValue(err error) Value

ErrorValue returns a RESP error.

func FloatValue

func FloatValue(f float64) Value

FloatValue returns a RESP bulk string representation of a float.

func IntegerValue

func IntegerValue(i int) Value

IntegerValue returns a RESP integer.

func MultiBulkValue

func MultiBulkValue(commandName string, args ...interface{}) Value

MultiBulkValue returns a RESP array which contains one or more bulk strings. For more information on RESP arrays and strings please see http://redis.io/topics/protocol.

func NullValue

func NullValue() Value

NullValue returns a RESP null bulk string.

func SimpleStringValue

func SimpleStringValue(s string) Value

SimpleStringValue returns a RESP simple string. A simple string has no new lines. The carriage return and new line characters are replaced with spaces.

func StringValue

func StringValue(s string) Value

StringValue returns a RESP bulk string. A bulk string can represent any data.

func (Value) Array

func (v Value) Array() []Value

Array converts the Value to a an array. If Value is not an array or when it's is a RESP Null value, nil is returned.

func (Value) Bool

func (v Value) Bool() bool

Bool converts Value to an bool. If Value cannot be converted, false is returned.

func (Value) Bytes

func (v Value) Bytes() []byte

Bytes converts the Value to a byte array. An empty string is converted to a non-nil empty byte array. If it's a RESP Null value, nil is returned.

func (Value) Equals

func (v Value) Equals(value Value) bool

Equals compares one value to another value.

func (Value) Error

func (v Value) Error() error

Error converts the Value to an error. If Value is not an error, nil is returned.

func (Value) Float

func (v Value) Float() float64

Float converts Value to a float64. If Value cannot be converted Zero is returned.

func (Value) Integer

func (v Value) Integer() int

Integer converts Value to an int. If Value cannot be converted, Zero is returned.

func (Value) IsNull

func (v Value) IsNull() bool

IsNull indicates whether or not the base value is null.

func (Value) MarshalRESP

func (v Value) MarshalRESP() ([]byte, error)

MarshalRESP returns the original serialized byte representation of Value. For more information on this format please see http://redis.io/topics/protocol.

func (Value) ReplInfo

func (v Value) ReplInfo() (runID string, offset int64)

func (Value) String

func (v Value) String() string

String converts Value to a string.

func (Value) Type

func (v Value) Type() Type

Type returns the underlying RESP type. The following types are represent valid RESP values.

'+'  SimpleString
'-'  Error
':'  Integer
'$'  BulkString
'*'  Array
'R'  Rdb
'\r' Crlf

type ValueType

type ValueType byte

ValueType of redis type

const (
	TypeString  ValueType = 0
	TypeList    ValueType = 1
	TypeSet     ValueType = 2
	TypeZSet    ValueType = 3
	TypeHash    ValueType = 4
	TypeZSet2   ValueType = 5
	TypeModule  ValueType = 6
	TypeModule2 ValueType = 7

	TypeHashZipmap      ValueType = 9
	TypeListZiplist     ValueType = 10
	TypeSetIntset       ValueType = 11
	TypeZSetZiplist     ValueType = 12
	TypeHashZiplist     ValueType = 13
	TypeListQuicklist   ValueType = 14
	TypeStreamListPacks ValueType = 15
)

type value

Jump to

Keyboard shortcuts

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