goredis

package
v1.12.22 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 4 Imported by: 0

README

go-redis/redis

go redis

how to use

please look redis_test.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HashDefaultExpire int64 = 300 // 默认过期时间300s
View Source
var RedisClientList = map[string]*redis.Client{}

a redis client list

Functions

func GetJson added in v1.8.3

func GetJson(client *redis.Client, key string, data interface{}) error

GetJson 从redis中获取指定的key对应的val解析到data中 data必须是提前定义好的类型,且为指针类型

func GetRedisClient

func GetRedisClient(name string) (*redis.Client, error)

GetRedisClient get redis client from RedisClientList

func SetJson added in v1.8.3

func SetJson(client *redis.Client, key string, d interface{}, expire int64) error

SetJson 设置任意类型到redis中,以json格式保存

Types

type RedisClientConf

type RedisClientConf struct {
	// host:port address.
	Address string

	// Optional password. Must match the password specified in the
	// requirepass server configuration option.
	Password string

	// Database to be selected after connecting to the server.
	DB int

	// Maximum number of retries before giving up.
	// Default is to not retry failed commands.
	MaxRetries int

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration

	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
	// Default is 3 seconds.
	ReadTimeout time.Duration

	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout time.Duration

	// Maximum number of socket connections.
	// Default is 10 connections per every CPU as reported by runtime.NumCPU.
	PoolSize int

	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout time.Duration

	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int

	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes. -1 disables idle timeout check.
	IdleTimeout time.Duration

	// Connection age at which client retires (closes) the connection.
	// Default is to not close aged connections.
	MaxConnAge time.Duration
}

redis client config

func (*RedisClientConf) GetClient

func (conf *RedisClientConf) GetClient() *redis.Client

GetClient return redis client

func (*RedisClientConf) SetClientName

func (conf *RedisClientConf) SetClientName(name string)

SetClientName set a redis client to clientList

type RedisClusterConf

type RedisClusterConf struct {
	// A seed list of host:port addresses of cluster nodes.
	AddressNodes []string

	Password string

	// Maximum number of retries before giving up.
	// Default is to not retry failed commands.
	MaxRetries int

	DialTimeout  time.Duration // Default is 5 seconds.
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	// PoolSize applies per cluster node and not for the whole cluster.
	PoolSize int

	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout time.Duration

	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int

	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes. -1 disables idle timeout check.
	IdleTimeout time.Duration

	// Connection age at which client retires (closes) the connection.
	// Default is to not close aged connections.
	MaxConnAge time.Duration
}

redis cluster config

func (*RedisClusterConf) GetCluster

func (conf *RedisClusterConf) GetCluster() *redis.ClusterClient

GetCluster return redis cluster client

Jump to

Keyboard shortcuts

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