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 ICredentialStore

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.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

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
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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
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.
toString() String
A string representation of this object.
inherited
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.

Operators

operator ==(Object other) bool
The equality operator.
inherited