diff --git a/.gitignore b/.gitignore index 8a2ccc6..32cd7d1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ /dipper-engine /plugins/ /coverage.out -/examples/base/go.sum +go.sum diff --git a/README.MD b/README.MD index 98a3c17..5b41dc6 100644 --- a/README.MD +++ b/README.MD @@ -98,7 +98,7 @@ c.Hook(engine.AfterStart, func(dipper *core.DipperEngine, c *cli.Context) error return dipper.Add(context.Background(), &data.Session{ Data: map[string]interface{}{ - "default": map[string]interface{}{ + "default": map[string]interface{}{ "a": 10, "b": 20, "d": 5, diff --git a/core/daq/query.go b/core/daq/query.go index 3b80473..deb4825 100644 --- a/core/daq/query.go +++ b/core/daq/query.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "reflect" + "strconv" "strings" ) @@ -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() @@ -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 diff --git a/core/management.go b/core/management.go index 185faca..e2e1e90 100644 --- a/core/management.go +++ b/core/management.go @@ -80,6 +80,7 @@ func (d *DipperEngine) handlerOutput(ctx context.Context, dataOutput *data.Outpu SessionId: sessionInfo.Id, ChanId: sessionInfo.ChanId, IdNode: nextId, + MetaData: dataOutput.MetaData, BranchMain: dataOutput.BranchMain, FromEngine: node.RuleId, ToEngine: dataOutput.FromEngine, diff --git a/core/session.go b/core/session.go index 98fb258..99ff25f 100644 --- a/core/session.go +++ b/core/session.go @@ -12,16 +12,18 @@ import ( func NewSessionInfo(timeout time.Duration, session *data.Session, mapRule map[string]Rule) *data.Info { now := time.Now() var ( - id uint64 + id uint64 = session.Id err error ) - for { - id, err = util.NextID() - if err != nil { - log.Error(err) - continue + if id == 0 { + for { + id, err = util.NextID() + if err != nil { + log.Error(err) + continue + } + break } - break } endCount := 0 @@ -68,7 +70,7 @@ func (d *DipperEngine) StartSession(ctx context.Context, sessionId uint64) error Error: nil, }) if err != nil { - log.Error(err) + log.Error("Publish have error ", err) return err } } diff --git a/data/map_data.go b/data/map_data.go index 8c536b7..ee17962 100644 --- a/data/map_data.go +++ b/data/map_data.go @@ -22,6 +22,7 @@ func CreateOutput(input *InputEngine, id string) (output *OutputEngine) { output.BranchMain = input.BranchMain output.ChanId = input.ChanId output.IdNode = input.IdNode + output.MetaData = input.MetaData output.FromEngine = id output.SessionId = input.SessionId output.Time = &timeData diff --git a/data/ouput.go b/data/ouput.go index 2e99a2d..aa8c651 100644 --- a/data/ouput.go +++ b/data/ouput.go @@ -17,6 +17,7 @@ type OutputEngine struct { ChanId string `json:"chan_id"` IdNode string `json:"id_node"` FromEngine string `json:"from_engine"` + MetaData map[string]interface{} `json:"meta_data"` Data map[string]interface{} `json:"data"` BranchMain string `json:"branch_main"` Next []string `json:"next"` @@ -33,6 +34,7 @@ func (o OutputEngine) Clone() *OutputEngine { IdNode: o.IdNode, FromEngine: o.FromEngine, Data: o.Data, + MetaData: o.MetaData, BranchMain: o.BranchMain, Next: o.Next, Time: o.Time, diff --git a/data/session.go b/data/session.go index fe50d19..61cc55d 100644 --- a/data/session.go +++ b/data/session.go @@ -13,18 +13,21 @@ type NodeRule struct { } type Session struct { + Id uint64 `json:"id"` ChanId string `json:"chan_id"` MapNode map[string]*NodeRule `json:"map_node"` + MetaData map[string]interface{} `json:"meta_data"` RootNode string `json:"root_node"` Data map[string]interface{} `json:"data"` Result map[string]*OutputEngine `json:"result"` } type ResultSession struct { - Id uint64 `json:"id"` - ChanId string `json:"chan_id"` - Data map[string]interface{} `json:"data"` - Result map[string]*OutputEngine `json:"result"` + Id uint64 `json:"id"` + ChanId string `json:"chan_id"` + MetaData map[string]interface{} `json:"meta_data"` + Data map[string]interface{} `json:"data"` + Result map[string]*OutputEngine `json:"result"` } type Info struct { @@ -35,6 +38,7 @@ type Info struct { Infinite bool `json:"infinite"` MapNode map[string]*NodeRule `json:"map_node"` RootNode *NodeRule `json:"root_node"` + MetaData map[string]interface{} `json:"meta_data"` Data map[string]interface{} `json:"data"` Result map[string]*OutputEngine `json:"result"` EndCount int `json:"end_count"` diff --git a/engine/cli.go b/engine/cli.go index d7af556..ee06031 100644 --- a/engine/cli.go +++ b/engine/cli.go @@ -3,7 +3,7 @@ package engine import ( "fmt" "github.com/dipper-iot/dipper-engine/core" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" "github.com/urfave/cli/v2" "os" "os/signal" diff --git a/engine/dipper.go b/engine/dipper.go index e1a5e09..1be90c5 100644 --- a/engine/dipper.go +++ b/engine/dipper.go @@ -7,7 +7,7 @@ import ( "github.com/dipper-iot/dipper-engine/internal/util" rs "github.com/dipper-iot/dipper-engine/redis" "github.com/dipper-iot/dipper-engine/store" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "time" diff --git a/engine/run_test.go b/engine/run_test.go index 4e12d33..59bfadd 100644 --- a/engine/run_test.go +++ b/engine/run_test.go @@ -6,7 +6,7 @@ import ( "github.com/dipper-iot/dipper-engine/core" "github.com/dipper-iot/dipper-engine/data" "github.com/dipper-iot/dipper-engine/internal/debug" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "io" diff --git a/examples/base/go.mod b/examples/base/go.mod index 6a35a79..3d96c2e 100644 --- a/examples/base/go.mod +++ b/examples/base/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/dipper-iot/dipper-engine v0.0.0-20221022050351-f7e9b09096a6 - github.com/go-redis/redis/v9 v9.0.0-rc.1 + github.com/go-redis/redis/v8 v8.11.5 github.com/sirupsen/logrus v1.9.0 github.com/urfave/cli/v2 v2.11.2 ) diff --git a/examples/base/main.go b/examples/base/main.go index a60427d..1419082 100644 --- a/examples/base/main.go +++ b/examples/base/main.go @@ -7,8 +7,8 @@ import ( "github.com/dipper-iot/dipper-engine/engine" "github.com/dipper-iot/dipper-engine/internal/debug" "github.com/dipper-iot/dipper-engine/queue" + log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "log" "os" ) diff --git a/examples/redis-queue/go.mod b/examples/redis-queue/go.mod index 4e069cd..93b9b1c 100644 --- a/examples/redis-queue/go.mod +++ b/examples/redis-queue/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/dipper-iot/dipper-engine v0.0.0-20221022050351-f7e9b09096a6 - github.com/go-redis/redis/v9 v9.0.0-rc.1 + github.com/go-redis/redis/v8 v8.11.5 github.com/sirupsen/logrus v1.9.0 github.com/urfave/cli/v2 v2.11.2 ) diff --git a/examples/redis-queue/go.sum b/examples/redis-queue/go.sum deleted file mode 100644 index 37d40ac..0000000 --- a/examples/redis-queue/go.sum +++ /dev/null @@ -1,46 +0,0 @@ -github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg= -github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM= -github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/dipper-iot/dipper-engine v0.0.0-20221022050351-f7e9b09096a6 h1:9jZGJ+U7nuTpt31/N7alXPTpL7R/rBr5jSvWN55HHP8= -github.com/dipper-iot/dipper-engine v0.0.0-20221022050351-f7e9b09096a6/go.mod h1:DCBPB384HxgFQmKdNXYu5VVaufJ9yt4T5JadZPlzCqA= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= -github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs= -github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/gomega v1.21.1 h1:OB/euWYIExnPBohllTicTHmGTrMaqJ67nIu80j0/uEM= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/sony/sonyflake v1.1.0 h1:wnrEcL3aOkWmPlhScLEGAXKkLAIslnBteNUq4Bw6MM4= -github.com/sony/sonyflake v1.1.0/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/urfave/cli/v2 v2.11.2 h1:FVfNg4m3vbjbBpLYxW//WjxUoHvJ9TlppXcqY9Q9ZfA= -github.com/urfave/cli/v2 v2.11.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/redis-queue/redis.go b/examples/redis-queue/redis.go index 995a770..f7611a2 100644 --- a/examples/redis-queue/redis.go +++ b/examples/redis-queue/redis.go @@ -7,7 +7,7 @@ import ( "github.com/dipper-iot/dipper-engine/core" "github.com/dipper-iot/dipper-engine/data" "github.com/dipper-iot/dipper-engine/engine" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" "io" diff --git a/go.mod b/go.mod index d49d417..99a2203 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/Knetic/govaluate v3.0.0+incompatible github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef - github.com/go-redis/redis/v9 v9.0.0-rc.1 + github.com/go-redis/redis/v8 v8.11.5 github.com/sirupsen/logrus v1.9.0 github.com/sony/sonyflake v1.1.0 github.com/urfave/cli/v2 v2.11.2 diff --git a/go.sum b/go.sum deleted file mode 100644 index 6843a39..0000000 --- a/go.sum +++ /dev/null @@ -1,50 +0,0 @@ -github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg= -github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM= -github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII= -github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= -github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/go-redis/redis/v9 v9.0.0-beta.2 h1:ZSr84TsnQyKMAg8gnV+oawuQezeJR11/09THcWCQzr4= -github.com/go-redis/redis/v9 v9.0.0-beta.2/go.mod h1:Bldcd/M/bm9HbnNPi/LUtYBSD8ttcZYBMupwMXhdU0o= -github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs= -github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/helloyi/go-value v0.0.1 h1:uGOO/0VjmYrE77vyy2hEr/9qRLQJO0xOV92aStNseu8= -github.com/helloyi/go-value v0.0.1/go.mod h1:4wIQyO4qtMR8wndno/q6CZPwOuGPFYAbEJk1E9F/Hzc= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/sony/sonyflake v1.1.0 h1:wnrEcL3aOkWmPlhScLEGAXKkLAIslnBteNUq4Bw6MM4= -github.com/sony/sonyflake v1.1.0/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/urfave/cli/v2 v2.11.2 h1:FVfNg4m3vbjbBpLYxW//WjxUoHvJ9TlppXcqY9Q9ZfA= -github.com/urfave/cli/v2 v2.11.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/lock/redis_lock/try_lock.go b/internal/lock/redis_lock/try_lock.go index ad24be7..5f1d808 100644 --- a/internal/lock/redis_lock/try_lock.go +++ b/internal/lock/redis_lock/try_lock.go @@ -2,7 +2,7 @@ package redis_lock import ( "context" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "time" ) diff --git a/redis/bus.go b/redis/bus.go index 6c6b605..7a69f9d 100644 --- a/redis/bus.go +++ b/redis/bus.go @@ -3,7 +3,7 @@ package redis import ( "context" "github.com/dipper-iot/dipper-engine/internal/util" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "io" ) diff --git a/redis/queue.go b/redis/queue.go index 753abf1..f4a0fef 100644 --- a/redis/queue.go +++ b/redis/queue.go @@ -7,7 +7,7 @@ import ( "github.com/dipper-iot/dipper-engine/core" "github.com/dipper-iot/dipper-engine/internal/util" "github.com/dipper-iot/dipper-engine/queue" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "io" "time" diff --git a/redis/store.go b/redis/store.go index c214eb7..6326a97 100644 --- a/redis/store.go +++ b/redis/store.go @@ -8,7 +8,7 @@ import ( "github.com/dipper-iot/dipper-engine/internal/lock" "github.com/dipper-iot/dipper-engine/internal/lock/redis_lock" "github.com/dipper-iot/dipper-engine/internal/util" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "time" ) @@ -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) @@ -40,7 +44,7 @@ func (r redisStore) Add(sessionInfo *data.Info) error { return err } - return r.client.Set(context.TODO(), key, data, r.timeout).Err() + return r.client.SetNX(context.TODO(), key, data, 0).Err() } func (r redisStore) Get(sessionId uint64) *data.Info { @@ -53,9 +57,9 @@ func (r redisStore) Get(sessionId uint64) *data.Info { } var data data.Info - err = json.Unmarshal([]byte(dataStr), data) + err = json.Unmarshal([]byte(dataStr), &data) if err != nil { - log.Error(err) + log.Error("Get json.Unmarshal => ", err) return nil } @@ -71,9 +75,9 @@ func (r redisStore) Has(sessionId uint64) bool { return false } var data data.Info - err = json.Unmarshal([]byte(dataStr), data) + err = json.Unmarshal([]byte(dataStr), &data) if err != nil { - log.Error(err) + log.Error("Has json.Unmarshal => ", err) return false } diff --git a/rules/common/connect_redis.go b/rules/common/connect_redis.go index c61fcb3..5c921eb 100644 --- a/rules/common/connect_redis.go +++ b/rules/common/connect_redis.go @@ -2,7 +2,7 @@ package common import ( "context" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" ) func ConnectRedis(ctx context.Context, option *OptionRedis) (client *redis.Client, err error) { diff --git a/rules/input_redis_queue/input_redis_queue.go b/rules/input_redis_queue/input_redis_queue.go index e646ed6..ba957e4 100644 --- a/rules/input_redis_queue/input_redis_queue.go +++ b/rules/input_redis_queue/input_redis_queue.go @@ -7,7 +7,7 @@ import ( "github.com/dipper-iot/dipper-engine/errors" "github.com/dipper-iot/dipper-engine/queue" "github.com/dipper-iot/dipper-engine/rules/common" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "io" "sync" diff --git a/rules/input_redis_queue_extend/input_redis_queue.go b/rules/input_redis_queue_extend/input_redis_queue.go index 24aba9d..6172ef6 100644 --- a/rules/input_redis_queue_extend/input_redis_queue.go +++ b/rules/input_redis_queue_extend/input_redis_queue.go @@ -7,7 +7,7 @@ import ( "github.com/dipper-iot/dipper-engine/errors" "github.com/dipper-iot/dipper-engine/queue" "github.com/dipper-iot/dipper-engine/rules/common" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" "io" "sync" diff --git a/rules/input_redis_queue_extend/option.go b/rules/input_redis_queue_extend/option.go index 3b539ad..0e9095b 100644 --- a/rules/input_redis_queue_extend/option.go +++ b/rules/input_redis_queue_extend/option.go @@ -3,7 +3,7 @@ package input_redis_queue_extend import ( "context" "github.com/dipper-iot/dipper-engine/data" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" ) type OptionSession struct { diff --git a/rules/output_redis_queue/input_redis_queue.go b/rules/output_redis_queue/input_redis_queue.go index 3ea8d7c..910b586 100644 --- a/rules/output_redis_queue/input_redis_queue.go +++ b/rules/output_redis_queue/input_redis_queue.go @@ -7,7 +7,6 @@ import ( "github.com/dipper-iot/dipper-engine/errors" "github.com/dipper-iot/dipper-engine/queue" "github.com/dipper-iot/dipper-engine/rules/common" - "github.com/go-redis/redis/v9" log "github.com/sirupsen/logrus" ) diff --git a/rules/output_redis_queue_extend/input_redis_queue_extend.go b/rules/output_redis_queue_extend/input_redis_queue_extend.go index 7ffa5ce..10a3035 100644 --- a/rules/output_redis_queue_extend/input_redis_queue_extend.go +++ b/rules/output_redis_queue_extend/input_redis_queue_extend.go @@ -7,7 +7,7 @@ import ( "github.com/dipper-iot/dipper-engine/errors" "github.com/dipper-iot/dipper-engine/queue" "github.com/dipper-iot/dipper-engine/rules/common" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" log "github.com/sirupsen/logrus" ) diff --git a/server.go b/server.go index c605b49..75c3520 100644 --- a/server.go +++ b/server.go @@ -2,7 +2,7 @@ package main import ( "github.com/dipper-iot/dipper-engine/engine" - "log" + log "github.com/sirupsen/logrus" "os" ) diff --git a/server_test.go b/server_test.go index 5c5289b..57beeb7 100644 --- a/server_test.go +++ b/server_test.go @@ -15,7 +15,7 @@ import ( log2 "github.com/dipper-iot/dipper-engine/rules/log" _switch "github.com/dipper-iot/dipper-engine/rules/switch" "github.com/dipper-iot/dipper-engine/store" - "github.com/go-redis/redis/v9" + "github.com/go-redis/redis/v8" "log" "sync" "testing"