fix(CurrentRecipePointer): 🐛 Fix cache recipe
Remove continue last opened version
This commit is contained in:
parent
4219c1cb43
commit
2b8745679f
16 changed files with 481 additions and 174 deletions
|
|
@ -4,6 +4,9 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/png"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
|
@ -81,7 +84,7 @@ func (r *RedisCli) GetKeyTo(source string, dest interface{}) error {
|
|||
err = json.NewDecoder(bytes.NewBufferString(saved)).Decode(dest)
|
||||
|
||||
if err != nil {
|
||||
// //fmt.Println("GET error ", err)
|
||||
fmt.Println("GET error ", err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
@ -136,6 +139,41 @@ func (r *RedisCli) SetKeyTimeout(key string, value interface{}, timeout int) err
|
|||
return err
|
||||
}
|
||||
|
||||
func (r *RedisCli) SetImageToCache(key string, value image.Image) error {
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mValue, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = r.Client.Set(context.Background(), key, mValue, time.Duration(3600)*time.Second).Err()
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *RedisCli) GetCacheImage(key string) (image.Image, error) {
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := r.Client.Get(context.Background(), key).Result()
|
||||
if err != nil {
|
||||
fmt.Println("GetCacheImage", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacheImg, err := png.Decode(bytes.NewBufferString(result))
|
||||
if err != nil {
|
||||
fmt.Println("GetCacheImage.Decode", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Println("Cache image return OK!")
|
||||
return cacheImg, nil
|
||||
|
||||
}
|
||||
|
||||
func (r *RedisCli) KeyList() ([]string, error) {
|
||||
// if cannot pass healthcheck, return err
|
||||
if err := r.HealthCheck(); err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue