def do_txn(self, args):
        """
        txn -- Command to create IntegerKey transactions
            txn <expr> [ && <expr> ]*
        """
        txn = integer_key.IntegerKeyTransaction()

        # pylint: disable=line-too-long
        pattern = re.compile(
            r"^\s*(?P<name>[a-zA-Z0-9]+)\s*(?P<verb>[+-]?=)\s*(?P<value>[0-9]+)\s*$"
        )  # noqa
        expressions = args.split('&&')
        for expression in expressions:
            match = pattern.match(expression)
            if not match:
                print 'unable to parse the transaction; {0}'.format(expression)
                return

            update = integer_key.Update()
            update.Verb = self._TxnVerbMap[match.group('verb')]
            update.Name = match.group('name')
            update.Value = long(match.group('value'))
            txn.Updates.append(update)

        txn.sign_from_node(self.LocalNode)

        msg = integer_key.IntegerKeyTransactionMessage()
        msg.Transaction = txn

        self.sign_and_post(msg)
    def dec(self, key, value):
        """
        """
        update = integer_key.Update({
            "Verb": "dec",
            "Name": key,
            "Value": value
        })

        return self._sendtxn(update)
Beispiel #3
0
    def set(self, key, value, txndep=None, postmsg=True):
        """Creates an update object which sets the value associated with a key.

               Args:
                   key (str): The key to set.
                   value (int): The value to set for key.
        """
        update = integer_key.Update({
            "Verb": "set",
            "Name": key,
            "Value": value
        })

        return self._sendtxn(update, txndep, postmsg)
Beispiel #4
0
    def dec(self, key, value, txndep=None, postmsg=True):
        """Creates an update object which decrements the value associated with
           a key.
               Args:
                   key (str): The key to set.
                   value (int): The value by which to decrement the current
                       value associated with key.
        """
        update = integer_key.Update({
            "Verb": "dec",
            "Name": key,
            "Value": value
        })

        return self._sendtxn(update, txndep, postmsg)
    def inc(self, key, value):
        """Creates an update object which increments the value associated with
           a key.
               Args:
                   key (str): The key to set.
                   value (int): The value by which to increment the current
                       value associated with key.
        """
        update = integer_key.Update({
            "Verb": "inc",
            "Name": key,
            "Value": value
        })

        return self._sendtxn(update)