Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
8273a9137a | |
|
c9ca8e5beb |
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module git.selly.red/Selly-Modules/redisdb/v3
|
module git.selly.red/Selly-Modules/redisdb
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ func Connect(uri, password string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("⚡️[natsio]: connected to %s \n", uri)
|
fmt.Printf("⚡️[redis]: connected to %s \n", uri)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,21 +4,25 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetKeyValue ...
|
// SetKeyValue ...
|
||||||
func SetKeyValue(ctx context.Context, key string, value interface{}, options ...Options) {
|
func SetKeyValue(ctx context.Context, key string, value interface{}) {
|
||||||
b, err := json.Marshal(value)
|
b, err := json.Marshal(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("[redisdb] SetKeyValue error: %s - data: %s - %v \n", err.Error(), key, value)
|
fmt.Printf("[redisdb] SetKeyValue error: %s - data: %s - %v \n", err.Error(), key, value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
rdb.Set(ctx, key, b, 0)
|
||||||
// get options
|
}
|
||||||
opts := allOptions{}
|
|
||||||
for _, o := range options {
|
// SetTTL ...
|
||||||
o.apply(&opts)
|
func SetTTL(ctx context.Context, key string, value interface{}, d time.Duration) {
|
||||||
}
|
b, err := json.Marshal(value)
|
||||||
|
if err != nil {
|
||||||
rdb.Set(ctx, key, b, opts.ttl)
|
fmt.Printf("[redisdb] SetTTL error: %s - data: %s - %d - %v \n", err.Error(), key, d, value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rdb.Set(ctx, key, b, d)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue