redisdb/set_key_value.go

45 lines
812 B
Go
Raw Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"encoding/json"
2022-01-27 03:10:02 +00:00
"time"
2022-10-29 02:58:04 +00:00
"git.selly.red/Selly-Modules/logger"
2021-08-09 03:36:09 +00:00
)
// SetKeyValue ...
func SetKeyValue(ctx context.Context, key string, value interface{}) {
b, err := json.Marshal(value)
if err != nil {
2022-10-29 02:58:04 +00:00
logger.Error("", logger.LogData{
Source: "redisdb.SetKeyValue",
Message: err.Error(),
Data: logger.Map{
"key": key,
"value": value,
},
})
2021-08-09 03:36:09 +00:00
return
}
rdb.Set(ctx, key, b, 0)
}
2022-01-27 03:10:02 +00:00
// SetTTL ...
func SetTTL(ctx context.Context, key string, value interface{}, d time.Duration) {
b, err := json.Marshal(value)
if err != nil {
2022-10-29 02:58:04 +00:00
logger.Error("", logger.LogData{
Source: "redisdb.SetTTL",
Message: err.Error(),
Data: logger.Map{
"key": key,
"value": value,
"duration": d,
},
})
2022-01-27 03:10:02 +00:00
return
}
rdb.Set(ctx, key, b, d)
}