Commit da2187b2 authored by luxq's avatar luxq

update registry

parent 7e18deea
...@@ -3,6 +3,7 @@ package query ...@@ -3,6 +3,7 @@ package query
import ( import (
"github.com/odysseus/service-registry/common" "github.com/odysseus/service-registry/common"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
"sort"
) )
type WorkerInfo struct { type WorkerInfo struct {
...@@ -27,3 +28,34 @@ func getWorkerQuery(rdb *redis.Client) ServiceQuery { ...@@ -27,3 +28,34 @@ func getWorkerQuery(rdb *redis.Client) ServiceQuery {
}, },
} }
} }
func (g workerQuery) List() ([]string, error) {
all, err := getAll(g.rdb, g.service)
if err != nil {
return nil, err
}
sort.Sort(ServiceInfoList(all))
var res []string
for _, v := range all {
res = append(res, string(v.Message()))
}
return res, nil
}
func (g workerQuery) ListByPage(pageSize int, pageNum int) ([]string, int, error) {
all, err := getAll(g.rdb, g.service)
if err != nil {
return nil, 0, err
}
sort.Sort(ServiceInfoList(all))
start := pageSize * pageNum
end := start + pageSize
if len(all) < end {
end = len(all)
}
var res []string
for _, v := range all[start:end] {
res = append(res, string(v.Message()))
}
return res, len(all), nil
}
...@@ -121,7 +121,7 @@ func (s *Registry) registry(rdb *redis.Client) error { ...@@ -121,7 +121,7 @@ func (s *Registry) registry(rdb *redis.Client) error {
k := fmt.Sprintf("%s%s", common.GetServiceKeyPrefix(s.register.ServiceType()), instance) k := fmt.Sprintf("%s%s", common.GetServiceKeyPrefix(s.register.ServiceType()), instance)
err = rdb.HSet(context.Background(), k, RegistryInfo{ err = rdb.HSet(context.Background(), k, RegistryInfo{
Timestamp: time.Now().Unix(), Timestamp: time.Now().UnixMilli(),
Status: status, Status: status,
Instance: instance, Instance: instance,
Detail: string(detail), Detail: string(detail),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment