MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / Get

Method Get

pkg/cache/redis.go:64–87  ·  view source on GitHub ↗

Get one value

(ctx context.Context, key string, val interface{})

Source from the content-addressed store, hash-verified

62
63// Get one value
64func (c *redisCache) Get(ctx context.Context, key string, val interface{}) error {
65 cacheKey, err := BuildCacheKey(c.KeyPrefix, key)
66 if err != nil {
67 return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key)
68 }
69
70 dataBytes, err := c.client.Get(ctx, cacheKey).Bytes()
71 // NOTE: don't handle the case where redis value is nil
72 // but leave it to the upstream for processing
73 if err != nil {
74 return err
75 }
76
77 // prevent Unmarshal from reporting an error if data is empty
78 if len(dataBytes) == 0 || bytes.Equal(dataBytes, NotFoundPlaceholderBytes) {
79 return ErrPlaceholder
80 }
81 err = encoding.Unmarshal(c.encoding, dataBytes, val)
82 if err != nil {
83 return fmt.Errorf("encoding.Unmarshal error: %v, key=%s, cacheKey=%s, type=%T, json=%s ",
84 err, key, cacheKey, val, dataBytes)
85 }
86 return nil
87}
88
89// MultiSet set multiple values
90func (c *redisCache) MultiSet(ctx context.Context, valueMap map[string]interface{}, expiration time.Duration) error {

Callers

nothing calls this directly

Calls 4

UnmarshalFunction · 0.92
BuildCacheKeyFunction · 0.85
ErrorfMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected