You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: redisqueue/queue.go
+9-16Lines changed: 9 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
packagequeue
1
+
packageredisqueue
2
2
3
3
import (
4
4
"fmt"
@@ -8,22 +8,26 @@ import (
8
8
"github.com/garyburd/redigo/redis"
9
9
)
10
10
11
+
// Queue holds a reference to a redis connection and a queue name.
11
12
typeQueuestruct {
12
13
c redis.Conn
13
14
Namestring
14
15
}
15
16
17
+
// New defines a new Queue
16
18
funcNew(queueNamestring, c redis.Conn) *Queue {
17
19
return&Queue{
18
20
c: c,
19
21
Name: queueName,
20
22
}
21
23
}
22
24
25
+
// Push pushes a single job on to the queue. The job string can be any format, as the queue doesn't really care.
23
26
func (q*Queue) Push(jobstring) (bool, error) {
24
27
returnq.Schedule(job, time.Now())
25
28
}
26
29
30
+
// Schedule schedule a job at some point in the future, or some point in the past. Scheduling a job far in the past is the same as giving it a high priority, as jobs are popped in order of due date.
27
31
func (q*Queue) Schedule(jobstring, when time.Time) (bool, error) {
// Pending returns the count of jobs pending, including scheduled jobs that are not due yet.
35
40
func (q*Queue) Pending() (int64, error) {
36
41
returnredis.Int64(q.c.Do("ZCARD", q.Name))
37
42
}
38
43
44
+
// FlushQueue removes everything from the queue. Useful for testing.
39
45
func (q*Queue) FlushQueue() error {
40
46
_, err:=q.c.Do("DEL", q.Name)
41
47
returnerr
42
48
}
43
49
50
+
// Pop removes and returns a single job from the queue. Safe for concurrent use (multiple goroutines must use their own Queue objects and redis connections)
0 commit comments