memdb

package
v0.0.0-...-e5591e2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 16 Imported by: 0

README

memdb

memdb 主要解决以下问题:

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

核心思想是调用AddHook添加回调,拦截所有缓存操作进行观察。

配置

框架默认只支持 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对象。

import "github.com/go-kiss/sniper/pkg/sqldb"

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	redis.UniversalClient
}

Client redis 客户端

func Get

func Get(name string) *Client

Get 获取缓存实例

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

type StatsCollector

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

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