redisdb/set_key_value.go

25 lines
462 B
Go
Raw 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"
2021-08-09 03:36:09 +00:00
)
// SetKeyValue ...
func (s Server) SetKeyValue(ctx context.Context, key string, value interface{}, options ...Options) {
2021-08-09 03:36:09 +00:00
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
}
2022-01-27 03:10:02 +00:00
2022-12-05 08:01:07 +00:00
// get options
opts := allOptions{}
for _, o := range options {
o.apply(&opts)
2022-01-27 03:10:02 +00:00
}
2022-12-05 08:01:07 +00:00
s.rdb.Set(ctx, key, b, opts.ttl)
2022-01-27 03:10:02 +00:00
}