memdb

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

README

memdb

memdb 主要解决以下问题:

  • 加载 redis 配置
  • 记录 redis 执行日志
  • 上报 opentracing 追踪数据
  • 汇总 prometheus 监控指标

核心思想是用github.com/ngrok/sqlmw把现有的database/sql驱动包起来, 拦截所有数据库操作进行观察。

配置

框架默认只支持 redis。

每个数据库的配置需要指定一个名字,并添加MEMDB_DSN_前缀。

配置内容使用 url 格式,参数使用 query 字符串传递。

MEMDB_DSN_BAR = "redis://name:password@localhost:6379?DB=1"

除了 hostname 之外,其他参数均为可选。支持的配置所有 int/bool/time.Duration 类型的配置。

配置列表参考官方文档:https://pkg.go.dev/github.com/go-redis/redis#Options

使用

框架通过memdb.Get(name)函数获取缓存实例,入参是配置名(去掉前缀), 返回的是*redis.Client对象。

ctx, db := Get(ctx, "foo")
db.Set(ctx, "a", "123", 0)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, name string) (context.Context, *redis.Client)

Get 获取缓存实例

ctx, db := Get(ctx, "foo") db.Set(ctx, "a", "123", 0)

Types

type StatsCollector

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

func NewStatsCollector

func NewStatsCollector(dbName string, db *redis.Client) *StatsCollector

NewStatsCollector creates a new StatsCollector.

func (StatsCollector) Collect

func (c StatsCollector) Collect(ch chan<- prometheus.Metric)

Collect implements the prometheus.Collector interface.

func (StatsCollector) Describe

func (c StatsCollector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector interface.

Jump to

Keyboard shortcuts

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