Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BusinessConfig ¶
type BusinessConfig struct { KeyPrefix string `json:"key_prefix"` Expiration time.Duration `json:"expiration"` }
BusinessConfig 业务配置
type Config ¶
type Config struct { // 本地缓存大小(字节) LocalCacheSize int `json:"local_cache_size"` // 各业务配置 BusinessConfigs map[string]BusinessConfig `json:"business_configs"` }
Config 配置
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory 幂等性服务工厂
func NewFactory ¶
NewFactory 创建幂等性服务工厂
func (*Factory) GetService ¶
func (f *Factory) GetService(businessType string) *IdempotencyService
GetService 获取指定业务的幂等性服务
type IdempotencyService ¶
type IdempotencyService struct {
// contains filtered or unexported fields
}
IdempotencyService 提供幂等性检查服务
func NewIdempotencyService ¶
func NewIdempotencyService(redisClient redis.UniversalClient, keyPrefix string, size int, expiration time.Duration) *IdempotencyService
NewIdempotencyService 创建幂等性服务实例
func (*IdempotencyService) CheckIdempotency ¶
func (s *IdempotencyService) CheckIdempotency(ctx context.Context, requestID string, data interface{}) (bool, error)
CheckIdempotency 检查操作是否重复 requestID: 请求唯一标识符(如订单号) data: 请求数据(用于生成唯一键) 返回值: - bool: true 表示请求是新的(未重复),false 表示请求重复 - error: 操作过程中的错误
func (*IdempotencyService) DeleteIdempotencyKey ¶
func (s *IdempotencyService) DeleteIdempotencyKey(ctx context.Context, requestID string, data interface{})
DeleteIdempotencyKey 删除幂等性键 用于处理失败时清理已设置的键
func (*IdempotencyService) GetCacheStats ¶
func (s *IdempotencyService) GetCacheStats() string
GetCacheStats 获取缓存使用情况
Click to show internal directories.
Click to hide internal directories.