Module etcd-client.txn
This module helps to create a transaction object for etcd-client.
An example of usage:
local txn = etcd_txn.new()
txn:cmp('foo', txn.EQUAL, {value = 'bar'})
txn:put_on_success('a', 'a') -- will be executed if value('foo') == 'bar'
txn:put_on_success('b', 'a') -- will be executed if value('foo') == 'bar'
txn:put_on_failure('a', 'b') -- will be executed if value('foo') ~= 'bar'
txn:put_on_failure('b', 'b') -- will be executed if value('foo') ~= 'bar'
local ret = etcd_client:txn(txn)
Instance methods
| instance.cmp (self, key, result, opts) | Add a logical comparison operation for the transaction. |
| instance.put_on_success (self, key[, value[, opts]]) | Add a put request when compare evaluates to true. |
| instance.put_on_failure (self, key[, value[, opts]]) | Add a put request when compare evaluates to false. |
| instance.range_on_success (self, key[, range_end[, opts]]) | Add a range request when compare evaluates to true. |
| instance.range_on_failure (self, key[, range_end[, opts]]) | Add a range request when compare evaluates to false. |
| instance.deleterange_on_success (self, key[, range_end[, opts]]) | Add a delete range request when compare evaluates to true. |
| instance.deleterange_on_failure (self, key[, range_end[, opts]]) | Add a delete range request when compare evaluates to false. |
| instance.txn_on_success (self, txn) | Add a txn request when compare evaluates to true. |
| instance.txn_on_failure (self, txn) | Add a txn request when compare evaluates to false. |
Module functions
| new () | Creates a new txn intance. |
Module constants
| EQUAL | A target value must be equal to a specified. |
| GREATER | A target value must be greater then a specified. |
| LESS | A target value must be less then a specified. |
| NOT_EQUAL | A target value must be not equal to a specified. |
Instance methods
- instance.cmp (self, key, result, opts)
-
Add a logical comparison operation for the transaction.
Be careful, a one target must be set with opts.
Parameters:
- self
txn instance.
- key
(string)
Key for the comparison operation.
- result
(string)
An expected result of the operation, one of the values:
- opts
(table)
Comparison operation options. A one target must be set.
- range_end
(string,
optional)
Compares the given target to all keys in the range [key, range_end).
- value
(string,
optional)
Target is the value of the given key.
- version
(integer,
optional)
Target is the version of the given key.
- create_revision
(integer,
optional)
Target is the creation revision of the given key.
- mod_revision
(integer,
optional)
Target is the last modified revision of the given key.
- lease
(integer,
optional)
Target is the lease id of the given key.
- range_end
(string,
optional)
Returns:
-
nil
Raises:
an error if opts are invalid - self
- instance.put_on_success (self, key[, value[, opts]])
-
Add a put request when compare evaluates to true.
See a full description of all parameters at etcd-client.put.
Parameters:
- self
txn instance.
- key
(string)
Key to put.
- value
(string,
optional)
Value to associate with the key.
- opts
(table,
optional)
Put request options.
Returns:
-
nil
See also:
- self
- instance.put_on_failure (self, key[, value[, opts]])
-
Add a put request when compare evaluates to false.
See a full description of all parameters at etcd-client.put.
Parameters:
- self
txn instance.
- key
(string)
Key to put.
- value
(string,
optional)
Value to associate with the key.
- opts
(table,
optional)
Put request options.
Returns:
-
nil
See also:
- self
- instance.range_on_success (self, key[, range_end[, opts]])
-
Add a range request when compare evaluates to true.
See a full description of all parameters at etcd-client.range.
Parameters:
- self
txn instance.
- key
(string)
A key, a key prefix or a range start (depending of 'range_end' value).
- range_end
(string,
optional)
Upper boundary of the range (exclusive).
- opts
(table,
optional)
Range request options.
Returns:
-
nil
See also:
- self
- instance.range_on_failure (self, key[, range_end[, opts]])
-
Add a range request when compare evaluates to false.
See a full description of all parameters at etcd-client.range.
Parameters:
- self
txn instance.
- key
(string)
A key, a key prefix or a range start (depending of 'range_end' value).
- range_end
(string,
optional)
Upper boundary of the range (exclusive).
- opts
(table,
optional)
Range request options.
Returns:
-
nil
See also:
- self
- instance.deleterange_on_success (self, key[, range_end[, opts]])
-
Add a delete range request when compare evaluates to true.
See a full description of all parameters at etcd-client.deleterange.
Parameters:
- self
txn instance.
- key
(string)
The first key of the range to delete.
- range_end
(string,
optional)
Upper boundary of the range to delete (exclusive).
- opts
(table,
optional)
Delete range request options.
Returns:
-
nil
See also:
- self
- instance.deleterange_on_failure (self, key[, range_end[, opts]])
-
Add a delete range request when compare evaluates to false.
See a full description of all parameters at etcd-client.deleterange.
Parameters:
- self
txn instance.
- key
(string)
The first key of the range to delete.
- range_end
(string,
optional)
Upper boundary of the range to delete (exclusive).
- opts
(table,
optional)
Delete range request options.
Returns:
-
nil
See also:
- self
- instance.txn_on_success (self, txn)
-
Add a txn request when compare evaluates to true.
The feature requires etcd 3.3+.
Parameters:
- self
txn instance.
- txn
(table)
Another txn instance.
Returns:
-
nil
See also:
- self
- instance.txn_on_failure (self, txn)
-
Add a txn request when compare evaluates to false.
The feature requires etcd 3.3+.
Parameters:
- self
txn instance.
- txn
(table)
Another txn instance.
Returns:
-
nil
See also:
- self
Module functions
Module constants
The gRPC codes are exported to the package level. The error codes comes from gRPC api implementation.