redis

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrConvertKey = errors.New(MsgErrConvertKey)
View Source
var ErrConvertNewKey = errors.New(MsgErrConvertNewKey)
View Source
var ErrConvertValue = errors.New(MsgErrConvertValue)
View Source
var ErrDestIsNotPointer = errors.New(MsgErrDestIsNotPointer)
View Source
var ErrKeyNotFound = errors.New(MsgErrKeyNotFound)
View Source
var MsgErrConvertKey = "redis: error convert key to string"
View Source
var MsgErrConvertNewKey = "redis: error convert new key to string"
View Source
var MsgErrConvertValue = "redis: error convert value"
View Source
var MsgErrDestIsNotPointer = "redis: dest is not pointer"
View Source
var MsgErrKeyNotFound = "redis: key not found"

Functions

This section is empty.

Types

type MSetInput

type MSetInput struct {
	// Key can be of any type, but cannot be null, and must be compatible with conversion to string (helper.ConvertToString).
	Key any
	// Value can be of any type, but cannot be null, and must be compatible with conversion to string (helper.ConvertToString).
	Value any
	// Opt to customize the operation (not required)
	Opt *option.Set
}

type MSetOutput

type MSetOutput struct {
	Key any
	Err error
}

type ScanOutput

type ScanOutput struct {
	Cursor uint64
	Page   []string
}

type Template

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

func NewTemplate

func NewTemplate(opts option.Client) *Template

NewTemplate create a new template instance

func (*Template) Del

func (t *Template) Del(ctx context.Context, keys ...any) error

Del delete redis keys.

The keys parameter can be of any type, but cannot be empty, if an error occurs during the conversion, the error returned is ErrConvertKey.

If the return is null, the operation was performed successfully, otherwise an error occurred in the operation.

func (*Template) Disconnect

func (t *Template) Disconnect() error

Disconnect close connection to redis

func (*Template) Exists

func (t *Template) Exists(ctx context.Context, key any) (bool, error)

Exists redis values by key.

The key parameter can be of any type, but cannot be null, if an error occurs during the conversion, the error returned is ErrConvertKey.

The return if true means that the key exists, otherwise it returns false, and if an error occurs in the operation we return false with the second return parameter filled in

func (*Template) Get

func (t *Template) Get(ctx context.Context, key, dest any) error

Get redis `GET key` command.

The key parameter can be of any type, but cannot be null, in case an error occurs when converting, the error returned is ErrConvertKey. If no registered key is found, the error ErrKeyNotFound is returned.

The dest parameter must be a pointer.

If the return is null, the operation was performed successfully, otherwise an error occurred in the operation.

func (*Template) GetDel

func (t *Template) GetDel(ctx context.Context, key, dest any) error

GetDel get and delete value by key.

The key parameter can be of any type, but cannot be null, if an error occurs during the conversion, the error returned is ErrConvertKey. If no registered key is found, the error ErrKeyNotFound is returned.

The dest parameter must be a pointer.

If the return is null, the operation was performed successfully, otherwise an error occurred in the operation.

func (*Template) Keys

func (t *Template) Keys(ctx context.Context, pattern string) ([]string, error)

Keys return list of keys by pattern.

func (*Template) MSet

func (t *Template) MSet(ctx context.Context, values ...MSetInput) []MSetOutput

MSet defines N values. (Multiple Set)

Parameter values cannot be empty, and must follow the Set function documentation for each MSetInput.

The return will have a list of MSetOutput with each key and the error // that occurred, if the MSetOutput.Err field is nil, it means that the operation for that key (MSetOutput.Key) was carried out successfully, otherwise it failed .

func (*Template) Rename

func (t *Template) Rename(ctx context.Context, key, newKey any) error

Rename redis key.

The key and newKey parameters can be of any type, but cannot be null, in case an error occurs when converting the key or newKey, the error returned is ErrConvertKey or ErrConvertNewKey respectively.

If the return is null, the operation was performed successfully, otherwise an error occurred in the operation.

func (*Template) Scan

func (t *Template) Scan(ctx context.Context, cursor uint64, match string, count int64) ScanOutput

Scan return list keys pageable by match

func (*Template) Set

func (t *Template) Set(ctx context.Context, key, value any, opts ...*option.Set) error

Set supports all options that the SET command supports.

The key and value parameters can be of any type, but cannot be nil, if an error occurs when converting the key or value, the error returned is ErrConvertKey or ErrConvertValue respectively.

If the return is nil, the operation was carried out successfully, otherwise an error occurred in the operation.

To customize the operation, use the opts parameter (option.Set).

func (*Template) SetGet

func (t *Template) SetGet(ctx context.Context, key, value, dest any, opts ...*option.Set) error

SetGet supports all options that the SET command supports.

The key and value parameters can be of any type, but cannot be null, in case an error occurs when converting the key or value, the error returned is ErrConvertKey or ErrConvertValue respectively.

The dest parameter must be a pointer, not null, if we do not find a predecessor value to the set, dest will not have any modification

If the return is null, the operation was performed successfully, otherwise an error occurred in the operation.

To customize the operation, use the opts parameter (option.Set).

func (*Template) SimpleDisconnect

func (t *Template) SimpleDisconnect()

SimpleDisconnect close connection to redis without error

func (*Template) SprintKey added in v1.0.2

func (t *Template) SprintKey(vs ...any) string

SprintKey format values as prefix in string for a future redis key, ex: "test", "test2" -> "test:test2"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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