redis

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMode int = 1

Functions

func Del

func Del(entity RedisEntity, ctx context.Context, keys ...string) error

Del delete keys

func Exists

func Exists(entity RedisEntity, ctx context.Context, keys ...string) (bool, error)

Exists check whether keys is(are) exist

func Get

func Get(entity RedisEntity, ctx context.Context, key string) (string, error)

Get get the of value of a key

func HDel

func HDel(entity RedisEntity, ctx context.Context, key string, fields ...string) error

HDel delete the field(s) in the hash

func HExists

func HExists(entity RedisEntity, ctx context.Context, key, field string) (bool, error)

HExists whether the field's name is exists in a hash

func HGet

func HGet(entity RedisEntity, ctx context.Context, key, field string) (string, error)

HGet get a field's value of the hash

func HGetAll

func HGetAll(entity RedisEntity, ctx context.Context, key string) (map[string]string, error)

HGetAll get all field name and them value in a hash

func HKeys

func HKeys(entity RedisEntity, ctx context.Context, key string) ([]string, error)

HKeys get all field's name in specified hash

func HSet

func HSet(entity RedisEntity, ctx context.Context, key string, values ...interface{}) error

HSet set a hash key and the value values's format is one of the folloing: "key1", "value1", "key2", "value2" -- pairs of key,value []string{"key1", "value1", "key2", "value2"} --- slice with pairs of key,value map[string]interface{}{"key1": "value1", "key2": "value2"} --- map

func IsValidAddrs

func IsValidAddrs(mode int, addrs string) bool

IsValidAddrs check the address of redis server(or redis sentinel server) is a valid adds this is redis server address and port,like as localhost:6379 when mode is 1(single) these are addresses and ports of redis servers like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 2(cluster) these are addresses and ports of sentinel like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 3(sentinel)

func IsValidMaster

func IsValidMaster(mode int, master string) bool

IsValidMode check whether master is a valid hostname

func IsValidMode

func IsValidMode(mode int) bool

IsValidMode check whether mode is a valid redis mode

func Keys

func Keys(entity RedisEntity, ctx context.Context, pattern string) ([]string, error)

Keys get all keys' name matched pattern

func Set

func Set(entity RedisEntity, ctx context.Context, key string, value interface{}) error

Set set the value of a key

Types

type ClientConf

type ClientConf struct {
	// connection mode 1 for single server; 2 for cluster; 3 for sentinel mode
	Mode int `form:"mode" json:"mode" yaml:"mode" xml:"mode"`

	// master server name. the value of this field is empty when mode are 1 and 2
	Master string `form:"master" json:"master" yaml:"master" xml:"master"`

	// a string join with semicolon for the addresses of server
	// this is redis server address and port,like as localhost:6379 when mode is 1
	// these are addresses and ports of redis servers like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 2
	// these are addresses and ports of sentinel like as localhost:6379;192.168.1.10:6379;x.x.x.x:6379 when mode is 3
	Addrs string `form:"addrs" json:"addrs" yaml:"addrs" xml:"addrs"`

	//redis server username
	Username string `form:"username" json:"username" yaml:"username" xml:"username"`

	// redis server password
	Password string `form:"password" json:"password" yaml:"password" xml:"password"`

	// sentinel username
	SentinelUsername string `form:"sentinelUsername" json:"sentinelUsername" yaml:"sentinelUsername" xml:"sentinelUsername"`

	// sentinel password
	SentinelPassword string `form:"sentinelPassword" json:"sentinelPassword" yaml:"sentinelPassword" xml:"sentinelPassword"`

	// db
	DB int `form:"db" json:"db" yaml:"db" xml:"db"`

	// tls parameters for agent when agent running as daemon.
	Tls config.Tls `form:"tls" json:"tls" yaml:"tls" xml:"tls"`
}

connection parameters for client.

type RedisCluster

type RedisCluster struct {
	Client     *redis.ClusterClient
	ClientConf ClientConf
}

func (RedisCluster) Close

func (r RedisCluster) Close() error

func (RedisCluster) Del

func (r RedisCluster) Del(ctx context.Context, keys ...string) *redis.IntCmd

func (RedisCluster) Exists

func (r RedisCluster) Exists(ctx context.Context, keys ...string) *redis.IntCmd

func (RedisCluster) Get

func (r RedisCluster) Get(ctx context.Context, key string) *redis.StringCmd

func (RedisCluster) HDel

func (r RedisCluster) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

func (RedisCluster) HExists

func (r RedisCluster) HExists(ctx context.Context, key, field string) *redis.BoolCmd

func (RedisCluster) HGet

func (r RedisCluster) HGet(ctx context.Context, key, field string) *redis.StringCmd

func (RedisCluster) HGetAll

func (RedisCluster) HKeys

func (RedisCluster) HSet

func (r RedisCluster) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd

func (RedisCluster) Keys

func (r RedisCluster) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd

func (RedisCluster) Set

func (r RedisCluster) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

type RedisEntity

type RedisEntity interface {
	Close() error
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	Get(ctx context.Context, key string) *redis.StringCmd
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	Exists(ctx context.Context, keys ...string) *redis.IntCmd
	HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
	HGet(ctx context.Context, key, field string) *redis.StringCmd
	HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd
	HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd
	HExists(ctx context.Context, key, field string) *redis.BoolCmd
	Keys(ctx context.Context, pattern string) *redis.StringSliceCmd
	HKeys(ctx context.Context, key string) *redis.StringSliceCmd
}

func NewClient

func NewClient(conf ClientConf, workDir string) (RedisEntity, error)

initating a entity according mode, then open a connection to redis server(s) return RedisEntity,nil if successful, otherwise return nil, error

type RedisSentinel

type RedisSentinel struct {
	Client     *redis.Client
	ClientConf ClientConf
}

func (RedisSentinel) Close

func (r RedisSentinel) Close() error

func (RedisSentinel) Del

func (r RedisSentinel) Del(ctx context.Context, keys ...string) *redis.IntCmd

func (RedisSentinel) Exists

func (r RedisSentinel) Exists(ctx context.Context, keys ...string) *redis.IntCmd

func (RedisSentinel) Get

func (RedisSentinel) HDel

func (r RedisSentinel) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

func (RedisSentinel) HExists

func (r RedisSentinel) HExists(ctx context.Context, key, field string) *redis.BoolCmd

func (RedisSentinel) HGet

func (r RedisSentinel) HGet(ctx context.Context, key, field string) *redis.StringCmd

func (RedisSentinel) HGetAll

func (RedisSentinel) HKeys

func (RedisSentinel) HSet

func (r RedisSentinel) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd

func (RedisSentinel) Keys

func (r RedisSentinel) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd

func (RedisSentinel) Set

func (r RedisSentinel) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

type RedisSingle

type RedisSingle struct {
	Client     *redis.Client
	ClientConf ClientConf
}

func (RedisSingle) Close

func (s RedisSingle) Close() error

func (RedisSingle) Del

func (r RedisSingle) Del(ctx context.Context, keys ...string) *redis.IntCmd

func (RedisSingle) Exists

func (r RedisSingle) Exists(ctx context.Context, keys ...string) *redis.IntCmd

func (RedisSingle) Get

func (r RedisSingle) Get(ctx context.Context, key string) *redis.StringCmd

func (RedisSingle) HDel

func (r RedisSingle) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd

func (RedisSingle) HExists

func (r RedisSingle) HExists(ctx context.Context, key, field string) *redis.BoolCmd

func (RedisSingle) HGet

func (r RedisSingle) HGet(ctx context.Context, key, field string) *redis.StringCmd

func (RedisSingle) HGetAll

func (RedisSingle) HKeys

func (RedisSingle) HSet

func (r RedisSingle) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd

func (RedisSingle) Keys

func (r RedisSingle) Keys(ctx context.Context, pattern string) *redis.StringSliceCmd

func (RedisSingle) Set

func (s RedisSingle) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd

Jump to

Keyboard shortcuts

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