From 60ca8e05bb8c05d14e939d5938280349f37f2e52 Mon Sep 17 00:00:00 2001 From: wbc6080 Date: Tue, 14 May 2024 15:02:53 +0800 Subject: [PATCH] fix code in redis Signed-off-by: wbc6080 --- .../mapper/data/dbmethod/redis/client.go | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/client.go b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/client.go index 7885220a6b5..397f535af0c 100644 --- a/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/client.go +++ b/staging/src/github.com/kubeedge/mapper-framework/_template/mapper/data/dbmethod/redis/client.go @@ -69,33 +69,16 @@ func (d *DataBaseConfig) AddData(data *common.DataModel) error { // The key to construct the ordered set, here DeviceName is used as the key klog.V(1).Infof("deviceName:%s", data.DeviceName) // Check if the current ordered set exists - exists, err := RedisCli.Exists(ctx, data.DeviceName).Result() + deviceData := "TimeStamp: " + strconv.FormatInt(data.TimeStamp, 10) + " PropertyName: " + data.PropertyName + " data: " + data.Value + // Add data to ordered set. If the ordered set does not exist, it will be created. + _, err = RedisCli.ZAdd(ctx, data.DeviceName, &redis.Z{ + Score: float64(data.TimeStamp), + Member: deviceData, + }).Result() if err != nil { klog.V(4).Info("Exit AddData") return err } - deviceData := "TimeStamp: " + strconv.FormatInt(data.TimeStamp, 10) + " PropertyName: " + data.PropertyName + " data: " + data.Value - if exists == 0 { - // The ordered set does not exist, create a new ordered set and add data - _, err = RedisCli.ZAdd(ctx, data.DeviceName, &redis.Z{ - Score: float64(data.TimeStamp), - Member: deviceData, - }).Result() - if err != nil { - klog.V(4).Info("Exit AddData") - return err - } - } else { - // The ordered set already exists, add data directly - _, err = RedisCli.ZAdd(ctx, data.DeviceName, &redis.Z{ - Score: float64(data.TimeStamp), - Member: deviceData, - }).Result() - if err != nil { - klog.V(4).Info("Exit AddData") - return err - } - } return nil }