redisdb/set_key_value.go

29 lines
621 B
Go

package redisdb
import (
"context"
"encoding/json"
"fmt"
"time"
)
// SetKeyValue ...
func SetKeyValue(ctx context.Context, key string, value interface{}) {
b, err := json.Marshal(value)
if err != nil {
fmt.Printf("[redisdb] SetKeyValue error: %s - data: %s - %v \n", err.Error(), key, value)
return
}
rdb.Set(ctx, key, b, 0)
}
// SetTTL ...
func SetTTL(ctx context.Context, key string, value interface{}, d time.Duration) {
b, err := json.Marshal(value)
if err != nil {
fmt.Printf("[redisdb] SetTTL error: %s - data: %s - %d - %v \n", err.Error(), key, d, value)
return
}
rdb.Set(ctx, key, b, d)
}