redisdb

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceDataCachePrefix = "deviceCacheData:" // 设备数据缓存前缀

	ModeSingle   = "single"
	ModeCluster  = "cluster"
	ModeSentinel = "sentinel"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataProcessor

type DataProcessor func(data string)

DataProcessor 是一个处理新数据的函数类型

type RedisManager

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

RedisManager 管理Redis操作和连接池

func DB

func DB() *RedisManager

DB 用于全局获取RedisManager实例

func (*RedisManager) GetClient

func (r *RedisManager) GetClient() redis.UniversalClient

GetClient 获取Redis客户端

func (*RedisManager) GetData

func (r *RedisManager) GetData(ctx context.Context, key string) ([]string, error)

GetData 获取最新的数据

func (*RedisManager) GetDataByLatest

func (r *RedisManager) GetDataByLatest(ctx context.Context, key string) (string, error)

GetDataByLatest 获取最新的一条数据

func (*RedisManager) GetDataByPage

func (r *RedisManager) GetDataByPage(ctx context.Context, deviceKey string, pageNum, pageSize int, types, dateRange []string) (res []string, total, currentPage int, err error)

GetDataByPage 按分页获取数据,增加按字段内容搜索和时间区间搜索

func (*RedisManager) GetDbname

func (r *RedisManager) GetDbname() string

func (*RedisManager) InsertBatchData

func (r *RedisManager) InsertBatchData(ctx context.Context, key string, data []interface{}) error

InsertBatchData 批量插入数据到Redis

func (*RedisManager) InsertData

func (r *RedisManager) InsertData(ctx context.Context, key string, data interface{}, buffer bool) (err error)

InsertData 插入单条数据到Redis

func (*RedisManager) ListenForNewData

func (r *RedisManager) ListenForNewData(ctx context.Context, key string, processor DataProcessor, interval time.Duration)

ListenForNewData 监听指定的 Redis key,对新数据执行处理函数,interval为轮询间隔

Jump to

Keyboard shortcuts

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