diff --git a/pkg/nex/cachekit/adaptar.go b/pkg/nex/cachekit/adaptar.go index 2ff9a42..42c0816 100644 --- a/pkg/nex/cachekit/adaptar.go +++ b/pkg/nex/cachekit/adaptar.go @@ -4,6 +4,6 @@ import ( redis_store "github.com/eko/gocache/store/redis/v4" ) -func (c *CaConn) GoCache() *redis_store.RedisStore { +func (c *Conn) GoCache() *redis_store.RedisStore { return redis_store.NewRedis(c.Rd) } diff --git a/pkg/nex/cachekit/io.go b/pkg/nex/cachekit/io.go index a4d741a..9da7a0b 100644 --- a/pkg/nex/cachekit/io.go +++ b/pkg/nex/cachekit/io.go @@ -13,7 +13,7 @@ import ( // Provide a advanced tagging experience // At the same time, the advanced cache using client side marshaling to handle the advance data types -func Set[T any](c *CaConn, key string, value T, ttl time.Duration, tags ...string) error { +func Set[T any](c *Conn, key string, value T, ttl time.Duration, tags ...string) error { raw, err := json.Marshal(value) if err != nil { return fmt.Errorf("unable to marshal value during caching: %v", err) @@ -27,7 +27,7 @@ func Set[T any](c *CaConn, key string, value T, ttl time.Duration, tags ...strin // SetKA stands for Set Keep Alive // Don't set a TTL for the value set via this function -func SetKA[T any](c *CaConn, key string, value T, tags ...string) error { +func SetKA[T any](c *Conn, key string, value T, tags ...string) error { raw, err := json.Marshal(value) if err != nil { return fmt.Errorf("unable to marshal value during caching: %v", err) @@ -39,7 +39,7 @@ func SetKA[T any](c *CaConn, key string, value T, tags ...string) error { return cm.Set(ctx, key, string(raw), store.WithTags(tags)) } -func Get[T any](c *CaConn, key string) (T, error) { +func Get[T any](c *Conn, key string) (T, error) { var out T ctx, cancel := c.withTimeout() @@ -57,14 +57,14 @@ func Get[T any](c *CaConn, key string) (T, error) { return out, nil } -func Delete(c *CaConn, key string) error { +func Delete(c *Conn, key string) error { ctx, cancel := c.withTimeout() defer cancel() cm := cache.New[[]byte](c.GoCache()) return cm.Delete(ctx, key) } -func DeleteByTags(c *CaConn, tags ...string) error { +func DeleteByTags(c *Conn, tags ...string) error { if len(tags) == 0 { return nil } diff --git a/pkg/nex/cachekit/raw_io.go b/pkg/nex/cachekit/raw_io.go index f3b19e9..1c0971c 100644 --- a/pkg/nex/cachekit/raw_io.go +++ b/pkg/nex/cachekit/raw_io.go @@ -5,28 +5,28 @@ import "time" // The functions below are directly using the redis connection to operaete the redis // Set stores a key-value pair in Redis with an optional expiration time -func (c *CaConn) RSet(key string, value any, ttl time.Duration) error { +func (c *Conn) RSet(key string, value any, ttl time.Duration) error { ctx, cancel := c.withTimeout() defer cancel() return c.Rd.Set(ctx, key, value, ttl).Err() } // Get retrieves a value from Redis by key -func (c *CaConn) RGet(key string) (string, error) { +func (c *Conn) RGet(key string) (string, error) { ctx, cancel := c.withTimeout() defer cancel() return c.Rd.Get(ctx, key).Result() } // Delete removes a key from Redis -func (c *CaConn) RDelete(key string) error { +func (c *Conn) RDelete(key string) error { ctx, cancel := c.withTimeout() defer cancel() return c.Rd.Del(ctx, key).Err() } // Exists checks if a key exists in Redis -func (c *CaConn) RExists(key string) (bool, error) { +func (c *Conn) RExists(key string) (bool, error) { ctx, cancel := c.withTimeout() defer cancel() exists, err := c.Rd.Exists(ctx, key).Result() @@ -37,7 +37,7 @@ func (c *CaConn) RExists(key string) (bool, error) { } // ClearCacheByPrefix deletes all keys matching a given prefix -func (c *CaConn) RDeleteByPrefix(prefix string) error { +func (c *Conn) RDeleteByPrefix(prefix string) error { ctx, cancel := c.withTimeout() defer cancel() diff --git a/pkg/nex/cachekit/rdb.go b/pkg/nex/cachekit/rdb.go index d9b4074..1bac9b5 100644 --- a/pkg/nex/cachekit/rdb.go +++ b/pkg/nex/cachekit/rdb.go @@ -9,14 +9,14 @@ import ( "github.com/redis/go-redis/v9" ) -type CaConn struct { +type Conn struct { n *nex.Conn Rd *redis.Client Timeout time.Duration } -func NewCaConn(conn *nex.Conn, timeout time.Duration) (*CaConn, error) { - c := &CaConn{ +func NewCaConn(conn *nex.Conn, timeout time.Duration) (*Conn, error) { + c := &Conn{ n: conn, Timeout: timeout, } @@ -33,6 +33,6 @@ func NewCaConn(conn *nex.Conn, timeout time.Duration) (*CaConn, error) { return c, nil } -func (c *CaConn) withTimeout() (context.Context, context.CancelFunc) { +func (c *Conn) withTimeout() (context.Context, context.CancelFunc) { return context.WithTimeout(context.Background(), c.Timeout) }