Skip to content

Commit

Permalink
fix daq and redis store
Browse files Browse the repository at this point in the history
  • Loading branch information
NortonBen committed Jun 5, 2024
1 parent 9d6b974 commit dd9be79
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
42 changes: 42 additions & 0 deletions core/daq/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"reflect"
"strconv"
"strings"
)

Expand Down Expand Up @@ -211,6 +212,21 @@ func (q *Query) Number() (float64, error) {
if !ok {
return 0, fmt.Errorf("%s: %s", NotFoundPath, strings.Join(q.paths, "."))
}
switch v := n.(type) {
case string:
s, err := strconv.ParseFloat(v, 64)
return s, err
case float64:
return v, nil
case float32:
return float64(v), nil
case int64:
return float64(v), nil
case int:
return float64(v), nil
default:
}

v := reflect.ValueOf(n)
if v.CanInt() {
v2 := v.Int()
Expand Down Expand Up @@ -238,6 +254,32 @@ func (q *Query) String() (string, error) {
if q.dataString != "" {
return q.dataString, nil
}
if q.index > len(q.paths)-1 {
return "", fmt.Errorf("%s: %s", NotFoundPath, strings.Join(q.paths, "."))
}
if q.Type() == Object {
name := q.paths[q.index]
data, err := q.object()
if err != nil {
return "", err
}
n, ok := data[name]
if !ok {
return "", fmt.Errorf("%s: %s", NotFoundPath, strings.Join(q.paths, "."))
}
switch v := n.(type) {
case string:
return v, nil
case float64, float32:
return fmt.Sprintf("%f", v), nil
case int, int64:
return fmt.Sprintf("%d", v), nil
default:
}
v := reflect.ValueOf(n)
q.dataString = v.String()
return q.dataString, nil
}
v := reflect.ValueOf(q.data)
q.dataString = v.String()
return q.dataString, nil
Expand Down
4 changes: 4 additions & 0 deletions redis/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (r redisStore) getKey(sessionId uint64) string {
}

func (r redisStore) Add(sessionInfo *data.Info) error {

if r.Has(sessionInfo.Id) {
r.delete(sessionInfo.Id)
}
key := r.getKey(sessionInfo.Id)

data, err := util.ConvertToByte(sessionInfo)
Expand Down

0 comments on commit dd9be79

Please sign in to comment.