redis

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ElementKey = micro.ElementKey("RedisComponent")

ElementKey is ElementKey for redis

Functions

func SetDefaultRedisConfig

func SetDefaultRedisConfig()

SetDefaultRedisConfig Set the default configuration information for the Redis non-relational cache database

Types

type Component

type Component struct {
	micro.EmptyComponent
	// contains filtered or unexported fields
}

Component is Component for redis

func (*Component) Init

func (c *Component) Init(server *micro.Server) error

Init the component

func (*Component) Name

func (c *Component) Name() string

Name of the component

func (*Component) PostStop

func (c *Component) PostStop(ctx context.Context) error

PostStop called after Stop()

func (*Component) PreInit

func (c *Component) PreInit(ctx context.Context) error

PreInit called before Init()

type Config

type Config struct {
	Address         string `toml:"address"`
	DB              int    `toml:"db"`
	Password        string `toml:"password"`
	MaxIdle         int    `toml:"maxIdle"`
	MaxActive       int    `toml:"maxActive"`
	IdleTimeout     int    `toml:"idleTimeout"`
	ConnTimeout     int    `toml:"connTimeout"`
	Wait            bool   `toml:"wait"`
	MaxConnLifetime int    `toml:"maxConnLifetime"`
}

Config redis configuration

func GetRedisConfig

func GetRedisConfig() *Config

GetRedisConfig Get the configuration information of the Redis non-relational cache database

type RXRedisCache

type RXRedisCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RXRedisCache implement RXCache

func InitRedisPool

func InitRedisPool(config Config) (*RXRedisCache, error)

InitRedisPool init redis connection pool

func (*RXRedisCache) DecrBy

func (rc *RXRedisCache) DecrBy(key string, num int64) (interface{}, error)

DecrBy redis key The stored value minus the specified decrement

func (*RXRedisCache) Delete

func (rc *RXRedisCache) Delete(key string) error

Delete Redis DEL Command to delete an existing key. Non-existent keys will be ignored.

func (*RXRedisCache) Get

func (rc *RXRedisCache) Get(key string) (interface{}, error)

Get Redis Get The command is used to get the value of the specified key. If the key does not exist, return nil. If the value stored in the key is not a string type, return an error.

func (*RXRedisCache) GetObject

func (rc *RXRedisCache) GetObject(key string, ref interface{}) error

GetObject redis get object

func (*RXRedisCache) GetString

func (rc *RXRedisCache) GetString(key string) (string, error)

GetString Get The command is used to get the value of the specified key and convert it to a string

func (*RXRedisCache) IncrBy

func (rc *RXRedisCache) IncrBy(key string, num int64, timeOut int) (interface{}, error)

IncrBy redis set key storage limit and timeout.

func (*RXRedisCache) IsExist

func (rc *RXRedisCache) IsExist(key string) bool

IsExist Redis EXISTS Command to check if the given key exists.

func (*RXRedisCache) Keys

func (rc *RXRedisCache) Keys(expression string) (interface{}, error)

Keys Redis Keys The command is used to find all keys that match the given pattern

func (*RXRedisCache) LOCK

func (rc *RXRedisCache) LOCK(key, requestID string, timeOut time.Duration) error

LOCK redis Lock reply. Unlock."

func (*RXRedisCache) LPop

func (rc *RXRedisCache) LPop(key string) (interface{}, error)

LPop Redis Lpop Command to remove and return the first element of the list.

func (*RXRedisCache) LPush

func (rc *RXRedisCache) LPush(key string, value interface{}) error

LPush Redis Lpush Command to insert one or more values at the beginning of the list.

func (*RXRedisCache) Put

func (rc *RXRedisCache) Put(key string, value interface{}) error

Put redis insert data

func (*RXRedisCache) PutNX

func (rc *RXRedisCache) PutNX(key string, value interface{}) (bool, error)

PutNX Redis Setnx(SET if Not exist)

func (*RXRedisCache) PutWithExpire

func (rc *RXRedisCache) PutWithExpire(key string, value interface{}, expire interface{}) error

PutWithExpire Redis Setex The command sets the value and expiration time for the specified key. If the key already exists, the SETEX command will replace the old value

func (*RXRedisCache) UNLOCK

func (rc *RXRedisCache) UNLOCK(key, requestID string, timeOut time.Duration) error

UNLOCK redis Unlock

Jump to

Keyboard shortcuts

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