Documentation
¶
Overview ¶
Package sabi_redis is a library that provides data access for Redis within the sabi framework.
This library allows for a streamlined and consistent way to access various Redis configurations while adhering to the architectural patterns of the sabi framework.
Key Features ¶
- Multi-Configuration Support: Provides specialized implementations for Standalone Redis servers, Redis Sentinel for high availability, and Redis Cluster for horizontal scaling.
- Consistency Management: Since Redis lacks native rollbacks, this library provides mechanisms to manage data integrity during failures:
- Pre-commit: Logic executed before the main commit phase.
- Post-commit: Logic executed after a successful commit.
- Force-back: A mechanism to register "revert" logic that executes if a transaction fails.
Integration with the sabi framework ¶
This library integrates with sabi by implementing its core data access abstractions:
- DataSrc & DataConn: It provides RedisDataSrc (and variants like RedisSentinelDataSrc and RedisClusterDataSrc) to handle connection pooling and configuration, and RedisDataConn (and its variants) to provide the actual connection to business logic.
- Registration & Setup: Data sources are registered using the framework's "Uses" function and initialized during the setup phase.
- Transaction Management: Redis operations are typically performed within a sabi transaction (Dab.Txn).
- Error Handling: It utilizes the framework's transaction lifecycle to trigger "ForceBack" operations, allowing developers to attempt to undo Redis changes if a transaction fails.
Index ¶
- type RedisClusterDataConn
- func (dc *RedisClusterDataConn) AddForceBack(fn func(*redis.ClusterClient) errs.Err)
- func (dc *RedisClusterDataConn) AddPostCommit(fn func(*redis.ClusterClient) errs.Err)
- func (dc *RedisClusterDataConn) AddPreCommit(fn func(*redis.ClusterClient) errs.Err)
- func (dc *RedisClusterDataConn) Close()
- func (dc *RedisClusterDataConn) Commit(ag *sabi.AsyncGroup) errs.Err
- func (dc *RedisClusterDataConn) ForceBack(ag *sabi.AsyncGroup)
- func (dc *RedisClusterDataConn) GetConnection() *redis.ClusterClient
- func (dc *RedisClusterDataConn) PostCommit(ag *sabi.AsyncGroup)
- func (dc *RedisClusterDataConn) PreCommit(ag *sabi.AsyncGroup) errs.Err
- func (dc *RedisClusterDataConn) Rollback(ag *sabi.AsyncGroup)
- func (dc *RedisClusterDataConn) ShouldForceBack() bool
- type RedisClusterDataSrc
- type RedisClusterDataSrcAlreadySetup
- type RedisClusterDataSrcFailToPing
- type RedisClusterDataSrcNotSetupYet
- type RedisDataConn
- func (dc *RedisDataConn) AddForceBack(fn func(*redis.Conn) errs.Err)
- func (dc *RedisDataConn) AddPostCommit(fn func(*redis.Conn) errs.Err)
- func (dc *RedisDataConn) AddPreCommit(fn func(*redis.Conn) errs.Err)
- func (dc *RedisDataConn) Close()
- func (dc *RedisDataConn) Commit(ag *sabi.AsyncGroup) errs.Err
- func (dc *RedisDataConn) ForceBack(ag *sabi.AsyncGroup)
- func (dc *RedisDataConn) GetConnection() *redis.Conn
- func (dc *RedisDataConn) PostCommit(ag *sabi.AsyncGroup)
- func (dc *RedisDataConn) PreCommit(ag *sabi.AsyncGroup) errs.Err
- func (dc *RedisDataConn) Rollback(ag *sabi.AsyncGroup)
- func (dc *RedisDataConn) ShouldForceBack() bool
- type RedisDataSrc
- type RedisDataSrcAlreadySetup
- type RedisDataSrcFailToPing
- type RedisDataSrcNotSetupYet
- type RedisSentinelDataConn
- func (dc *RedisSentinelDataConn) AddForceBack(fn func(*redis.Conn) errs.Err)
- func (dc *RedisSentinelDataConn) AddPostCommit(fn func(*redis.Conn) errs.Err)
- func (dc *RedisSentinelDataConn) AddPreCommit(fn func(*redis.Conn) errs.Err)
- func (dc *RedisSentinelDataConn) Close()
- func (dc *RedisSentinelDataConn) Commit(ag *sabi.AsyncGroup) errs.Err
- func (dc *RedisSentinelDataConn) ForceBack(ag *sabi.AsyncGroup)
- func (dc *RedisSentinelDataConn) GetConnection() *redis.Conn
- func (dc *RedisSentinelDataConn) PostCommit(ag *sabi.AsyncGroup)
- func (dc *RedisSentinelDataConn) PreCommit(ag *sabi.AsyncGroup) errs.Err
- func (dc *RedisSentinelDataConn) Rollback(ag *sabi.AsyncGroup)
- func (dc *RedisSentinelDataConn) ShouldForceBack() bool
- type RedisSentinelDataSrc
- type RedisSentinelDataSrcAlreadySetup
- type RedisSentinelDataSrcFailToPing
- type RedisSentinelDataSrcNotSetupYet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RedisClusterDataConn ¶
type RedisClusterDataConn struct {
// contains filtered or unexported fields
}
RedisClusterDataConn is a data connection for Redis Cluster.
func (*RedisClusterDataConn) AddForceBack ¶
func (dc *RedisClusterDataConn) AddForceBack(fn func(*redis.ClusterClient) errs.Err)
AddForceBack adds a function to be executed on force back.
func (*RedisClusterDataConn) AddPostCommit ¶
func (dc *RedisClusterDataConn) AddPostCommit(fn func(*redis.ClusterClient) errs.Err)
AddPostCommit adds a function to be executed after commit.
func (*RedisClusterDataConn) AddPreCommit ¶
func (dc *RedisClusterDataConn) AddPreCommit(fn func(*redis.ClusterClient) errs.Err)
AddPreCommit adds a function to be executed before commit.
func (*RedisClusterDataConn) Close ¶
func (dc *RedisClusterDataConn) Close()
Close does nothing for this data connection.
func (*RedisClusterDataConn) Commit ¶
func (dc *RedisClusterDataConn) Commit(ag *sabi.AsyncGroup) errs.Err
Commit does nothing for this data connection.
func (*RedisClusterDataConn) ForceBack ¶
func (dc *RedisClusterDataConn) ForceBack(ag *sabi.AsyncGroup)
ForceBack executes force-back functions in reverse order.
func (*RedisClusterDataConn) GetConnection ¶
func (dc *RedisClusterDataConn) GetConnection() *redis.ClusterClient
GetConnection returns the underlying redis cluster client.
func (*RedisClusterDataConn) PostCommit ¶
func (dc *RedisClusterDataConn) PostCommit(ag *sabi.AsyncGroup)
PostCommit executes post-commit functions.
func (*RedisClusterDataConn) PreCommit ¶
func (dc *RedisClusterDataConn) PreCommit(ag *sabi.AsyncGroup) errs.Err
PreCommit executes pre-commit functions.
func (*RedisClusterDataConn) Rollback ¶
func (dc *RedisClusterDataConn) Rollback(ag *sabi.AsyncGroup)
Rollback does nothing for this data connection.
func (*RedisClusterDataConn) ShouldForceBack ¶
func (dc *RedisClusterDataConn) ShouldForceBack() bool
ShouldForceBack returns true to indicate that this data connection should be forced back.
type RedisClusterDataSrc ¶
type RedisClusterDataSrc struct {
// contains filtered or unexported fields
}
RedisClusterDataSrc is a data source for Redis Cluster.
func NewRedisClusterDataSrc ¶
func NewRedisClusterDataSrc(opt *redis.ClusterOptions) *RedisClusterDataSrc
NewRedisClusterDataSrc creates a new RedisClusterDataSrc.
func (*RedisClusterDataSrc) Close ¶
func (ds *RedisClusterDataSrc) Close()
Close closes the Redis cluster client.
func (*RedisClusterDataSrc) CreateDataConn ¶
func (ds *RedisClusterDataSrc) CreateDataConn() (sabi.DataConn, errs.Err)
CreateDataConn creates a new RedisClusterDataConn.
func (*RedisClusterDataSrc) Setup ¶
func (ds *RedisClusterDataSrc) Setup(ag *sabi.AsyncGroup) errs.Err
Setup initializes the Redis cluster client and pings the cluster.
type RedisClusterDataSrcAlreadySetup ¶
type RedisClusterDataSrcAlreadySetup struct{}
RedisClusterDataSrcAlreadySetup is an error reason which indicates that the data source is already setup.
type RedisClusterDataSrcFailToPing ¶
type RedisClusterDataSrcFailToPing struct {
Options *redis.ClusterOptions
}
RedisClusterDataSrcFailToPing is an error reason which indicates that the data source failed to ping.
type RedisClusterDataSrcNotSetupYet ¶
type RedisClusterDataSrcNotSetupYet struct{}
RedisClusterDataSrcNotSetupYet is an error reason which indicates that the data source is not setup yet.
type RedisDataConn ¶
type RedisDataConn struct {
// contains filtered or unexported fields
}
RedisDataConn is a data connection for Redis.
func (*RedisDataConn) AddForceBack ¶
func (dc *RedisDataConn) AddForceBack(fn func(*redis.Conn) errs.Err)
AddForceBack adds a function to be executed on force back.
func (*RedisDataConn) AddPostCommit ¶
func (dc *RedisDataConn) AddPostCommit(fn func(*redis.Conn) errs.Err)
AddPostCommit adds a function to be executed after commit.
func (*RedisDataConn) AddPreCommit ¶
func (dc *RedisDataConn) AddPreCommit(fn func(*redis.Conn) errs.Err)
AddPreCommit adds a function to be executed before commit.
func (*RedisDataConn) Close ¶
func (dc *RedisDataConn) Close()
Close does nothing for this data connection.
func (*RedisDataConn) Commit ¶
func (dc *RedisDataConn) Commit(ag *sabi.AsyncGroup) errs.Err
Commit does nothing for this data connection.
func (*RedisDataConn) ForceBack ¶
func (dc *RedisDataConn) ForceBack(ag *sabi.AsyncGroup)
ForceBack executes force-back functions in reverse order.
func (*RedisDataConn) GetConnection ¶
func (dc *RedisDataConn) GetConnection() *redis.Conn
GetConnection returns the underlying redis connection.
func (*RedisDataConn) PostCommit ¶
func (dc *RedisDataConn) PostCommit(ag *sabi.AsyncGroup)
PostCommit executes post-commit functions.
func (*RedisDataConn) PreCommit ¶
func (dc *RedisDataConn) PreCommit(ag *sabi.AsyncGroup) errs.Err
PreCommit executes pre-commit functions.
func (*RedisDataConn) Rollback ¶
func (dc *RedisDataConn) Rollback(ag *sabi.AsyncGroup)
Rollback does nothing for this data connection.
func (*RedisDataConn) ShouldForceBack ¶
func (dc *RedisDataConn) ShouldForceBack() bool
ShouldForceBack returns true to indicate that this data connection should be forced back.
type RedisDataSrc ¶
type RedisDataSrc struct {
// contains filtered or unexported fields
}
RedisDataSrc is a data source for Redis.
func NewRedisDataSrc ¶
func NewRedisDataSrc(opt *redis.Options) *RedisDataSrc
NewRedisDataSrc creates a new RedisDataSrc.
func (*RedisDataSrc) CreateDataConn ¶
func (ds *RedisDataSrc) CreateDataConn() (sabi.DataConn, errs.Err)
CreateDataConn creates a new RedisDataConn.
func (*RedisDataSrc) Setup ¶
func (ds *RedisDataSrc) Setup(ag *sabi.AsyncGroup) errs.Err
Setup initializes the Redis client and pings the server.
type RedisDataSrcAlreadySetup ¶
type RedisDataSrcAlreadySetup struct{}
RedisDataSrcAlreadySetup is an error reason which indicates that the data source is already setup.
type RedisDataSrcFailToPing ¶
RedisDataSrcFailToPing is an error reason which indicates that the data source failed to ping.
type RedisDataSrcNotSetupYet ¶
type RedisDataSrcNotSetupYet struct{}
RedisDataSrcNotSetupYet is an error reason which indicates that the data source is not setup yet.
type RedisSentinelDataConn ¶
type RedisSentinelDataConn struct {
// contains filtered or unexported fields
}
RedisSentinelDataConn is a data connection for Redis Sentinel.
func (*RedisSentinelDataConn) AddForceBack ¶
func (dc *RedisSentinelDataConn) AddForceBack(fn func(*redis.Conn) errs.Err)
AddForceBack adds a function to be executed on force back.
func (*RedisSentinelDataConn) AddPostCommit ¶
func (dc *RedisSentinelDataConn) AddPostCommit(fn func(*redis.Conn) errs.Err)
AddPostCommit adds a function to be executed after commit.
func (*RedisSentinelDataConn) AddPreCommit ¶
func (dc *RedisSentinelDataConn) AddPreCommit(fn func(*redis.Conn) errs.Err)
AddPreCommit adds a function to be executed before commit.
func (*RedisSentinelDataConn) Close ¶
func (dc *RedisSentinelDataConn) Close()
Close does nothing for this data connection.
func (*RedisSentinelDataConn) Commit ¶
func (dc *RedisSentinelDataConn) Commit(ag *sabi.AsyncGroup) errs.Err
Commit does nothing for this data connection.
func (*RedisSentinelDataConn) ForceBack ¶
func (dc *RedisSentinelDataConn) ForceBack(ag *sabi.AsyncGroup)
ForceBack executes force-back functions in reverse order.
func (*RedisSentinelDataConn) GetConnection ¶
func (dc *RedisSentinelDataConn) GetConnection() *redis.Conn
GetConnection returns the underlying redis connection.
func (*RedisSentinelDataConn) PostCommit ¶
func (dc *RedisSentinelDataConn) PostCommit(ag *sabi.AsyncGroup)
PostCommit executes post-commit functions.
func (*RedisSentinelDataConn) PreCommit ¶
func (dc *RedisSentinelDataConn) PreCommit(ag *sabi.AsyncGroup) errs.Err
PreCommit executes pre-commit functions.
func (*RedisSentinelDataConn) Rollback ¶
func (dc *RedisSentinelDataConn) Rollback(ag *sabi.AsyncGroup)
Rollback does nothing for this data connection.
func (*RedisSentinelDataConn) ShouldForceBack ¶
func (dc *RedisSentinelDataConn) ShouldForceBack() bool
ShouldForceBack returns true to indicate that this data connection should be forced back.
type RedisSentinelDataSrc ¶
type RedisSentinelDataSrc struct {
// contains filtered or unexported fields
}
RedisSentinelDataSrc is a data source for Redis Sentinel.
func NewRedisSentinelDataSrc ¶
func NewRedisSentinelDataSrc(opt *redis.FailoverOptions) *RedisSentinelDataSrc
NewRedisSentinelDataSrc creates a new RedisSentinelDataSrc.
func (*RedisSentinelDataSrc) Close ¶
func (ds *RedisSentinelDataSrc) Close()
Close closes the Redis client.
func (*RedisSentinelDataSrc) CreateDataConn ¶
func (ds *RedisSentinelDataSrc) CreateDataConn() (sabi.DataConn, errs.Err)
CreateDataConn creates a new RedisSentinelDataConn.
func (*RedisSentinelDataSrc) Setup ¶
func (ds *RedisSentinelDataSrc) Setup(ag *sabi.AsyncGroup) errs.Err
Setup initializes the Redis client and pings the server.
type RedisSentinelDataSrcAlreadySetup ¶
type RedisSentinelDataSrcAlreadySetup struct{}
RedisSentinelDataSrcAlreadySetup is an error reason which indicates that the data source is already setup.
type RedisSentinelDataSrcFailToPing ¶
RedisSentinelDataSrcFailToPing is an error reason which indicates that the data source failed to ping.
type RedisSentinelDataSrcNotSetupYet ¶
type RedisSentinelDataSrcNotSetupYet struct{}
RedisSentinelDataSrcNotSetupYet is an error reason which indicates that the data source is not setup yet.