mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +08:00
Add Hash method to Payload
This commit is contained in:
parent
14ac5f6674
commit
324a785233
1
asynq.go
1
asynq.go
@ -6,7 +6,6 @@ import "github.com/go-redis/redis/v7"
|
|||||||
TODOs:
|
TODOs:
|
||||||
- [P0] asynqmon kill <taskID>, asynqmon killall <qname>
|
- [P0] asynqmon kill <taskID>, asynqmon killall <qname>
|
||||||
- [P0] Pagination for `asynqmon ls` command
|
- [P0] Pagination for `asynqmon ls` command
|
||||||
- [P0] Better Payload API - Assigning int or any number type to Payload will be converted to float64 in handler
|
|
||||||
- [P0] Show elapsed time for InProgress tasks (asynqmon ls inprogress)
|
- [P0] Show elapsed time for InProgress tasks (asynqmon ls inprogress)
|
||||||
- [P0] Redis Memory Usage, Connection info in stats
|
- [P0] Redis Memory Usage, Connection info in stats
|
||||||
- [P0] Processed, Failed count for today
|
- [P0] Processed, Failed count for today
|
||||||
|
@ -19,6 +19,12 @@ func (e *errKeyNotFound) Error() string {
|
|||||||
return fmt.Sprintf("key %q does not exist", e.key)
|
return fmt.Sprintf("key %q does not exist", e.key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Has reports whether key exists.
|
||||||
|
func (p Payload) Has(key string) bool {
|
||||||
|
_, ok := p[key]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// GetString returns a string value if a string type is associated with
|
// GetString returns a string value if a string type is associated with
|
||||||
// the key, otherwise reports an error.
|
// the key, otherwise reports an error.
|
||||||
func (p Payload) GetString(key string) (string, error) {
|
func (p Payload) GetString(key string) (string, error) {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPayload(t *testing.T) {
|
func TestPayloadGet(t *testing.T) {
|
||||||
names := []string{"luke", "anakin", "ray"}
|
names := []string{"luke", "anakin", "ray"}
|
||||||
primes := []int{2, 3, 5, 7, 11, 13, 17}
|
primes := []int{2, 3, 5, 7, 11, 13, 17}
|
||||||
user := map[string]interface{}{"name": "Ken", "score": 3.14}
|
user := map[string]interface{}{"name": "Ken", "score": 3.14}
|
||||||
@ -125,7 +125,7 @@ func TestPayload(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPayloadWithMarshaling(t *testing.T) {
|
func TestPayloadGetWithMarshaling(t *testing.T) {
|
||||||
names := []string{"luke", "anakin", "ray"}
|
names := []string{"luke", "anakin", "ray"}
|
||||||
primes := []int{2, 3, 5, 7, 11, 13, 17}
|
primes := []int{2, 3, 5, 7, 11, 13, 17}
|
||||||
user := map[string]interface{}{"name": "Ken", "score": 3.14}
|
user := map[string]interface{}{"name": "Ken", "score": 3.14}
|
||||||
@ -252,3 +252,16 @@ func TestPayloadWithMarshaling(t *testing.T) {
|
|||||||
"duration", gotDuration, err, duration)
|
"duration", gotDuration, err, duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPayloadHas(t *testing.T) {
|
||||||
|
payload := Payload{
|
||||||
|
"user_id": 123,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !payload.Has("user_id") {
|
||||||
|
t.Errorf("Payload.Has(%q) = false, want true", "user_id")
|
||||||
|
}
|
||||||
|
if payload.Has("name") {
|
||||||
|
t.Errorf("Payload.Has(%q) = true, want false", "name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user