redcas

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 12 Imported by: 0

Documentation

Overview

Package redcas realizes CAS extension function.

Index

Constants

View Source
const (
	ForceSetCAS = -1            // Mandatory modification cas.
	MaxCAS      = math.MaxInt32 // Lua only supports float64,

)
View Source
const (
	// SetLua set lua script.
	SetLua = `` /* 656-byte string literal not displayed */

	// HSetLua lua script.
	HSetLua = `` /* 454-byte string literal not displayed */

	// MSetLua MSet lua script.
	MSetLua = `` /* 605-byte string literal not displayed */

	// HMSetLua HMSet lua script.
	HMSetLua = `` /* 755-byte string literal not displayed */

)

lua script.

Variables

View Source
var (
	// SetScript is set script optimizer.
	// Execute and upload the script through Eval if the server does not exist,
	// and execute it through EvalSha if it exists.
	SetScript = script.New(SetLua)
	// HSetScript HSet script optimization.
	// Execute and upload the script through Eval if the server does not exist,
	// and execute it through EvalSha if it exists.
	HSetScript = script.New(HSetLua)
	// MSetScript MSet script optimization.
	// Execute and upload the script through Eval if the server does not exist,
	// and execute it through EvalSha if it exists.
	MSetScript = script.New(MSetLua)
	// HMSetScript HMSet script optimization.
	// Execute and upload the script through Eval if the server does not exist,
	// and execute it through EvalSha if it exists.
	HMSetScript = script.New(HMSetLua)
)

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string.

func Decode

func Decode(raw []byte) ([]byte, int64, error)

Decode is to decode packet.

func Encode

func Encode(value []byte, cas int64) []byte

Encode is to encode packet.

func Marshal

func Marshal(in interface{}) ([]byte, error)

Marshal is type instantiation.

func MarshalJSONString

func MarshalJSONString(v interface{}) string

MarshalJSONString is convenient for printing logs.

func NextCAS

func NextCAS(cas int64) int64

NextCAS calculates the next cas.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice.

func Unmarshal

func Unmarshal(in []byte, message interface{}) error

Unmarshal is type deserialization.

Types

type GetCmd

type GetCmd struct {
	*redis.StringCmd
}

GetCmd get command.

func Get

func Get(ctx context.Context, c redis.Cmdable, key string) *GetCmd

Get redis Get, redis.Nil indicates that the key does not exist.

func HGet

func HGet(ctx context.Context, c redis.Cmdable, key, field string) *GetCmd

HGet redis hget, redis.Nil indicates that the key does not exist.

func (*GetCmd) Bytes

func (cmd *GetCmd) Bytes() ([]byte, int64, error)

Bytes gets the result converted to []byte.

func (*GetCmd) Result

func (cmd *GetCmd) Result() (string, int64, error)

Result gets results.

func (*GetCmd) Unmarshal

func (cmd *GetCmd) Unmarshal(message interface{}) (int64, error)

Unmarshal is type parsing for commonly used types.

func (*GetCmd) Val

func (cmd *GetCmd) Val() (string, int64)

Val get value.

type HSetCmd

type HSetCmd struct {
	redis.Cmder
	// contains filtered or unexported fields
}

HSetCmd HSet is result class.

func HSet

func HSet(ctx context.Context, c redis.Cmdable, key, field string, value interface{}, cas int64) *HSetCmd

HSet redis hSet function, CAS ForceSetCAS(-1) force reset, 0 means set without.

func (*HSetCmd) Err

func (cmd *HSetCmd) Err() error

Err is error message.

func (*HSetCmd) Result

func (cmd *HSetCmd) Result() (int64, error)

Result is hset result.

func (*HSetCmd) Val

func (cmd *HSetCmd) Val() int64

Val is hset value.

type MGetCmd

type MGetCmd struct {
	*redis.SliceCmd
}

MGetCmd MGet is result class.

func HMGet

func HMGet(ctx context.Context, c redis.Cmdable, key string, fields ...string) *MGetCmd

HMGet redis HMGet

func MGet

func MGet(ctx context.Context, c redis.Cmdable, keys ...string) *MGetCmd

MGet redis MGet

func (*MGetCmd) Unmarshal

func (cmd *MGetCmd) Unmarshal(i int64, message interface{}) (int64, error)

Unmarshal is type parsing for commonly used types.

type MSetCmd

type MSetCmd struct {
	*redis.Cmd
	// contains filtered or unexported fields
}

MSetCmd is mset result parser.

func HMSet

func HMSet(ctx context.Context, c redis.Cmdable, key string, values ...*S) *MSetCmd

HMSet is redis set function, cas function description: ForceSetCAS(-1) force modification, 0 means set if it does not exist, duration 0 means no expiration time.

func MSet

func MSet(ctx context.Context, c redis.Cmdable, values ...*S) *MSetCmd

MSet redis, MSet functions are implemented through pipelines, compatible with all versions of redis, it is recommended to use the cluster version. Lua script version reference MSetWithEval.

func MSetWithEval

func MSetWithEval(ctx context.Context, c redis.Cmdable, values ...*S) *MSetCmd

MSetWithEval redis MSet lua script version, strong performance, not compatible with the cluster version key across slots, etc., it is recommended to use the redis standard version. Key cross-slot can also be adjusted by adding hash tags, specifically: http://www.redis.cn/commands/cluster-keyslot.html,

func (*MSetCmd) Err

func (cmd *MSetCmd) Err() error

Err is error massage.

func (*MSetCmd) Result

func (cmd *MSetCmd) Result() ([]error, error)

Result returns results.

type S

type S struct {
	Key      string        // MSet is the key field, HMSet is the field.
	Value    interface{}   // Setting value.
	CAS      int64         // cas ForceSetCAS(-1) mandatory modification, 0 means set if it does not exist.
	Duration time.Duration // Validity period, only valid for MSetWithPipelined.
}

S is Set/HSet value structure.

type SetCmd

type SetCmd struct {
	redis.Cmder
}

SetCmd is set result parser.

func Set

func Set(ctx context.Context, c redis.Cmdable, key string, value interface{}, cas int64,
	duration time.Duration) *SetCmd

Set redis set function, cas function description: ForceSetCAS(-1) force modification, 0 means set if it does not exist, duration 0 means no expiration time. EvalSha has compatibility: when executing the SCRIPT LOAD command on a single node, it is not guaranteed to save the Lua script to other nodes, See:https://help.aliyun.com/document_detail/92942.html#section-8f7-qgv-dlv

func (*SetCmd) Err

func (cmd *SetCmd) Err() error

Err is error message.

func (*SetCmd) Result

func (cmd *SetCmd) Result() (string, error)

Result returns results.

func (*SetCmd) Val

func (cmd *SetCmd) Val() string

Val returns results.

Jump to

Keyboard shortcuts

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