def test_neg_operate_ordered_prepend_set_to_aerospike_null(self):
        """
        Invoke operate_ordered() with prepend command bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        llist = [
            {
                "op": aerospike.OPERATOR_PREPEND,
                "bin": "no",
                "val": aerospike.null()
            },
            {
                "op": aerospike.OPERATOR_READ,
                "bin": "no"
            }
        ]

        try:
            (key, _, bins) = self.as_connection.operate_ordered(key, llist)

        except e.InvalidRequest as exception:
            assert exception.code == 4
        self.as_connection.remove(key)
Beispiel #2
0
    def test_pos_operate_prepend_set_to_aerospike_null(self):
        """
        Invoke operate() with prepend command with bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        (key, _, bins) = self.as_connection.get(key)

        assert {"name": "John", "no": 3} == bins

        llist = [{
            "op": aerospike.OPERATOR_PREPEND,
            "bin": "no",
            "val": aerospike.null()
        }, {
            "op": aerospike.OPERATOR_READ,
            "bin": "no"
        }]

        try:
            (key, _, bins) = self.as_connection.operate(key, llist)

        except e.InvalidRequest as exception:
            assert exception.code == 4
        self.as_connection.remove(key)
    def test_pos_operate_ordered_write_set_to_aerospike_null(self):
        """
        Invoke operate_ordered() with write command bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        llist = [
            {
                "op": aerospike.OPERATOR_WRITE,
                "bin": "no",
                "val": aerospike.null()
            },
            {
                "op": aerospike.OPERATOR_READ,
                "bin": "no"
            }
        ]

        _, _, bins = self.as_connection.operate_ordered(key, llist)
        self.as_connection.remove(key)
        # we read a non existent bin, so nothing is returned
        assert [] == bins
Beispiel #4
0
    def test_pos_operate_write_set_to_aerospike_null(self):
        """
        Invoke operate() with write command with bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        (key, _, bins) = self.as_connection.get(key)

        assert {"name": "John", "no": 3} == bins

        llist = [{
            "op": aerospike.OPERATOR_WRITE,
            "bin": "no",
            "val": aerospike.null()
        }, {
            "op": aerospike.OPERATOR_READ,
            "bin": "no"
        }]

        (key, _, bins) = self.as_connection.operate(key, llist)
        assert {} == bins

        self.as_connection.remove(key)
    def test_pos_operate_prepend_set_to_aerospike_null(self):
        """
        Invoke operate() with prepend command with bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        (key, _, bins) = self.as_connection.get(key)

        assert {"name": "John", "no": 3} == bins

        llist = [
            operations.prepend("no", aerospike.null()),
            operations.read("no")
        ]

        try:
            (key, _, bins) = self.as_connection.operate(key, llist)

        except e.InvalidRequest as exception:
            assert exception.code == 4
        self.as_connection.remove(key)
    def test_pos_operate_prepend_set_to_aerospike_null(self):
        """
        Invoke operate() with prepend command with bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        (key, _, bins) = self.as_connection.get(key)

        assert {"name": "John", "no": 3} == bins

        llist = [
            operations.prepend("no", aerospike.null()),
            operations.read("no")
        ]

        try:
            (key, _, bins) = self.as_connection.operate(key, llist)

        except e.InvalidRequest as exception:
            assert exception.code == 4
        self.as_connection.remove(key)
    def test_pos_operate_ordered_write_set_to_aerospike_null(self):
        """
        Invoke operate_ordered() with write command bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        llist = [
            {
                "op": aerospike.OPERATOR_WRITE,
                "bin": "no",
                "val": aerospike.null()
            },
            {
                "op": aerospike.OPERATOR_READ,
                "bin": "no"
            }
        ]

        (key, _, bins) = self.as_connection.operate_ordered(key, llist)

        assert [None, ('no', None)] == bins

        self.as_connection.remove(key)
    def test_map_value_null_infinity_range(self):
        operation = map_ops.map_get_by_value_range(
            self.cdt_map_bin,
            [1, aerospike.null()],
            [1, aerospike.CDTInfinite()],
            aerospike.MAP_RETURN_KEY
        )
        result = get_list_result_from_operation(
            self.as_connection,
            self.cdt_key,
            operation,
            self.cdt_map_bin
        )

        assert set(result) == set(('b', 'c', 'd'))
    def test_pos_operate_write_set_to_aerospike_null(self):
        """
        Invoke operate() with write command with bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        self.as_connection.put(key, bins)

        llist = [
            operations.write("no", aerospike.null()),
            operations.read("no")
        ]

        _, _, bins = self.as_connection.operate(key, llist)
        assert {} == bins

        self.as_connection.remove(key)
    def test_pos_operate_write_set_to_aerospike_null(self):
        """
        Invoke operate() with write command with bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        self.as_connection.put(key, bins)

        llist = [
            operations.write("no", aerospike.null()),
            operations.read("no")
        ]

        _, _, bins = self.as_connection.operate(key, llist)
        assert {} == bins

        self.as_connection.remove(key)
    def test_cdt_infinite_list_range_value(self):
        operation = lo.list_get_by_value_range(
            self.cdt_list_bin,
            aerospike.LIST_RETURN_VALUE,
            [1, aerospike.null()],
            [1, aerospike.CDTInfinite()]
        )            

        result = get_list_result_from_operation(
            self.as_connection,
            self.keys[0],
            operation,
            self.cdt_list_bin
            )

        # All items starting with 1
        assert len(result) == 3
        for lst in result:
            assert lst[0] == 1
Beispiel #12
0
    def test_pos_operate_ordered_write_set_to_aerospike_null(self):
        """
        Invoke operate_ordered() with write command bin set to aerospike_null
        """
        key = ('test', 'demo', 'null_record')

        bins = {"name": "John", "no": 3}

        assert 0 == self.as_connection.put(key, bins)

        llist = [{
            "op": aerospike.OPERATOR_WRITE,
            "bin": "no",
            "val": aerospike.null()
        }, {
            "op": aerospike.OPERATOR_READ,
            "bin": "no"
        }]

        _, _, bins = self.as_connection.operate_ordered(key, llist)
        self.as_connection.remove(key)
        # we read a non existent bin, so nothing is returned
        assert [] == bins
pp = pprint.PrettyPrinter(indent=2)
sensor_id = options.sensor_id
spacer = "=" * 30
try:
    key = (namespace, set, "sensor{}-12-31".format(sensor_id))
    print("\nRetrieve sensor{} data for 8-11am, December 31st".format(sensor_id))
    if options.interactive:
        pause()
    starts = 8 * 60
    ends = 11 * 60
    ops = [
        lh.list_get_by_value_range(
            "t",
            aerospike.LIST_RETURN_VALUE,
            [starts, aerospike.null()],
            [ends, aerospike.null()],
        )
    ]
    _, _, b = client.operate(key, ops)
    pp.pprint(b["t"])
    print(spacer)

    print("\nGet sensor{} data for April 2nd".format(sensor_id))
    key = (namespace, set, "sensor{}-04-02".format(sensor_id))
    if options.interactive:
        pause()
    _, _, b = client.get(key)
    pp.pprint(b["t"])
    print(spacer)
Beispiel #14
0
                    "l", 99, -1, aerospike.LIST_RETURN_VALUE, 4
                )
            ],
        )
        print(
            "\nremove_by_value_rel_rank_range('l', 99, -1, VALUE, 4): {}".format(
                bins["l"]
            )
        )
        # remove_by_value_rel_rank_range('l', 99, -1, VALUE, 4): [26]
    except ex.OpNotApplicable as e:
        print("\nError: {0} [{1}]".format(e.msg, e.code))

    # example with tuple values
    tuples = [["z", 26], ["d", 4], ["b", 2], ["a", 1], ["e", 3], ["b", 2]]
    nil = aerospike.null()
    ops = [
        operations.write("l", tuples),
        operations.read("l"),
        lops.list_remove_by_value_rank_range_relative(
            "l", ["c", nil], -1, aerospike.LIST_RETURN_NONE, 2, inverted=True
        ),
        operations.read("l"),
    ]
    key, metadata, bins = client.operate_ordered(key, ops)
    print("\n{}".format(bins[0][1]))
    # [['z', 26], ['d', 4], ['b', 2], ['a', 1], ['e', 3], ['b', 2]]
    print(
        "remove_by_value_rel_rank_range('l', ['c', NIL], -1, INVERTED|NONE, 2)\n{}".format(
            bins[1][1]
        )
Beispiel #15
0
pp = pprint.PrettyPrinter(indent=2)
spacer = "=" * 30
epoch = datetime.datetime(2019, 1, 1)
now = datetime.datetime.now()
try:
    # Find all segments whose TTL is before this hour
    key = (namespace, set, "u3")
    current_hour = int((now - epoch).total_seconds() / 3600)
    print("\nCurrent hour is {} hours since epoch".format(current_hour))
    if options.interactive:
        pause()

    ops = [
        mh.map_get_by_value_range(
            "u",
            [0, aerospike.null()],
            [current_hour - 1, aerospike.null()],
            aerospike.MAP_RETURN_KEY,
            False,
        ),
        mh.map_size("u"),
    ]
    _, _, b = client.operate_ordered(key, ops)
    stale_segments, total_segments = b
    print("This user has a total of {} segments".format(total_segments[1]))
    print("Of those, a total of {} segments should be cleaned".format(
        len(stale_segments[1])))
    print("Show all segments with a segment TTL before the current hour:")
    print(stale_segments)
    print(spacer)
    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()
    ops = [
        mh.map_get_by_value_range(
            "u",
            [0, aerospike.null()],
            [end_ttl, aerospike.null()],
            aerospike.MAP_RETURN_KEY,
            True,
        )
    ]
    _, _, b = client.operate(key, ops)
    print("Show all segments not expiring today:".format(segment_ttl))
    print(b["u"])
    print(spacer)

    # Count all the segments in the segment ID range 8000-9000
    print("\nCount how many segments u1 has in the segment ID range 8000-9000")
    if options.interactive:
        pause()
    ops = [mh.map_get_by_key_range("u", 8000, 9000, aerospike.MAP_RETURN_COUNT)]
    client.put(key, bins, {"ttl": aerospike.TTL_NEVER_EXPIRE})
    map_policy = {
        "map_write_mode": aerospike.MAP_UPDATE,
        "map_order": aerospike.MAP_KEY_VALUE_ORDERED,
    }
    client.map_set_policy(key, "messages", map_policy)
except ex.RecordError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(3)

pp = pprint.PrettyPrinter(indent=2)
try:
    print("\nGet the messages between two timestamps using",
          "'get_by_value_interval'")
    k = client.map_get_by_value_range(
        key,
        "messages",
        [1523474230000, aerospike.null()],
        [1523474250000, aerospike.null()],
        aerospike.MAP_RETURN_VALUE,
    )
    pp.pprint(k)
    print("\nGet the four most recent messages using 'get_by_rank_range'")
    v = client.map_get_by_rank_range(key, "messages", -4, 4,
                                     aerospike.MAP_RETURN_VALUE)
    pp.pprint(v)
except ex.RecordError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))

client.close()
        aerospike.LIST_ORDERED,
        "write_flags": (aerospike.LIST_WRITE_ADD_UNIQUE
                        | aerospike.LIST_WRITE_PARTIAL
                        | aerospike.LIST_WRITE_NO_FAIL),
    }
    ops = [lh.list_append_items("scores", wr_100m_2, list_policy)]
    client.operate(key, ops)

    k, m, b = client.get(key)
    print("\nThe merged, ordered, unique scores are")
    pp.pprint(b["scores"])

    print("\nClosest two results to 10.0 seconds by relative rank")
    ops = [
        lh.list_get_by_value_rank_range_relative(
            "scores",
            [10.00, aerospike.null()],
            -1,
            aerospike.LIST_RETURN_VALUE,
            2,
            False,
        )
    ]
    k, m, b = client.operate(key, ops)
    print(b["scores"])
    print("\n")
except e.RecordError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))

client.close()