RedisLock class

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:
  • retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
  • retries: number of retries (default: 3)

References

  • :discovery::*:1.0 (optional) IDiscovery services to resolve connection
  • :credential-store::*:1.0 (optional) Credential stores to resolve credential

Example

var lock = RedisLock(); lock.configure(ConfigParams.fromTuples( 'host', 'localhost', 'port', 6379 ));

await lock.open('123'); ...

await lock.acquire('123', 'key1');

try { // Processing... } finally { await lock.releaseLock('123', 'key1'); // Continue... }

Constructors

RedisLock()

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

close(String correlationId) → Future
Closes component and frees used resources. [...]
configure(ConfigParams config) → void
Configures component by passing configuration parameters. [...]
isOpen() → bool
Checks if the component is opened. [...]
open(String correlationId) → Future
Opens the component. [...]
releaseLock(String correlationId String key) → Future
Releases prevously acquired lock by its key. [...]
setReferences(IReferences references) → void
Sets references to dependent components. [...]
tryAcquireLock(String correlationId, String key, int ttl) → Future<bool>
Makes a single attempt to acquire a lock by its key. It returns immediately a positive or negative result. [...]
acquireLock(String correlationId, String key, int ttl int timeout) → Future
Makes multiple attempts to acquire a lock by its key within give time interval. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited