-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis.helper.go
42 lines (38 loc) · 1.04 KB
/
redis.helper.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
package gojobs
import (
"context"
"fmt"
"go.dtapp.net/gorequest"
"go.dtapp.net/gotime"
"time"
)
// GetRedisKeyName 获取Redis键名
func GetRedisKeyName(taskType string) string {
return "task:run:" + taskType
}
// SetRedisKeyValue 返回设置Redis键值
func SetRedisKeyValue(ctx context.Context, taskType string) (context.Context, string, any, time.Duration) {
return ctx,
GetRedisKeyName(taskType),
fmt.Sprintf(
"%s-%s-%s-%s",
gotime.Current().SetFormat(gotime.DateTimeZhFormat),
TraceGetTraceID(ctx),
TraceGetSpanID(ctx),
gorequest.GetRequestIDContext(ctx),
),
0
}
// SetRedisKeyValueExpiration 返回设置Redis键值,有过分时间
func SetRedisKeyValueExpiration(ctx context.Context, taskType string, expiration int64) (context.Context, string, any, time.Duration) {
return ctx,
GetRedisKeyName(taskType),
fmt.Sprintf(
"%s-%s-%s-%s",
gotime.Current().SetFormat(gotime.DateTimeZhFormat),
TraceGetTraceID(ctx),
TraceGetSpanID(ctx),
gorequest.GetRequestIDContext(ctx),
),
time.Duration(expiration)
}