jsonStr, err := client.Get( deviceIdKey ).Result()
if err == redis.Nil {
deviceIds = []string{deviceId}
fmt.Println("nil" )
} else if err != nil {
//error
r.status = -2
fmt.Println( "error ",err )
return c.JSON(http.StatusOK, r)
} else {
fmt.Println("other", jsonStr)
//c, _ := ioutil.ReadFile(jsonStr)
//dec := json.NewDecoder( bytes.NewReader(c) )
//deviceIds = []string{}
json.Unmarshal( []byte(jsonStr) , &deviceIds)
//dec.Decode(&deviceIds)
//deviceIds = append(deviceIds, deviceId)
}
fmt.Println( deviceIds )
jsonObj,err := json.Marshal(deviceIds)
err = client.Set(deviceIdKey, string( jsonObj ), 0).Err()
if err == nil {
//panic(err)
r.message = "success"
r.status = 1
}
时间: 2024-10-09 09:18:35