redis

package
v1.23.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 2 Imported by: 0

README

redis

业务通过 app-starter 使用 Redis,不要 import "github.com/redis/go-redis/v9"

初始化

builder.EnableRedis(redis.Options{
    Addr:     addr,
    Password: pwd,
})

使用

c := app.GetRedisClient()
if err := c.LPush(ctx, "queue", payload).Err(); err != nil { ... }
val, err := c.RPop(ctx, "queue").Result()
if redis.IsRedisNil(err) { ... }

redis.Client 嵌入 go-redis client,所有命令(KV、List、Pub/Sub 等)直接可用,无需逐条封装。

错误处理

路径 判断
app.GetRedisClient() 命令返回的 err redis.IsRedisNil(err)

带本地 LFU 的对象缓存见 cache/README.mdcache.IsNotFound)。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRedisNil

func IsRedisNil(err error) bool

IsRedisNil reports missing-key errors from direct Client command results (.Result() / .Err()). Use this when calling app.GetRedisClient(); do not import go-redis in business code.

Types

type Client

type Client struct {
	*goredis.Client
}

Client wraps go-redis; embeds the driver client so all commands (LPush, RPop, …) are available. Business imports github.com/lishimeng/app-starter/redis only, not go-redis.

func NewClient

func NewClient(opts Options) *Client

NewClient creates a Redis client from Options.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

type Options

type Options goredis.Options

Options mirrors go-redis client options; business uses this type only.

Jump to

Keyboard shortcuts

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