-
Notifications
You must be signed in to change notification settings - Fork 332
/
store_limiter.go
48 lines (38 loc) · 1.18 KB
/
store_limiter.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
46
47
48
package kv
import (
"context"
"go.uber.org/ratelimit"
)
type StoreLimiter struct {
Store Store
Limiter ratelimit.Limiter
}
func NewStoreLimiter(s Store, l ratelimit.Limiter) *StoreLimiter {
return &StoreLimiter{
Store: s,
Limiter: l,
}
}
func (s *StoreLimiter) Get(ctx context.Context, partitionKey, key []byte) (*ValueWithPredicate, error) {
_ = s.Limiter.Take()
return s.Store.Get(ctx, partitionKey, key)
}
func (s *StoreLimiter) Set(ctx context.Context, partitionKey, key, value []byte) error {
_ = s.Limiter.Take()
return s.Store.Set(ctx, partitionKey, key, value)
}
func (s *StoreLimiter) SetIf(ctx context.Context, partitionKey, key, value []byte, valuePredicate Predicate) error {
_ = s.Limiter.Take()
return s.Store.SetIf(ctx, partitionKey, key, value, valuePredicate)
}
func (s *StoreLimiter) Delete(ctx context.Context, partitionKey, key []byte) error {
_ = s.Limiter.Take()
return s.Store.Delete(ctx, partitionKey, key)
}
func (s *StoreLimiter) Scan(ctx context.Context, partitionKey []byte, options ScanOptions) (EntriesIterator, error) {
_ = s.Limiter.Take()
return s.Store.Scan(ctx, partitionKey, options)
}
func (s *StoreLimiter) Close() {
s.Store.Close()
}