commRedisService

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: GPL-3.0 Imports: 9 Imported by: 4

README

功能说明

commRedisService提供了保存在redis中的commEntity.IEntity的数据实体们的各种操作能力

Redis缓存方案

为了加快数据处理速度,Fox-Edge的数据基本上都采用了Redis作为缓存。但是同样是使用redis,有多种技术方案, 分别用来解决各种的场景问题。

  • 生产者/消费者:ProducerRedisService/ConsumerRedisService
背景:由于redis服务是独立的基础服务,应用服务对redis服务直接访问,会存在进程之间的延迟,大约是几十个毫秒左右。
如果是高频的访问缓存数据,应用服务与redis服务累加的延迟会大的无法接受,然后就有了下列技术方案。

缓冲方案:
数据同时在Local缓存和redis缓存之间各自保存一份数据,并启动一个后台线程维持Local缓存和Redis缓存的数据同步。
那么,应用服务只需要访问Local缓存中的数据即可,此时的延迟基本上忽略为0,可以支持高频的数据处理

数据结构:
缓存方案产生的Redis数据结构包括数据、敏捷数据、同步标识,三个部分
data:真正的数据部分,使用json结构进行保存
sync:时间戳标识,最近更新数据的时间
agile:敏捷数据,实际上是粒度细到每个数据对象的时间戳标识,用于判定到底是哪些数据发生了变化

  • 消费者:HashMapRedisService
背景:有了ConsumerRedisService之后,数据访问非常迅速,但是ConsumerRedisService的Local缓存的数据结构
是Map<String, BaseEntity>,这样有个问题就是方便Fox-Edge团队对Fox-Edge应用的对BaseEntity使用。
但是有个问题,就是如果是非第三方开发团队,他们并不知道BaseEntity,他们只知道Json对象和Map对象,此时为了方便
两者之间的交互,提供了Map<String, Map<String, Object>> 数据结构作为Local缓存的消费者HashMapRedisService

方案:
方案与ConsumerRedisService相同,但是Local缓存为更通用的Map<String, Map<String, Object>>

  • 直读/直写:RedisWriter/RedisReader
背景:上面三个种缓存模块虽然速度非常快,但它们是通过空间为代价来换取访问效率。
但是,有的应用它们管理的数据量非常大,Java缓存对象的内存空间效率又很低,导致整个应用占用的内存都非常巨大。
此时,继续采用缓存方案就不合时宜了,这边就提供了直读/直写 Redis的两个类。它们产生的Redis数据结构,依然跟上面的缓存
方案的数据结构一致,所以它们彼此产生的数据,是可以互相操作的。

方案:
直接访问Redis服务的数据,在Redis的数据结构依然为data/agile/sync结构。
因为数据结构一致,所以可以跟上面三种组件互通

  • 消费者:AgileMapRedisService
背景:
ProducerRedisService/ConsumerRedisService/HashMapRedisService虽然非常快,但是内存消耗很大
RedisWriter/RedisReader虽然内存消耗很小,但是无法快速感知变化Redis数据的变化
但是有些场景需要敏捷的感知数据变化,但是又不想太占用内存空间,然后有了下面这个方案

结合这两种方案,产生了第三种方案,就是只缓存敏捷数据,然后通过敏捷数据感知变化后,再去Redis服务读取具体的数据

方案:
Local缓存了Redis的agile/sync数据,并启动一个后台线程维持Local缓存和Redis缓存的数据同步
当agile/sync感知到变化的时候,业务模块再去Redis读取具体的data数据,然后通知给使用者

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RedisPrefix        string
	IRedisManager      *RedisManager
	IRedisAgileManager *RedisAgileServiceManager
)

Functions

func BindTypeNotify

func BindTypeNotify(entityType string, notify ConsumerTypeNotify)

func DeleteEntity

func DeleteEntity(entityType string, key string)

func FindEntity added in v1.0.1

func FindEntity(entityType string, finder func(entity commEntity.IEntity) bool) commEntity.IEntity

func FindEntityList

func FindEntityList(entityType string, finder func(entity commEntity.IEntity) bool) []commEntity.IEntity

func ForeachEntityList

func ForeachEntityList(entityType string, finder func(entity commEntity.IEntity) bool)

func GetChannelEntity

func GetChannelEntity(channelName string, channelType string) *edgeEntity.ChannelEntity

func GetConfigEntity

func GetConfigEntity(serviceName string, serviceType string, configName string) *edgeEntity.ConfigEntity

func GetDeviceEntity

func GetDeviceEntity(deviceName string) *edgeEntity.DeviceEntity

func GetEntityById

func GetEntityById(entityType string, id int64) commEntity.IEntity

func GetEntityByServiceKey

func GetEntityByServiceKey(entityType string, serviceKey string) (commEntity.IEntity, error)

func GetEntityByServiceKeys added in v1.0.1

func GetEntityByServiceKeys(entityType string, serviceKeys []string) (map[string]commEntity.IEntity, error)

func GetEntityCount added in v1.0.1

func GetEntityCount(entityType string, finder func(entity commEntity.IEntity) bool) (int, error)

func GetEntityList added in v1.0.1

func GetEntityList(entityType string) ([]commEntity.IEntity, error)

func GetEntityMap

func GetEntityMap(entityType string) (map[string]commEntity.IEntity, error)

func GetOperateEntity

func GetOperateEntity(manufacturer string, deviceType string, operateName string) *edgeEntity.OperateEntity

func GetUpdateTime

func GetUpdateTime(entityType string) int64

func HasEntityByServiceKey

func HasEntityByServiceKey(entityType string, serviceKey string) (bool, error)

func InsertEntity

func InsertEntity(entity commEntity.IEntity)

func ReadEntityByServiceKey

func ReadEntityByServiceKey(entityType string, serviceKey string) (commEntity.IEntity, error)

func UpdateEntity

func UpdateEntity(entity commEntity.IEntity) error

func WriteEntity

func WriteEntity(entity commEntity.IEntity) error

Types

type ConsumerEntityNotify

type ConsumerEntityNotify interface {
	// contains filtered or unexported methods
}

ConsumerEntityNotify Entity级别

type ConsumerTypeNotify

type ConsumerTypeNotify interface {
	Notify(updateTime int64, addMap map[string]commEntity.IEntity, delSet map[string]commEntity.IEntity, mdyMap map[string]commEntity.IEntity)
}

ConsumerTypeNotify Type级别

type RedisAgileService added in v1.0.1

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

func GetAgileService added in v1.0.1

func GetAgileService(entityType string) *RedisAgileService

func (*RedisAgileService) LoadAgileEntities added in v1.0.1

func (e *RedisAgileService) LoadAgileEntities()

func (*RedisAgileService) LoadAllEntities added in v1.0.1

func (e *RedisAgileService) LoadAllEntities() (map[string]commEntity.IEntity, error)

func (*RedisAgileService) LoadChangeEntities added in v1.0.1

func (e *RedisAgileService) LoadChangeEntities(addMap *map[string]commEntity.IEntity, delMap *map[string]commEntity.IEntity, mdyMap *map[string]commEntity.IEntity) error

type RedisAgileServiceManager added in v1.0.1

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

func (*RedisAgileServiceManager) GetAgileService added in v1.0.1

func (e *RedisAgileServiceManager) GetAgileService(entityType string) *RedisAgileService

type RedisManager

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

func (*RedisManager) BindTypeNotify

func (e *RedisManager) BindTypeNotify(entityType string, notify ConsumerTypeNotify)

func (*RedisManager) CopyEntityList

func (e *RedisManager) CopyEntityList(entityType string) []commEntity.IEntity

func (*RedisManager) DeleteEntity

func (e *RedisManager) DeleteEntity(entityType string, key string) error

func (*RedisManager) FindEntity

func (e *RedisManager) FindEntity(entityType string, finder func(entity commEntity.IEntity) bool) commEntity.IEntity

func (*RedisManager) FindEntityList

func (e *RedisManager) FindEntityList(entityType string, finder func(entity commEntity.IEntity) bool) []commEntity.IEntity

func (*RedisManager) ForeachEntityList

func (e *RedisManager) ForeachEntityList(entityType string, finder func(entity commEntity.IEntity) bool)

func (*RedisManager) GetConsumerService

func (e *RedisManager) GetConsumerService(entityType string) *RedisService

func (*RedisManager) GetEntityById

func (e *RedisManager) GetEntityById(entityType string, id int64) commEntity.IEntity

func (*RedisManager) GetEntityByServiceKey

func (e *RedisManager) GetEntityByServiceKey(entityType string, serviceKey string) (commEntity.IEntity, error)

func (*RedisManager) GetEntityByServiceKeys added in v1.0.1

func (e *RedisManager) GetEntityByServiceKeys(entityType string, serviceKeys []string) (map[string]commEntity.IEntity, error)

func (*RedisManager) GetEntityCount added in v1.0.1

func (e *RedisManager) GetEntityCount(entityType string, finder func(entity commEntity.IEntity) bool) (int, error)

func (*RedisManager) GetEntityMap

func (e *RedisManager) GetEntityMap(entityType string) (map[string]commEntity.IEntity, error)

GetEntityMap 复制一个全量数据的副本

func (*RedisManager) GetOperatorReader

func (e *RedisManager) GetOperatorReader(entityType string) *RedisOperator

func (*RedisManager) GetOperatorWriter

func (e *RedisManager) GetOperatorWriter(entityType string) *RedisOperator

func (*RedisManager) GetProducerService

func (e *RedisManager) GetProducerService(entityType string) *RedisService

func (*RedisManager) GetRedisConsumer

func (e *RedisManager) GetRedisConsumer() map[string]interface{}

func (*RedisManager) GetRedisProducer

func (e *RedisManager) GetRedisProducer() map[string]interface{}

func (*RedisManager) GetRedisReader

func (e *RedisManager) GetRedisReader() map[string]interface{}

func (*RedisManager) GetRedisService

func (e *RedisManager) GetRedisService(entityType string) *RedisService

func (*RedisManager) GetRedisWriter

func (e *RedisManager) GetRedisWriter() map[string]interface{}

func (*RedisManager) GetUpdateTime

func (e *RedisManager) GetUpdateTime(entityType string) int64

func (*RedisManager) InitLoadConsumerEntity

func (e *RedisManager) InitLoadConsumerEntity(entityType string) bool

func (*RedisManager) InitLoadProducerEntity

func (e *RedisManager) InitLoadProducerEntity(entityType string) bool

func (*RedisManager) InsertEntity

func (e *RedisManager) InsertEntity(entity commEntity.IEntity)

func (*RedisManager) LoadAgileEntities

func (e *RedisManager) LoadAgileEntities(entityType string) error

func (*RedisManager) LoadAllEntities

func (e *RedisManager) LoadAllEntities(entityType string) error

func (*RedisManager) ReadEntityByServiceKey

func (e *RedisManager) ReadEntityByServiceKey(entityType string, serviceKey string) (commEntity.IEntity, error)

func (*RedisManager) ReloadRedisService

func (e *RedisManager) ReloadRedisService(entityType string) bool

func (*RedisManager) SaveAgileEntities

func (e *RedisManager) SaveAgileEntities(entityType string) error

func (*RedisManager) SaveAllEntities

func (e *RedisManager) SaveAllEntities(entityType string) error

func (*RedisManager) UpdateEntity

func (e *RedisManager) UpdateEntity(entity commEntity.IEntity) error

func (*RedisManager) UpdateRedisService

func (e *RedisManager) UpdateRedisService(entityType string) bool

func (*RedisManager) WriteEntity

func (e *RedisManager) WriteEntity(entity commEntity.IEntity) error

type RedisModeManager

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

type RedisOperator

type RedisOperator struct {
	EntityType string // 实体类型
}

func (*RedisOperator) DeleteEntity

func (e *RedisOperator) DeleteEntity(key string) error

func (*RedisOperator) ReadAllDataMap added in v1.0.1

func (e *RedisOperator) ReadAllDataMap() (map[string]commEntity.IEntity, error)

func (*RedisOperator) WriteEntityMap added in v1.0.1

func (e *RedisOperator) WriteEntityMap(dataMap map[string]commEntity.IEntity) error

type RedisService

type RedisService struct {
	EntityType string // 实体类型
	// contains filtered or unexported fields
}

func (*RedisService) DeleteEntity

func (e *RedisService) DeleteEntity(key string)

func (*RedisService) Init added in v1.0.1

func (e *RedisService) Init(entityList []commEntity.IEntity)

func (*RedisService) IsInited

func (e *RedisService) IsInited() bool

func (*RedisService) PutEntity

func (e *RedisService) PutEntity(entity commEntity.IEntity)

func (*RedisService) SetInited

func (e *RedisService) SetInited()

func (*RedisService) SetTypeNotify

func (e *RedisService) SetTypeNotify(notify ConsumerTypeNotify)

func (*RedisService) UpdateEntity

func (e *RedisService) UpdateEntity(entity commEntity.IEntity) error

type RedisServiceManager

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

Jump to

Keyboard shortcuts

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