-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstate_backend.go
45 lines (33 loc) · 1.04 KB
/
state_backend.go
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
37
38
39
40
41
42
43
44
45
package window
import "context"
//StateBackend ...
type StateBackend interface {
//Update 更新窗口的状态
Update(ctx context.Context, key string, event interface{}) (State, error)
//Expire 给窗口状态设置过期时间
Expire(ctx context.Context, key string, expireSeconds int64) error
//Get 获取窗口的状态
Get(ctx context.Context, key string) (State, error)
//Del 删除窗口的状态
Del(ctx context.Context, key string) error
}
//DummyStateBackend 测试用
type DummyStateBackend struct {
}
//Update ...
func (o *DummyStateBackend) Update(ctx context.Context, key string, event interface{}) (State, error) {
return &DummyState{}, nil
}
//Expire ...
func (o *DummyStateBackend) Expire(ctx context.Context, key string, expireSeconds int64) error {
return nil
}
//Get ...
func (o *DummyStateBackend) Get(ctx context.Context, key string) (State, error) {
return &DummyState{}, nil
}
//Del ...
func (o *DummyStateBackend) Del(ctx context.Context, key string) error {
return nil
}
var _ StateBackend = (*DummyStateBackend)(nil)