AerospikeC客户端手册―――大数据类型(二)
2015-07-21 16:26:04
·
作者:
·
浏览: 1
ts); exit(-1); } LOG("lset size confirmed to be %u", n_elements); as_ldt lset2; as_ldt_init(&lset2, "mylset", AS_LDT_LSET, NULL); as_list* p_list = NULL; // Get all the values back. if (aerospike_lset_filter(&as, &err, NULL, &g_key, &lset, NULL, NULL, &p_list) != AEROSPIKE_OK) { LOG("aerospike_lset_filter() returned %d - %s", err.code, err.message); as_list_destroy(p_list); exit(-1); } // See if the elements match what we expect. as_arraylist_iterator it; as_arraylist_iterator_init(&it, (const as_arraylist*)p_list); while (as_arraylist_iterator_has_next(&it)) { const as_val* p_val = as_arraylist_iterator_next(&it); LOG(" element - type = %d, value = %s ", as_val_type(p_val), as_val_tostring(p_val)); } as_list_destroy(p_list); p_list = NULL; // Add 3 more items into the set. By using as_arraylist_inita(), we won't // need to destroy the as_arraylist if we only use // as_arraylist_append_int64(). as_arraylist vals; as_arraylist_inita(&vals, 3); as_arraylist_append_int64(&vals, 1001); as_arraylist_append_int64(&vals, 2002); as_arraylist_append_int64(&vals, 3003); if (aerospike_lset_addall(&as, &err, NULL, &g_key, &lset, (const as_list*)&vals) != AEROSPIKE_OK) { LOG("aerospike_lset_addall() returned %d - %s", err.code, err.message); exit(-1); } LOG("3 more values added"); // Get and print all the values back again. if (aerospike_lset_filter(&as, &err, NULL, &g_key, &lset, NULL, NULL, &p_list) != AEROSPIKE_OK) { LOG("second aerospike_lset_filter() returned %d - %s", err.code, err.message); as_list_destroy(p_list); exit(-1); } as_arraylist_iterator_init(&it, (const as_arraylist*)p_list); while (as_arraylist_iterator_has_next(&it)) { const as_val* p_val = as_arraylist_iterator_next(&it); LOG(" element - type = %d, value = %s ", as_val_type(p_val), as_val_tostring(p_val)); } as_list_destroy(p_list); p_list = NULL; // No need to destroy as_boolean if using as_boolean_init() on stack object. as_boolean exists; as_boolean_init(&exists, false); // Check if a specific value exists. if (aerospike_lset_exists(&as, &err, NULL, &g_key, &lset2, (const as_val*)&ival, &exists) != AEROSPIKE_OK) { LOG("aerospike_lset_exists() returned %d - %s", err.code, err.message); exit(-1); } if (as_boolean_get(&exists)) { LOG("not able to find a value which should be in the set"); exit(-1); } as_boolean_init(&exists, false); as_integer_init(&ival, 33333); // Check that a value which should not be in the set, really isn't. if (aerospike_lset_exists(&as, &err, NULL, &g_key, &lset2, (const as_val*)&ival, &exists) != AEROSPIKE_OK) { LOG("second aerospike_lset_exists() returned %d - %s", err.code, err.message); exit(-1); } if (as_boolean_get(&exists)) { LOG("found a value which should not be in the set"); exit(-1); } LOG("existence functionality checked"); // Destroy the lset. if (aerospike_lset_destroy(&as, &err, NULL, &g_key, &lset) != AEROSPIKE_OK) { LOG("aerospike_lset_destroy() returned %d - %s", err.code, err.message); exit(-1); } n_elements = 0; // See if we can still do any lset operations. if (aerospike_lset_size(&as, &err, NULL, &g_key, &lset, &n_elements) == AEROSPIKE_OK) { LOG("aerospike_lset_size() did not return error"); exit(-1); } // Cleanup and disconnect from the database cluster. example_cleanup(&as); LOG("lset example successfully completed"); return 0; }
总结
LDT的默认行为是接受任何类型的对象并存储。对象可以是不同类型和大小。唯一的附加条件是,若对象是复杂类型,那么大数据类型(LDT)链表(List)机制要求带