Documentation
¶
Index ¶
- type RedisLock
- func (c *RedisLock) Close(ctx context.Context) error
- func (c *RedisLock) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *RedisLock) IsOpen() bool
- func (c *RedisLock) Open(ctx context.Context) error
- func (c *RedisLock) ReleaseLock(ctx context.Context, key string) error
- func (c *RedisLock) SetReferences(ctx context.Context, references cref.IReferences)
- func (c *RedisLock) TryAcquireLock(ctx context.Context, key string, ttl int64) (result bool, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RedisLock ¶
RedisLock are distributed lock that is implemented based on Redis in-memory database.
Configuration parameters:
- connection(s):
- discovery_key: (optional) a key to retrieve the connection from IDiscovery
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
- credential(s):
- store_key: key to retrieve parameters from credential store
- username: user name (currently is not used)
- password: user password
- options:
- retrytimeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
- retries: number of retries (default: 3)
- db_num: database number in Redis (default 0)
References:
- *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credential
Example:
ctx := context.Background() lock = NewRedisRedis(); lock.Configure(ctx, cconf.NewConfigParamsFromTuples( "host", "localhost", "port", 6379, )); err = lock.Open(ctx) ... result, err := lock.TryAcquireLock(ctx, "key1", 3000) if result { // Processing... } err = lock.ReleaseLock(ctx, "key1") // Continue...
func NewRedisLock ¶
func NewRedisLock() *RedisLock
NewRedisLock method are creates a new instance of this lock.
func (*RedisLock) Close ¶
Close method are closes component and frees used resources. Parameters:
- ctx context.Context transaction id to trace execution through call chain.
Retruns: error or nil no errors occured.
func (*RedisLock) Configure ¶
func (c *RedisLock) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures component by passing configuration parameters. Parameters:
- config configuration parameters to be set.
func (*RedisLock) IsOpen ¶
IsOpen method are checks if the component is opened. Returns true if the component has been opened and false otherwise.
func (*RedisLock) Open ¶
Open method are opens the component. Parameters:
- ctx context.Context transaction id to trace execution through call chain.
Returns: error or nil no errors occured.
func (*RedisLock) ReleaseLock ¶
ReleaseLock method are releases prevously acquired lock by its key.
- ctx context.Context transaction id to trace execution through call chain.
- key a unique lock key to release.
Returns: error or nil for success.
func (*RedisLock) SetReferences ¶
func (c *RedisLock) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences method are sets references to dependent components. Parameters:
- ctx context.Context
- references references to locate the component dependencies.
func (*RedisLock) TryAcquireLock ¶
func (c *RedisLock) TryAcquireLock(ctx context.Context, key string, ttl int64) (result bool, err error)
TryAcquireLock method are makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result. Parameters:
- ctx context.Context transaction id to trace execution through call chain.
- key a unique lock key to acquire.
- ttl a lock timeout (time to live) in milliseconds.
Returns: a lock result or error.