-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource.go
58 lines (47 loc) · 1.25 KB
/
resource.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
49
50
51
52
53
54
55
56
57
58
package qless
import "github.com/gomodule/redigo/redis"
type Resource interface {
Exists() bool
}
type resource struct {
c *Client
name string
}
func (r *resource) Max() (int64, error) {
return redis.Int64(r.c.Do("resource.get", timestamp(), r.name))
}
func (r *resource) SetMax(v int) error {
_, err := r.c.Do("resource.set", timestamp(), r.name, v)
return err
}
func (r *resource) Delete() error {
_, err := r.c.Do("resource.unset", timestamp(), r.name)
return err
}
func (r *resource) Exists() (bool, error) {
return Bool(r.c.Do("resource.exists", timestamp(), r.name))
}
func (r *resource) LockCount() (int64, error) {
return redis.Int64(r.c.Do("resource.lock_count", timestamp(), r.name))
}
func (r *resource) Locks() ([]string, error) {
b, err := redis.Bytes(r.c.Do("resource.locks", timestamp(), r.name))
if err != nil {
return nil, err
}
var j StringSlice
err = unmarshal(b, &j)
return j, err
}
func (r *resource) PendingCount() (int64, error) {
return redis.Int64(r.c.Do("resource.pending_count", timestamp(), r.name))
}
func (r *resource) Pending() ([]string, error) {
b, err := redis.Bytes(r.c.Do("resource.pending", timestamp(), r.name))
if err != nil {
return nil, err
}
var j StringSlice
err = unmarshal(b, &j)
return j, err
}