-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.go
More file actions
36 lines (29 loc) · 822 Bytes
/
Copy pathstorage.go
File metadata and controls
36 lines (29 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package txndedup
import (
"context"
"time"
)
// Storage 存储接口
type Storage interface {
// 存储交易记录
Store(ctx context.Context, fingerprint string, record *TransactionRecord) error
// 获取相似交易
GetSimilar(ctx context.Context, fingerprint string, timeWindow time.Duration) ([]*TransactionRecord, error)
// 清理过期记录
Cleanup(ctx context.Context, timeWindow time.Duration) error
// 关闭存储
Close() error
}
// StorageFactory 存储工厂
type StorageFactory struct{}
// NewStorage 创建存储实例
func (sf *StorageFactory) NewStorage(config *Config) (Storage, error) {
switch config.StorageType {
case "memory":
return NewMemoryStorage(config), nil
case "redis":
return NewRedisStorage(config.RedisConfig)
default:
return nil, ErrUnsupportedStorageType
}
}