query_set.go
1.6 KB
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
59
60
61
62
package redis
import (
"fmt"
"github.com/linmadan/egglib-go/utils/json"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
)
const (
TableQuerySetExpire = 3600 * 24
)
func KeyTableQuerySet(tableId int) string {
return fmt.Sprintf("%v:queryset:temporary:%v", constant.CACHE_PREFIX, tableId)
}
type TableQuerySetCache struct {
QuerySetId int `json:"querySetId"`
TableId int `json:"tableId"`
QueryComponents []*domain.QueryComponent `json:"queryComponents"`
}
func NewTableQuerySetCache(querySetId int, tableId int, queryComponents []*domain.QueryComponent) TableQuerySetCache {
return TableQuerySetCache{
QuerySetId: querySetId,
TableId: tableId,
QueryComponents: queryComponents,
}
}
type TableQuerySetCacheService struct {
}
func (s *TableQuerySetCacheService) SetTableQuerySetCache(key string, cache TableQuerySetCache) error {
err := ZeroCoreRedis.Setex(key, json.MarshalToString(cache), TemporaryFileExpire)
return err
}
func (s *TableQuerySetCacheService) GetTableQuerySetCache(key string) (*TableQuerySetCache, error) {
var res = &TableQuerySetCache{}
ok, err := ZeroCoreRedis.Exists(key)
if !ok {
return nil, domain.ErrorNotFound
}
if err != nil {
return nil, err
}
data, err := ZeroCoreRedis.Get(key)
if err != nil {
return nil, err
}
err = json.UnmarshalFromString(data, res)
if err != nil {
return nil, err
}
return res, nil
}
func NewTableQuerySetCacheService() *TableQuerySetCacheService {
return &TableQuerySetCacheService{}
}