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

Method Set

pkg/cache/redis.go:240–261  ·  view source on GitHub ↗

Set one value

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

Source from the content-addressed store, hash-verified

238
239// Set one value
240func (c *redisClusterCache) Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error {
241 buf, err := encoding.Marshal(c.encoding, val)
242 if err != nil {
243 return fmt.Errorf("encoding.Marshal error: %v, key=%s, val=%+v ", err, key, val)
244 }
245
246 cacheKey, err := BuildCacheKey(c.KeyPrefix, key)
247 if err != nil {
248 return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key)
249 }
250 //if expiration == 0 {
251 // expiration = DefaultExpireTime
252 //}
253 if len(buf) == 0 {
254 buf = NotFoundPlaceholderBytes
255 }
256 err = c.client.Set(ctx, cacheKey, buf, expiration).Err()
257 if err != nil {
258 return fmt.Errorf("c.client.Set error: %v, cacheKey=%s", err, cacheKey)
259 }
260 return nil
261}
262
263// Get one value
264func (c *redisClusterCache) Get(ctx context.Context, key string, val interface{}) error {

Callers

nothing calls this directly

Calls 5

MarshalFunction · 0.92
BuildCacheKeyFunction · 0.85
ErrorfMethod · 0.80
SetMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected