Documentation
¶
Index ¶
- func BuyItemExample(goldCache, bagCache *MultiCache, uid int64, itemID int64, cost int64) error
- type BagDBStore
- func (s *BagDBStore) BatchDelete(ctx context.Context, keys []string) error
- func (s *BagDBStore) BatchInsert(ctx context.Context, entities []Entity) error
- func (s *BagDBStore) BatchUpdate(ctx context.Context, entities []Entity) error
- func (s *BagDBStore) Close() error
- func (s *BagDBStore) Delete(ctx context.Context, key string) error
- func (s *BagDBStore) Get(ctx context.Context, key string) (Entity, error)
- func (s *BagDBStore) Insert(ctx context.Context, entity Entity) error
- func (s *BagDBStore) MGet(ctx context.Context, keys []string) (map[string]Entity, error)
- func (s *BagDBStore) Update(ctx context.Context, entity Entity) error
- type BagItemEntity
- type BagService
- type BaseEntity
- type Cache
- func (c *Cache) Begin() (*Tx, error)
- func (c *Cache) Clear()
- func (c *Cache) Close() error
- func (c *Cache) Delete(key string) error
- func (c *Cache) DirtyCount() int
- func (c *Cache) Flush() error
- func (c *Cache) Get(key string) (Entity, error)
- func (c *Cache) IsDeleted(key string) bool
- func (c *Cache) IsDirty(key string) bool
- func (c *Cache) Keys() []string
- func (c *Cache) L2DirtyCount() int
- func (c *Cache) Len() int
- func (c *Cache) Load(entity Entity)
- func (c *Cache) MGet(keys []string) (map[string]Entity, error)
- func (c *Cache) Pipeline() *Pipeline
- func (c *Cache) Remove(key string)
- func (c *Cache) Set(entity Entity) error
- func (c *Cache) Stats() Stats
- type CacheBuilder
- func (b *CacheBuilder) Build() (*MultiCache, error)
- func (b *CacheBuilder) MustBuild() *MultiCache
- func (b *CacheBuilder) WithFlushInterval(d time.Duration) *CacheBuilder
- func (b *CacheBuilder) WithL1Size(size int) *CacheBuilder
- func (b *CacheBuilder) WithRedis(addr, password string, db int) *CacheBuilder
- func (b *CacheBuilder) WithRedisPrefix(prefix string) *CacheBuilder
- func (b *CacheBuilder) WithSyncInterval(d time.Duration) *CacheBuilder
- type Config
- type DBStore
- type DistTx
- type DistTxOpType
- type Entity
- type EntityWrapper
- type FlushMode
- type GenericEntity
- type GoldEntity
- type L2Store
- type MultiCache
- func MustNewSimpleCache(entityType Entity, cfg *SimpleConfig) *MultiCache
- func NewHighReliabilityCache(db *sqlx.DB, redisAddr string, entityType Entity) (*MultiCache, error)
- func NewMultiCache(dbStore DBStore, l2Store L2Store, config *MultiCacheConfig) (*MultiCache, error)
- func NewSimpleCache(entityType Entity, cfg *SimpleConfig) (*MultiCache, error)
- func NewUltraReliabilityCache(db *sqlx.DB, redisAddr string, entityType Entity) (*MultiCache, error)
- func (mc *MultiCache) Close() error
- func (mc *MultiCache) Delete(key string) error
- func (mc *MultiCache) Flush() error
- func (mc *MultiCache) FlushToL3() error
- func (mc *MultiCache) Get(key string) (Entity, error)
- func (mc *MultiCache) MGet(keys []string) (map[string]Entity, error)
- func (mc *MultiCache) Set(entity Entity) error
- func (mc *MultiCache) Stats() MultiCacheStats
- func (mc *MultiCache) SyncToL2()
- type MultiCacheConfig
- type MultiCacheStats
- type Option
- func WithBatchSize(size int) Option
- func WithCleanupInterval(d time.Duration) Option
- func WithDefaultExpiration(d time.Duration) Option
- func WithFlushInterval(d time.Duration) Option
- func WithFlushMode(mode FlushMode) Option
- func WithMaxCacheSize(size int) Option
- func WithRetryCount(count int) Option
- func WithWriteMode(mode WriteMode) Option
- func WithWriteWorkers(n int) Option
- type Order
- type OrderItem
- type Pipeline
- type RedisConfig
- type RedisStore
- func (s *RedisStore) Close() error
- func (s *RedisStore) Delete(ctx context.Context, key string) error
- func (s *RedisStore) Get(ctx context.Context, key string) (Entity, error)
- func (s *RedisStore) MDelete(ctx context.Context, keys []string) error
- func (s *RedisStore) MGet(ctx context.Context, keys []string) (map[string]Entity, error)
- func (s *RedisStore) MSet(ctx context.Context, entities []Entity) error
- func (s *RedisStore) Ping(ctx context.Context) error
- func (s *RedisStore) Publish(ctx context.Context, channel string, message string) error
- func (s *RedisStore) Set(ctx context.Context, entity Entity) error
- func (s *RedisStore) Subscribe(ctx context.Context, channels ...string) *redis.PubSub
- type SQLXStore
- func (s *SQLXStore) BatchDelete(ctx context.Context, keys []string) error
- func (s *SQLXStore) BatchInsert(ctx context.Context, entities []Entity) error
- func (s *SQLXStore) BatchUpdate(ctx context.Context, entities []Entity) error
- func (s *SQLXStore) CleanExpired(ctx context.Context, before time.Time) error
- func (s *SQLXStore) Close() error
- func (s *SQLXStore) Delete(ctx context.Context, key string) error
- func (s *SQLXStore) Get(ctx context.Context, key string) (Entity, error)
- func (s *SQLXStore) Insert(ctx context.Context, entity Entity) error
- func (s *SQLXStore) MGet(ctx context.Context, keys []string) (map[string]Entity, error)
- func (s *SQLXStore) Update(ctx context.Context, entity Entity) error
- type SQLXStoreConfig
- type ShardFunc
- type ShardedCache
- func (sc *ShardedCache) Close() error
- func (sc *ShardedCache) Delete(key string) error
- func (sc *ShardedCache) Flush() error
- func (sc *ShardedCache) Get(key string) (Entity, error)
- func (sc *ShardedCache) MGet(keys []string) (map[string]Entity, error)
- func (sc *ShardedCache) Set(entity Entity) error
- func (sc *ShardedCache) Stats() MultiCacheStats
- type SimpleConfig
- type Stats
- type Tx
- type User
- type UserService
- type WriteMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuyItemExample ¶
func BuyItemExample(goldCache, bagCache *MultiCache, uid int64, itemID int64, cost int64) error
BuyItemExample 用 DistTx 实现扣金币 + 加背包道具 goldCache 和 bagCache 是两个独立的 MultiCache
Types ¶
type BagDBStore ¶
type BagDBStore struct {
// contains filtered or unexported fields
}
func NewBagDBStore ¶
func NewBagDBStore(db *sqlx.DB) *BagDBStore
func (*BagDBStore) BatchDelete ¶
func (s *BagDBStore) BatchDelete(ctx context.Context, keys []string) error
func (*BagDBStore) BatchInsert ¶
func (s *BagDBStore) BatchInsert(ctx context.Context, entities []Entity) error
func (*BagDBStore) BatchUpdate ¶
func (s *BagDBStore) BatchUpdate(ctx context.Context, entities []Entity) error
func (*BagDBStore) Close ¶
func (s *BagDBStore) Close() error
type BagItemEntity ¶
type BagItemEntity struct {
BaseEntity
UID int64 `json:"uid" db:"uid"`
ItemID int64 `json:"item_id" db:"item_id"`
Count int64 `json:"count" db:"count"`
}
func NewBagItemEntity ¶
func NewBagItemEntity(uid, itemID, count int64) *BagItemEntity
func (*BagItemEntity) Copy ¶
func (e *BagItemEntity) Copy() Entity
func (*BagItemEntity) Marshal ¶ added in v1.0.17
func (e *BagItemEntity) Marshal() ([]byte, error)
func (*BagItemEntity) Unmarshal ¶ added in v1.0.17
func (e *BagItemEntity) Unmarshal(data []byte) error
type BagService ¶
type BagService struct {
// contains filtered or unexported fields
}
func NewBagService ¶
func NewBagService(cache *MultiCache) *BagService
func (*BagService) ChangeCount ¶
func (s *BagService) ChangeCount(uid, itemID, delta int64) error
ChangeCount 只修改单个道具,数据库仅更新一行
func (*BagService) DeleteItem ¶
func (s *BagService) DeleteItem(uid, itemID int64) error
DeleteItem 删除单个道具
func (*BagService) GetAll ¶
func (s *BagService) GetAll(uid int64, itemIDs []int64) (map[int64]*BagItemEntity, error)
GetAll 使用 MGet 批量读取整个背包 注意:实际项目中 itemIDs 可以从索引表或 Redis Set 中获取
func (*BagService) SetItem ¶
func (s *BagService) SetItem(item *BagItemEntity) error
SetItem 直接设置单个道具
type BaseEntity ¶
type BaseEntity struct {
ID string `json:"id" db:"id"`
Ver int64 `json:"ver" db:"ver"`
DelFlag bool `json:"del_flag" db:"del_flag"`
CreateTime time.Time `json:"create_time" db:"create_time"`
UpdateTime time.Time `json:"update_time" db:"update_time"`
}
BaseEntity 基础实体实现
func (*BaseEntity) IncrementVersion ¶
func (e *BaseEntity) IncrementVersion()
IncrementVersion 增加版本号
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache 带数据库持久化的缓存
func NewUserCache ¶
CacheWithUser 带有用户实体类型的缓存
func (*Cache) L2DirtyCount ¶ added in v1.0.18
L2DirtyCount 获取待同步到 L2 的条目数
func (*Cache) Load ¶ added in v1.0.15
Load 将实体加载到 L1 内存,不标记 dirty,不触发后台刷盘 适用于从 L2/L3 回填等只读场景 跳过条件:L1 中已有脏数据/删除标记,或 L1 版本号 >= 传入版本(避免旧数据覆盖新数据)
type CacheBuilder ¶
type CacheBuilder struct {
// contains filtered or unexported fields
}
CacheBuilder 缓存构建器
func NewCacheBuilder ¶
func NewCacheBuilder(db *sqlx.DB, entityType Entity) *CacheBuilder
NewCacheBuilder 创建构建器
func (*CacheBuilder) MustBuild ¶
func (b *CacheBuilder) MustBuild() *MultiCache
MustBuild 构建缓存,失败则panic
func (*CacheBuilder) WithFlushInterval ¶
func (b *CacheBuilder) WithFlushInterval(d time.Duration) *CacheBuilder
WithFlushInterval 设置刷盘间隔
func (*CacheBuilder) WithL1Size ¶
func (b *CacheBuilder) WithL1Size(size int) *CacheBuilder
WithL1Size 设置L1大小
func (*CacheBuilder) WithRedis ¶
func (b *CacheBuilder) WithRedis(addr, password string, db int) *CacheBuilder
WithRedis 设置Redis
func (*CacheBuilder) WithRedisPrefix ¶
func (b *CacheBuilder) WithRedisPrefix(prefix string) *CacheBuilder
WithRedisPrefix 设置Redis前缀
func (*CacheBuilder) WithSyncInterval ¶
func (b *CacheBuilder) WithSyncInterval(d time.Duration) *CacheBuilder
WithSyncInterval 设置同步间隔
type Config ¶
type Config struct {
// 写入模式
WriteMode WriteMode
// 刷新模式
FlushMode FlushMode
// 刷新间隔(定时刷新模式下有效)
FlushInterval time.Duration
// 批量大小,达到此数量触发写入
BatchSize int
// 最大缓存条目数
MaxCacheSize int
// 默认过期时间,0 表示永不过期
DefaultExpiration time.Duration
// 清理过期数据间隔
CleanupInterval time.Duration
// 写入失败重试次数
RetryCount int
// 重试间隔
RetryInterval time.Duration
// 并发写入协程数
WriteWorkers int
// 数据库连接池配置
DBMaxOpenConns int
DBMaxIdleConns int
DBMaxLifetime time.Duration
// 回调函数
OnFlushStart func(dirtyCount int)
OnFlushSuccess func(count int, duration time.Duration)
OnFlushError func(err error, entities []Entity)
OnCacheMiss func(key string)
OnCacheHit func(key string)
}
Config 配置
type DBStore ¶
type DBStore interface {
// Get 从数据库获取实体
Get(ctx context.Context, key string) (Entity, error)
// MGet 批量获取
MGet(ctx context.Context, keys []string) (map[string]Entity, error)
// Insert 插入新记录
Insert(ctx context.Context, entity Entity) error
// Update 更新记录
Update(ctx context.Context, entity Entity) error
// Delete 删除记录
Delete(ctx context.Context, key string) error
// BatchInsert 批量插入
BatchInsert(ctx context.Context, entities []Entity) error
// BatchUpdate 批量更新
BatchUpdate(ctx context.Context, entities []Entity) error
// BatchDelete 批量删除
BatchDelete(ctx context.Context, keys []string) error
// Close 关闭连接
Close() error
}
DBStore 数据库存储接口
type DistTx ¶
type DistTx struct {
// contains filtered or unexported fields
}
DistTx 跨 MultiCache 的分布式事务协调器 采用"预读旧值 + 顺序提交 + 失败补偿"策略
func (*DistTx) AddDelete ¶
func (dt *DistTx) AddDelete(cache *MultiCache, key string) error
AddDelete 注册 Delete 操作,同时预读旧值用于回滚
func (*DistTx) AddSet ¶
func (dt *DistTx) AddSet(cache *MultiCache, entity Entity) error
AddSet 注册 Set 操作,同时预读旧值用于回滚
func (*DistTx) CommitAndFlush ¶
CommitAndFlush 提交事务,并立即把所有涉及缓存的脏数据刷到数据库 适用于充值、交易等必须立即落盘的场景
type DistTxOpType ¶
type DistTxOpType string
DistTxOpType 操作类型
const ( DistTxSet DistTxOpType = "set" DistTxDelete DistTxOpType = "delete" )
type Entity ¶
type Entity interface {
// CacheKey 返回缓存键
CacheKey() string
// IsDeleted 是否标记删除
IsDeleted() bool
// SetDeleted 标记删除
SetDeleted(deleted bool)
// Version 获取版本号(用于乐观锁)
Version() int64
// IncrementVersion 增加版本号
IncrementVersion()
// Copy 复制实体(深拷贝)
Copy() Entity
// Marshal 将实体序列化为字节流,由用户决定具体格式(JSON、Protobuf 等)
Marshal() ([]byte, error)
// Unmarshal 从字节流反序列化到当前实体,格式需与 Marshal 保持一致
Unmarshal([]byte) error
}
Entity 实体接口,定义了缓存实体的基本契约
type EntityWrapper ¶
type EntityWrapper struct {
BaseEntity
Data interface{} `json:"data"`
}
EntityWrapper 实体包装器,用于将任意结构体转为 Entity
func NewEntityWrapper ¶
func NewEntityWrapper(key string, data interface{}) *EntityWrapper
NewEntityWrapper 创建实体包装器
func (*EntityWrapper) Marshal ¶ added in v1.0.16
func (e *EntityWrapper) Marshal() ([]byte, error)
Marshal JSON 序列化整个 wrapper
func (*EntityWrapper) Unmarshal ¶ added in v1.0.16
func (e *EntityWrapper) Unmarshal(data []byte) error
Unmarshal JSON 反序列化整个 wrapper
type GenericEntity ¶
type GenericEntity[T any] struct { BaseEntity Payload T `json:"payload"` }
GenericEntity 泛型实体
func NewGenericEntity ¶
func NewGenericEntity[T any](key string, payload T) *GenericEntity[T]
NewGenericEntity 创建泛型实体
func (*GenericEntity[T]) Marshal ¶ added in v1.0.16
func (e *GenericEntity[T]) Marshal() ([]byte, error)
Marshal JSON 序列化完整泛型实体
func (*GenericEntity[T]) Unmarshal ¶ added in v1.0.16
func (e *GenericEntity[T]) Unmarshal(data []byte) error
Unmarshal JSON 反序列化完整泛型实体
type GoldEntity ¶
type GoldEntity struct {
BaseEntity
UID int64 `json:"uid"`
Gold int64 `json:"gold"`
}
GoldEntity 金币实体(简化示例)
func NewGoldEntity ¶
func NewGoldEntity(uid, gold int64) *GoldEntity
func (*GoldEntity) Copy ¶
func (e *GoldEntity) Copy() Entity
func (*GoldEntity) Marshal ¶ added in v1.0.17
func (e *GoldEntity) Marshal() ([]byte, error)
func (*GoldEntity) Unmarshal ¶ added in v1.0.17
func (e *GoldEntity) Unmarshal(data []byte) error
type L2Store ¶ added in v1.0.15
type L2Store interface {
Get(ctx context.Context, key string) (Entity, error)
MGet(ctx context.Context, keys []string) (map[string]Entity, error)
Set(ctx context.Context, entity Entity) error
MSet(ctx context.Context, entities []Entity) error
Delete(ctx context.Context, key string) error
Ping(ctx context.Context) error
Close() error
}
L2Store L2 存储接口(内部使用,便于测试和扩展)
type MultiCache ¶
type MultiCache struct {
// contains filtered or unexported fields
}
MultiCache 多级缓存 (L1内存 -> L2Redis -> L3数据库)
func MustNewSimpleCache ¶
func MustNewSimpleCache(entityType Entity, cfg *SimpleConfig) *MultiCache
MustNewSimpleCache 创建缓存,失败则panic
func NewHighReliabilityCache ¶
NewHighReliabilityCache 创建高可靠性缓存(写L1时同步写L2 Redis)
func NewMultiCache ¶
func NewMultiCache(dbStore DBStore, l2Store L2Store, config *MultiCacheConfig) (*MultiCache, error)
NewMultiCache 创建多级缓存
func NewSimpleCache ¶
func NewSimpleCache(entityType Entity, cfg *SimpleConfig) (*MultiCache, error)
NewSimpleCache 创建简化版多级缓存
func NewUltraReliabilityCache ¶
func NewUltraReliabilityCache(db *sqlx.DB, redisAddr string, entityType Entity) (*MultiCache, error)
NewUltraReliabilityCache 创建超高可靠性缓存(写L1同步写L2,且快速刷L3)
func (*MultiCache) FlushToL3 ¶ added in v1.0.18
func (mc *MultiCache) FlushToL3() error
FlushToL3 立即将 L1 中所有脏数据刷盘到 L3,不等待后台定时器
func (*MultiCache) Get ¶
func (mc *MultiCache) Get(key string) (Entity, error)
Get 获取(L1 -> L2 -> L3)
func (*MultiCache) MGet ¶
func (mc *MultiCache) MGet(keys []string) (map[string]Entity, error)
MGet 批量获取(L1 -> L2 -> L3),汇总返回
func (*MultiCache) SyncToL2 ¶ added in v1.0.18
func (mc *MultiCache) SyncToL2()
SyncToL2 立即将 L1 中待同步的变更推送到 L2,不等待后台定时器
type MultiCacheConfig ¶
type MultiCacheConfig struct {
L1MaxSize int
L1CleanupInterval time.Duration
WriteToL2OnSet bool
SyncInterval time.Duration
FlushInterval time.Duration
WriteMode WriteMode // L1 写入模式
}
MultiCacheConfig 多级缓存配置
func DefaultMultiCacheConfig ¶
func DefaultMultiCacheConfig() *MultiCacheConfig
DefaultMultiCacheConfig 默认配置
type MultiCacheStats ¶
type MultiCacheStats struct {
// 命中计数
L1Hits int64
L2Hits int64
L3Hits int64
Misses int64
// 当前内存状态
L1Size int // L1 中当前存活的条目数(含未 flush 的脏数据)
L1DirtyCount int64 // 待 flush 到 L3 的脏条目数
L2DirtyCount int64 // 待同步到 L2 的条目数(自上次 syncToL2 以来新增的变更)
// L2 状态
L2Down bool // L2 当前是否处于降级状态
}
MultiCacheStats 统计
func (*MultiCacheStats) L1HitRate ¶ added in v1.0.18
func (s *MultiCacheStats) L1HitRate() float64
L1HitRate L1 命中率
type Option ¶
type Option func(*Config)
Option 配置选项
func WithCleanupInterval ¶
WithCleanupInterval 设置清理过期数据间隔
func WithDefaultExpiration ¶
WithDefaultExpiration 设置默认过期时间
type Order ¶
type Order struct {
BaseEntity
UserID string `json:"user_id"`
ProductID string `json:"product_id"`
Amount float64 `json:"amount"`
Status string `json:"status"`
Items []OrderItem `json:"items"`
}
Order 订单实体示例
type OrderItem ¶
type OrderItem struct {
ProductID string `json:"product_id"`
Quantity int `json:"quantity"`
Price float64 `json:"price"`
}
OrderItem 订单项
type RedisConfig ¶
type RedisConfig struct {
Addr string
Addrs []string // 集群地址列表(如 ["127.0.0.1:7000", "127.0.0.1:7001"])
Password string
DB int
KeyPrefix string
DefaultTTL time.Duration
PoolSize int
MinIdleConns int
ClusterMode bool // 显式开启集群模式
}
RedisConfig Redis配置
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore Redis存储实现(支持单机和集群模式)
func NewRedisStore ¶
func NewRedisStore(config *RedisConfig, entityType ...Entity) (*RedisStore, error)
NewRedisStore 创建Redis存储(自动识别单机/集群模式)
func (*RedisStore) Delete ¶
func (s *RedisStore) Delete(ctx context.Context, key string) error
Delete 从Redis删除
func (*RedisStore) MDelete ¶
func (s *RedisStore) MDelete(ctx context.Context, keys []string) error
MDelete 批量删除(集群模式下 go-redis 会自动按 slot 分片执行)
func (*RedisStore) MSet ¶
func (s *RedisStore) MSet(ctx context.Context, entities []Entity) error
MSet 批量设置(集群模式下 pipeline 会自动按 slot 分片到各节点执行)
func (*RedisStore) Ping ¶ added in v1.0.15
func (s *RedisStore) Ping(ctx context.Context) error
Ping 探测 Redis 是否可用
type SQLXStore ¶
type SQLXStore struct {
// contains filtered or unexported fields
}
SQLXStore SQLX存储实现
func NewSQLXStore ¶
func NewSQLXStore(dsn string, entityType Entity, configs ...*SQLXStoreConfig) (*SQLXStore, error)
NewSQLXStore 创建SQLX存储
func NewSQLXStoreFromDB ¶
NewSQLXStoreFromDB 从现有 sqlx.DB 创建存储
func (*SQLXStore) BatchDelete ¶
func (*SQLXStore) BatchInsert ¶
func (*SQLXStore) BatchUpdate ¶
func (*SQLXStore) CleanExpired ¶
CleanExpired 清理过期(软删除)数据
type SQLXStoreConfig ¶
type SQLXStoreConfig struct {
DSN string
TableName string
KeyColumn string
DataColumn string
VerColumn string
DelColumn string
TimeColumn string
MaxOpenConns int
MaxIdleConns int
MaxLifetime time.Duration
}
SQLXStoreConfig SQLX存储配置
func DefaultSQLXStoreConfig ¶
func DefaultSQLXStoreConfig() *SQLXStoreConfig
DefaultSQLXStoreConfig 默认配置
type ShardFunc ¶
ShardFunc 分片函数:根据 key 返回分片索引
func DefaultShardFunc ¶
DefaultShardFunc 默认 CRC32 取模分片
type ShardedCache ¶
type ShardedCache struct {
// contains filtered or unexported fields
}
ShardedCache 分片多级缓存(L1/L2/L3 按 shard 隔离)
func NewShardedCache ¶
func NewShardedCache(shardCount int, newShard func(idx int) (*MultiCache, error), shardFn ShardFunc) (*ShardedCache, error)
NewShardedCache 创建分片缓存池
shardCount: 分片数量(建议与 MySQL 分表数一致,如 16/32/64/128) newShard: 工厂函数,传入分片索引 idx,返回该分片对应的 *MultiCache shardFn: 可选自定义分片函数,nil 则使用 CRC32 取模
type SimpleConfig ¶
type SimpleConfig struct {
// 数据库
DB *sqlx.DB
// Redis(可选,为空则不使用L2)
RedisAddr string
RedisPass string
RedisDB int
RedisPrefix string
// 性能配置
L1Size int // L1最大条目数,默认10万
FlushInterval time.Duration // 刷盘间隔,默认1秒
SyncInterval time.Duration // L1->L2同步间隔,默认500ms
}
SimpleConfig 简化配置
type Stats ¶
type Stats struct {
// 缓存统计
CacheHits int64
CacheMisses int64
CacheSize int
DirtyCount int64
// 数据库统计
DBReads int64
DBWrites int64
DBWriteErrors int64
// 刷新统计
FlushCount int64
FlushTotalTime time.Duration
LastFlushTime time.Time
// 当前状态
IsFlushing bool
}
Stats 统计信息
type User ¶
type User struct {
BaseEntity
Username string `json:"username"`
Email string `json:"email"`
Age int `json:"age"`
Tags []string `json:"tags"`
}
User 用户实体示例
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService 用户服务示例
func (*UserService) BatchUpdateUsers ¶
func (s *UserService) BatchUpdateUsers(users []*User) error
BatchUpdateUsers 批量更新用户
func (*UserService) DeleteUser ¶
func (s *UserService) DeleteUser(userID string) error
DeleteUser 删除用户