def test_list_increment_with_incorrect_value_type(self):
        '''
        previous list was [1, 2, 3, 4]
        new should be [1, 2, 23, 4]
        '''
        key = ('test', 'demo', 'list_key')
        list = [list_operations.list_increment("int_bin", 2, "twenty")]

        with pytest.raises(e.AerospikeError):
            self.as_connection.operate(key, list)
    def test_list_increment_with_incorrect_value_type(self):
        '''
        previous list was [1, 2, 3, 4]
        new should be [1, 2, 23, 4]
        '''
        key = ('test', 'demo', 'list_key')
        list = [
            list_operations.list_increment("int_bin", 2, "twenty")
        ]

        with pytest.raises(e.AerospikeError):
            self.as_connection.operate(key, list)
    def test_list_increment_with_valid_value(self):
        '''
        previous list was [1, 2, 3, 4]
        new should be [1, 2, 23, 4]
        '''
        key = ('test', 'demo', 'list_key')
        list = [list_operations.list_increment("int_bin", 2, 20)]

        _, _, bins = self.as_connection.operate(key, list)

        assert bins == {'int_bin': 23}
        _, _, bins = self.as_connection.get(key)

        assert bins['int_bin'] == [1, 2, 23, 4]
    def test_list_increment_with_valid_value(self):
        '''
        previous list was [1, 2, 3, 4]
        new should be [1, 2, 23, 4]
        '''
        key = ('test', 'demo', 'list_key')
        list = [
            list_operations.list_increment("int_bin", 2, 20)
        ]

        _, _, bins = self.as_connection.operate(key, list)

        assert bins == {'int_bin': 23}
        _, _, bins = self.as_connection.get(key)

        assert bins['int_bin'] == [1, 2, 23, 4]
    ops = [
        mh.map_put_items("u", segments),
        mh.map_get_by_value(
            "u", [segment_ttl, aerospike.CDTWildcard()], aerospike.MAP_RETURN_KEY_VALUE
        ),
    ]
    _, _, b = client.operate(key, ops)
    print("Show all segments with TTL {}:".format(segment_ttl))
    print(b["u"])
    print(spacer)

    # Update a segment's TTL by 5 extra hours
    # First, the context for the list increment (path to the TTL)
    ctx = [ctxh.cdt_ctx_map_key(segment_id)]
    ops = [
        lh.list_increment("u", 0, 5, ctx=ctx),
        mh.map_get_by_key("u", segment_id, aerospike.MAP_RETURN_KEY_VALUE),
    ]
    print("\nAdd 5 hours to the TTL of user u1's segment {}".format(segment_id))
    if options.interactive:
        pause()
    _, _, b = client.operate(key, ops)
    print(b["u"])
    print(spacer)

    # Fetch the user's segments that are not going to expire today
    today = datetime.datetime(now.year, now.month, now.day)
    end_ttl = int((today - epoch).total_seconds() / 3600)
    print("\nGet only user segments that are not going to expire today")
    if options.interactive:
        pause()
예제 #6
0
except ex.ClientError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(2)

key = (options.namespace, options.set, "list-increment")
try:
    client.remove(key)
except ex.RecordError as e:
    pass

try:
    print("\nincrement(bin, index, delta-value[, writeFlags, context])\n")
    # create a new record with one element by upsert
    # a list created using increment will be unordered, regardless of the
    # list order policy
    ret = client.operate(key, [listops.list_increment("l", 1, 2.1)])
    key, metadata, bins = client.get(key)
    print("increment('l', 1, 2.1)")
    # increment('l', 1, 2.1)
    print("{}".format(bins["l"]))
    # [None, 2.1] - Aerospike NIL represented as a Python None instance

    ops = [
        listops.list_set("l", 0, 1),
        listops.list_append_items("l", [[3, 4]]),
    ]
    client.operate(key, ops)
    key, metadata, bins = client.get(key)
    print("\nset('l', 0, 1)")
    # set('l', 0, 1)
    print("append_items('l', [[3, 4]])")