redisdb/set_key_value.go

29 lines
621 B
Go
Raw Permalink Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"encoding/json"
2022-12-05 07:54:51 +00:00
"fmt"
2022-01-27 03:10:02 +00:00
"time"
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-12-05 07:54:51 +00:00
fmt.Printf("[redisdb] SetKeyValue error: %s - data: %s - %v \n", err.Error(), key, 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-12-05 07:54:51 +00:00
fmt.Printf("[redisdb] SetTTL error: %s - data: %s - %d - %v \n", err.Error(), key, d, value)
2022-01-27 03:10:02 +00:00
return
}
rdb.Set(ctx, key, b, d)
}