Documentation
¶
Index ¶
- Variables
- type Cache
- type CachedConn
- func (cc CachedConn) DelCache(keys ...string) error
- func (cc CachedConn) DelCacheCtx(ctx context.Context, keys ...string) error
- func (cc CachedConn) ExecCtx(ctx context.Context, execCtx ExecCtxFn, keys ...string) error
- func (cc CachedConn) ExecNoCache(exec ExecCtxFn) error
- func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, execCtx ExecCtxFn) (err error)
- func (cc CachedConn) GetCache(key string, v interface{}) error
- func (cc CachedConn) QueryCtx(ctx context.Context, v interface{}, key string, query QueryCtxFn) (err error)
- func (cc CachedConn) QueryNoCacheCtx(ctx context.Context, v interface{}, query QueryCtxFn) (err error)
- func (cc CachedConn) SetCache(key string, v interface{}) error
- func (cc CachedConn) Transact(fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error
- func (cc CachedConn) TransactCtx(ctx context.Context, fn func(db *gorm.DB) error, opts ...*sql.TxOptions) error
- type ExecCtxFn
- type IndexQueryCtxFn
- type Option
- type Options
- type PrimaryQueryCtxFn
- type QueryCtxFn
Constants ¶
This section is empty.
Variables ¶
var (
// ErrNotFound is the error when cache not found.
ErrNotFound = redis.Nil
)
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Del deletes cached values with keys. Del(keys ...string) error // DelCtx deletes cached values with keys. DelCtx(ctx context.Context, keys ...string) error // Get gets the cache with key and fills into v. Get(key string, val any) error // GetCtx gets the cache with key and fills into v. GetCtx(ctx context.Context, key string, val any) error // Set sets the cache with key and value. Set(key string, val any) error // SetCtx sets the cache with key and value. SetCtx(ctx context.Context, key string, val any) error // SetWithExpire sets the cache with key and v, using given expire. SetWithExpire(key string, val any, expire time.Duration) error // SetWithExpireCtx sets the cache with key and v, using given expire. SetWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error }
type CachedConn ¶
type CachedConn struct {
// contains filtered or unexported fields
}
func NewConn ¶
func NewConn(db *gorm.DB, c *redis.Client, opts ...Option) CachedConn
NewConn returns a CachedConn with a redis cluster cache.
func (CachedConn) DelCache ¶
func (cc CachedConn) DelCache(keys ...string) error
DelCache deletes cache with keys.
func (CachedConn) DelCacheCtx ¶
func (cc CachedConn) DelCacheCtx(ctx context.Context, keys ...string) error
DelCacheCtx deletes cache with keys.
func (CachedConn) ExecNoCache ¶
func (cc CachedConn) ExecNoCache(exec ExecCtxFn) error
ExecNoCache runs exec with given sql statement, without affecting cache.
func (CachedConn) ExecNoCacheCtx ¶
func (cc CachedConn) ExecNoCacheCtx(ctx context.Context, execCtx ExecCtxFn) (err error)
ExecNoCacheCtx runs exec with given sql statement, without affecting cache.
func (CachedConn) GetCache ¶
func (cc CachedConn) GetCache(key string, v interface{}) error
GetCache unmarshals cache with given key into v.
func (CachedConn) QueryCtx ¶
func (cc CachedConn) QueryCtx(ctx context.Context, v interface{}, key string, query QueryCtxFn) (err error)
func (CachedConn) QueryNoCacheCtx ¶
func (cc CachedConn) QueryNoCacheCtx(ctx context.Context, v interface{}, query QueryCtxFn) (err error)
QueryNoCacheCtx runs query with given sql statement, without affecting cache.
func (CachedConn) SetCache ¶
func (cc CachedConn) SetCache(key string, v interface{}) error
SetCache sets cache with key and v.
type IndexQueryCtxFn ¶
IndexQueryCtxFn defines the query method that based on unique indexes.
type Option ¶ added in v1.0.1
type Option func(o *Options)
Option defines the method to customize an Options.
func WithExpiry ¶ added in v1.0.1
WithExpiry returns a func to customize an Options with given expiry.
func WithNotFoundExpiry ¶ added in v1.0.1
WithNotFoundExpiry returns a func to customize an Options with given not found expiry.
type PrimaryQueryCtxFn ¶
PrimaryQueryCtxFn defines the query method that based on primary keys.
type QueryCtxFn ¶
QueryCtxFn defines the query method.