This commit is contained in:
richboo111
2024-02-06 14:42:51 +08:00
parent 0333466b01
commit 2e33b86a7b
4 changed files with 273 additions and 42 deletions

View File

@@ -12,6 +12,7 @@ type ICacher interface {
GetAs(key string, ptr interface{}) error
Keys(prefix string) ([]string, error)
GetString(key string) string
FlushDB() error
Incr(key string) error
LRange(key string) (retVal []string)

View File

@@ -1,6 +1,7 @@
package redis
import (
"encoding/json"
"fmt"
"time"
@@ -60,6 +61,18 @@ func (c *Cacher) Get(key string) interface{} {
return nil
}
func (c *Cacher) GetString(key string) string {
result, err := c.client.Get(key).Result()
if err == nil {
//return result
var retVal interface{}
if err = json.Unmarshal([]byte(result), &retVal); err == nil {
return retVal.(string)
}
}
return ""
}
func (c *Cacher) GetAs(key string, ptr interface{}) error {
result, err := c.client.Get(key).Result()
if err == nil {