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

Method Set

pkg/cache/redis.go:40–61  ·  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

38
39// Set one value
40func (c *redisCache) Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error {
41 buf, err := encoding.Marshal(c.encoding, val)
42 if err != nil {
43 return fmt.Errorf("encoding.Marshal error: %v, key=%s, val=%+v ", err, key, val)
44 }
45
46 cacheKey, err := BuildCacheKey(c.KeyPrefix, key)
47 if err != nil {
48 return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key)
49 }
50 //if expiration == 0 {
51 // expiration = DefaultExpireTime
52 //}
53 if len(buf) == 0 {
54 buf = NotFoundPlaceholderBytes
55 }
56 err = c.client.Set(ctx, cacheKey, buf, expiration).Err()
57 if err != nil {
58 return fmt.Errorf("c.client.Set error: %v, cacheKey=%s", err, cacheKey)
59 }
60 return nil
61}
62
63// Get one value
64func (c *redisCache) 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