redis

package
v0.0.0-...-e86600b Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 3 Imported by: 0

README

redis

1. 配置

// 添加配置
redis:
  address: localhost:6379
  password: 1234
  max-open: 10
  idle-timeout: 300     # 5分钟
  idle-conns: 5
  operation-timeout: 10 # 10秒

2. 代码

1. 读取配置
import "github.com/Baal19905/playground/pkg/redis"

// 在配置中添加redis对象
type Config struct {
    // ...
    Redis      redis.Config          `mapstructure:"redis"`
    // ...
}

// load config
2. 使用redis
import "github.com/Baal19905/playground/pkg/redis"

// 初始化指标
func (j *job) Init() {
    // ...
    j.r, err := redis.NewRedis(config)
    if err != nil {
        return ctx, err
    }
    // ...
}

// 记录指标
func (j *job) Run() {
    // ...
    j.r.Get(ctx, "key")
    // ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Address          string `mapstructure:"address"`
	Password         string `mapstructure:"password"`
	MaxOpen          int    `mapstructure:"max-open"`
	IdleConns        int    `mapstructure:"idle-conns"`
	IdleTimout       int    `mapstructure:"idle-timeout"`
	OperationTimeout int    `mapstructure:"operation-timeout"`
}

Config 配置信息

type Redis

type Redis struct {
	*redis.Client
}

func NewRedis

func NewRedis(config Config) (*Redis, error)

func (*Redis) Close

func (r *Redis) Close() error

Jump to

Keyboard shortcuts

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