redis_tool

package
v0.0.0-...-0ae73c4 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNil = errors.New("go_helper redis: nil returned")

ErrNil indicates that a reply value is nil.

Functions

func Bytes

func Bytes(reply interface{}, err error) ([]byte, error)

Bytes is a helper that converts a command reply to a slice of bytes. If err is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts the reply to a slice of bytes as follows:

Reply type      Result
bulk string     reply, nil
simple string   []byte(reply), nil
nil             nil, ErrNil
other           nil, error

func String

func String(reply interface{}, err error) (string, error)

String is a helper that converts a command reply to a string. If err is not equal to nil, then String returns "", err. Otherwise String converts the reply to a string as follows:

Reply type      Result
bulk string     string(reply), nil
simple string   reply, nil
nil             "",  ErrNil
other           "",  error

Types

type Error

type Error string

Error represents an error returned in a command reply.

func (Error) Error

func (err Error) Error() string

type RedisConfig

type RedisConfig struct {
	Host     string `json:"host"`
	Password string `json:"password"`
	Port     string `json:"port"`
	NetWork  string `json:"net_work"`
	Address  string `json:"address"`
}

type RedisConn

type RedisConn struct {
	Config *RedisConfig
	// contains filtered or unexported fields
}

func (*RedisConn) Close

func (r *RedisConn) Close() error

Close connection

func (*RedisConn) Connection

func (r *RedisConn) Connection() error

connect redis

func (*RedisConn) Del

func (r *RedisConn) Del(key string) (interface{}, error)

Del key Origin command: DEL KEY_NAME

func (*RedisConn) Exists

func (r *RedisConn) Exists(key string) (interface{}, error)

Check key whether exists Origin command: EXISTS KEY_NAME

func (*RedisConn) Expire

func (r *RedisConn) Expire(key string, timeout int) (interface{}, error)

Expire Set expire time

func (*RedisConn) Get

func (r *RedisConn) Get(key string) (interface{}, error)

Get a value by a given key return an interface and an error Origin command: GET KEY_NAME

func (*RedisConn) Init

func (r *RedisConn) Init(config *RedisConfig) error

init

func (*RedisConn) LIndex

func (r *RedisConn) LIndex(key string) (interface{}, error)

LINDEX Get the element of the list header by index.

func (*RedisConn) LInsert

func (r *RedisConn) LInsert(key string, args ...interface{}) (interface{}, error)

LINSERT LInsert(key, "BEFORE", element, value) Insert value into before the element of the list.

func (*RedisConn) LLen

func (r *RedisConn) LLen(key string) (interface{}, error)

LLEN Get list length

func (*RedisConn) LPUSHX

func (r *RedisConn) LPUSHX(key string, args ...interface{}) (interface{}, error)

LPUSHX Insert one value into the the list header

func (*RedisConn) LPop

func (r *RedisConn) LPop(key string) (interface{}, error)

LPOP Move out and get the first element of the list

func (*RedisConn) LPush

func (r *RedisConn) LPush(key string, args ...interface{}) (interface{}, error)

LPUSH Insert one or more values into the list header

func (*RedisConn) LRange

func (r *RedisConn) LRange(key string, args ...interface{}) (interface{}, error)

LRANGE

LRange(key, start, end) Start or end is beginning with 0, and -1 is meaning that the end of the list.

Get the elements in the specified range of the list.

func (*RedisConn) LRem

func (r *RedisConn) LRem(key string, args ...interface{}) (interface{}, error)

LRem LRrm(key, count, value)

count > 0: Search from the beginning of the header to the end of the table, removing the equivalent of value, the number is count.

count < 0: Search from the beginning of the table to the header, remove the same element as value, the number is the absolute value of count.

count = 0: Remove all values in the table that are equal to value.

func (*RedisConn) LSet

func (r *RedisConn) LSet(key string, args ...interface{}) (interface{}, error)

LSET LSet(key, index, value) Set the value of element by index.

func (*RedisConn) RPop

func (r *RedisConn) RPop(key string) (interface{}, error)

RPop Remove the element which in the end of the list. Return the value of element which is removed. If the index is not exists, return nil.

func (*RedisConn) RPush

func (r *RedisConn) RPush(key string, args ...interface{}) (interface{}, error)

RPush RPush(key, "foo") Insert one or more values into the end of the list(far right).

func (*RedisConn) RPushx

func (r *RedisConn) RPushx(key string, args ...interface{}) (interface{}, error)

RPushx RPushx(key, "foo") Insert one value into the end of the list(far right).

func (*RedisConn) Set

func (r *RedisConn) Set(key string, args ...interface{}) (interface{}, error)

Set a value for a customize key return an interface and an error Origin command: GET KEY_NAME

func (*RedisConn) SetNX

func (r *RedisConn) SetNX(key string, args ...interface{}) (interface{}, error)

Only set a value for the given key when the key is not exists Origin command: SETNX KEY_NAME VALUE

func (*RedisConn) String

func (r *RedisConn) String(value interface{}) string

convert interface to string.

Jump to

Keyboard shortcuts

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