redisPool

package
v1.64.55 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

RedisPool 说明

package main

import (
	`context`
	`fmt`
	`log`

	`github.com/aid297/aid/redisPool`
	`github.com/aid297/aid/time`
)

func main() {
	redisSetting, err := redisPool.Elements.Setting.New("redis.yaml")
	if err != nil {
		panic(err)
	}
	rp := redisPool.Elements.Pool.Once(redisSetting)
	prefix, rc := rp.GetClient("default")

	res := rc.Set(context.Background(), fmt.Sprintf("%s:%s", prefix, "some-key"), "some-value", 5*time.Minute)
	if err = res.Err(); err != nil {
		panic(err)
	}

	res2 := rc.Get(context.Background(), fmt.Sprintf("%s:%s", prefix, "some-key"))
	if err = res.Err(); err != nil {
		panic(err)
	}
	fmt.Printf("some-value: %s\n", res2.String())

	if _, err = rp.Set("default", "some-key2", "some-value2", 5*time.Minute); err != nil {
		panic(err)
	}

	someValue2, err := rp.Get("default", "some-key2")
	if err != nil {
		panic(err)
	}

	log.Printf("some-value2: %v", someValue2)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Elements struct {
	Setting RedisSetting
	Pool    RedisPool
}

Functions

This section is empty.

Types

type RedisPool

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

func (*RedisPool) Clean

func (*RedisPool) Clean()

Clean 清理链接

func (*RedisPool) Close

func (my *RedisPool) Close(key string) error

Close 关闭链接

func (*RedisPool) Get

func (*RedisPool) Get(clientName, key string) (string, error)

Get 获取值

func (*RedisPool) GetClient

func (*RedisPool) GetClient(key string) (string, *rds.Client)

GetClient 获取链接和链接前缀

func (*RedisPool) Once

func (*RedisPool) Once(redisSetting *RedisSetting) *RedisPool

func (*RedisPool) Set

func (*RedisPool) Set(clientName, key string, val any, exp time.Duration) (string, error)

Set 设置值

type RedisSetting

type RedisSetting struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Password string `yaml:"password"`
	Prefix   string `yaml:"prefix"`
	Pool     []struct {
		Key    string `yaml:"key"`
		Prefix string `yaml:"prefix"`
		DbNum  int    `yaml:"dbNum"`
	}
}

func (*RedisSetting) ExampleYaml

func (*RedisSetting) ExampleYaml() string

ExampleYaml 示例配置文件

func (*RedisSetting) New

func (*RedisSetting) New(path string) (rs *RedisSetting, err error)

New 初始化:数据库配置

Jump to

Keyboard shortcuts

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