From d705825351badb80c0da8bb90c78968bcb5fdd30 Mon Sep 17 00:00:00 2001 From: Nam Huynh Date: Mon, 5 Dec 2022 15:01:07 +0700 Subject: [PATCH] redundant set function --- go.mod | 2 +- set_key_value.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 2a68b00..1de0e65 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.selly.red/Selly-Modules/redisdb +module git.selly.red/Selly-Modules/redisdb/v3 go 1.19 diff --git a/set_key_value.go b/set_key_value.go index 38320de..4251d99 100644 --- a/set_key_value.go +++ b/set_key_value.go @@ -4,25 +4,21 @@ import ( "context" "encoding/json" "fmt" - "time" ) // SetKeyValue ... -func SetKeyValue(ctx context.Context, key string, value interface{}) { +func SetKeyValue(ctx context.Context, key string, value interface{}, options ...Options) { 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 + // get options + opts := allOptions{} + for _, o := range options { + o.apply(&opts) } - rdb.Set(ctx, key, b, d) + + rdb.Set(ctx, key, b, opts.ttl) }