redisdb/set_key_value.go

29 lines
545 B
Go
Raw Permalink Normal View History

2021-08-09 03:36:09 +00:00
package redisdb
import (
"context"
"encoding/json"
"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 {
fmt.Println("redisdb - SetKeyValue error", err.Error())
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 {
fmt.Println("redisdb - SetTTL error", err.Error())
return
}
rdb.Set(ctx, key, b, d)
}