redis

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package redis 提供基于 Redis 的消息队列实现。 本文件内联了 basemq.BaseMQProvider 和 native.As,消除对 contrib/internal 的依赖, 使本包成为可独立引用的模块。

Package redis provides Redis-based message queue implementation. This provider supports Pub/Sub and list-based queue operations.

本包提供基于 Redis 的消息队列实现。 支持 Pub/Sub 和列表队列操作。

Package redis provides redis message queue implementation for gorp. Import this package to register the redis provider with bootstrap.

redis 消息队列 Provider,通过 init() 自动注册到 bootstrap。

Example:

import _ "github.com/ngq/gorp/contrib/messagequeue/redis"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(source any, target any) bool

As 尝试通过 reflect 将 source 转换为 target 指向的类型。 支持直接赋值、接口实现和类型转换三种路径。 当 target 为 nil、非指针、nil 指针或不可设置时返回 false。

Types

type BaseMQProvider

BaseMQProvider 消除各 MQ provider 之间的结构重复。 内联自 contrib/internal/basemq,使本包成为独立模块。

各字段含义:

  • NameStr: provider 名称标识
  • GetConfig: 从容器获取 MQ 配置的回调
  • NewQueue: 根据配置创建 MQ 实例的回调

func (*BaseMQProvider) Boot

Boot 延迟 provider 无需 boot 操作,直接返回 nil。

func (*BaseMQProvider) DependsOn

func (p *BaseMQProvider) DependsOn() []string

DependsOn 返回该 provider 依赖的契约键列表:ConfigKey。

func (*BaseMQProvider) IsDefer

func (p *BaseMQProvider) IsDefer() bool

IsDefer 返回 true,表示 provider 延迟初始化。

func (*BaseMQProvider) Name

func (p *BaseMQProvider) Name() string

Name 返回 provider 名称标识。

func (*BaseMQProvider) Provides

func (p *BaseMQProvider) Provides() []string

Provides 返回该 provider 提供的契约键列表: MessageQueueKey、MessagePublisherKey、MessageSubscriberKey。

func (*BaseMQProvider) Register

Register 将 MessageQueue、MessagePublisher、MessageSubscriber 绑定到容器。 创建 MQ 实例后会注册 closer,在容器销毁时自动关闭资源。

type Provider

type Provider struct {
	BaseMQProvider
}

Provider implements runtimecontract.ServiceProvider for Redis message queue.

func NewProvider

func NewProvider() *Provider

NewProvider creates a new Redis message queue provider.

type Queue

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

Queue implements integrationcontract.MessageQueue using Redis SDK.

func NewQueue

NewQueue creates a new Redis Queue instance.

func (*Queue) As

func (q *Queue) As(target any) bool

As attempts to cast the underlying Redis client to the target type. This is useful for type-safe access to the native client.

As 尝试将底层 Redis 客户端转换为目标类型。 用于类型安全地访问原生客户端。

func (*Queue) Close

func (q *Queue) Close() error

Close closes all Redis resources.

func (*Queue) NativeMQClient

func (q *Queue) NativeMQClient() any

NativeMQClient implements NativeMQClientProvider interface. Returns the underlying *redis.Client.

NativeMQClient 实现 NativeMQClientProvider 接口。 返回底层 *redis.Client。

func (*Queue) Publisher

Publisher returns a Redis-based MessagePublisher.

func (*Queue) Subscriber

Subscriber returns a Redis-based MessageSubscriber.

func (*Queue) Underlying

func (q *Queue) Underlying() any

Underlying returns the underlying Redis client for advanced usage. This allows users to access native Redis SDK capabilities such as pipeline, Lua scripts, streams, transactions, etc.

Underlying 返回底层 Redis 客户端供高级使用。 这允许用户访问原生 Redis SDK 能力,如 pipeline、Lua 脚本、streams、事务等。

Jump to

Keyboard shortcuts

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