pip_services3_redis 1.1.0 copy "pip_services3_redis: ^1.1.0" to clipboard
pip_services3_redis: ^1.1.0 copied to clipboard

This framework is part of the [Pip.Services](https://github.com/pip-services/pip-services) project. It contains Redis components RedisCache and RedisLock

example/main.dart

import 'dart:io';
import 'package:pip_services3_commons/pip_services3_commons.dart';
import 'package:pip_services3_redis/pip_services3_redis.dart';

void main() async {
  final LOCK1 = 'lock_1';
  final LOCK2 = 'lock_2';

  RedisLock _lock;

  var host = Platform.environment['REDIS_SERVICE_HOST'] ?? 'localhost';
  var port = Platform.environment['REDIS_SERVICE_PORT'] ?? 6379;

  _lock = RedisLock();

  var config = ConfigParams.fromTuples(
      ['connection.host', host, 'connection.port', port]);
  _lock.configure(config);

  await _lock.open(null);

  // Try to acquire lock for the first time
  var result = await _lock.tryAcquireLock('123', LOCK1, 3000);
  print(result); // true

  // Try to acquire lock for the second time
  result = await _lock.tryAcquireLock('123', LOCK1, 3000); // false

  // Release the lock
  await _lock.releaseLock('123', LOCK1);

  // Acquire lock for the first time
  await _lock.acquireLock('123', LOCK2, 3000, 1000);
  // Acquire lock for the second time
  try {
    await _lock.acquireLock('123', LOCK2, 3000, 1000); // error
  } catch (err) {
    // error handle
  }

  // Release the lock
  await _lock.releaseLock('123', LOCK2);

  await _lock.close(null);
}
0
likes
105
pub points
0%
popularity

Publisher

verified publisherentinco.com

This framework is part of the [Pip.Services](https://github.com/pip-services/pip-services) project. It contains Redis components RedisCache and RedisLock

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

pip_services3_commons, pip_services3_components, redis

More

Packages that depend on pip_services3_redis