void RiakTest::ListBuckets() { riack_string_list* bucket_list; riack_list_buckets(m_riak, &bucket_list); char temp[_MAX_PATH]; for (int i = 0; i < bucket_list->string_count; i++) { riack_string& str = bucket_list->strings[i]; memset(temp, 0, _MAX_PATH); memcpy(temp, str.value, str.len); printf("%s\n", temp); } riack_free_string_list_p(m_riak, &bucket_list); }
/* {{{ proto array Riak\Bucket->index(string $index, string $from [, string $to]) Perform a secondary index lookup */ PHP_METHOD(RiakBucket, index) { riack_string rsbucket, rsindex, rsfrom, rsto, *type; riack_string_list *resultlist; char *index, *from, *to; int indexlen, fromlen, tolen, riackstatus, i; riak_connection *connection; zval *zresult; tolen = 0; to = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &index, &indexlen, &from, &fromlen, &to, &tolen) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } connection = get_riak_connection(getThis() TSRMLS_CC); rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); type = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); rsindex.len = indexlen; rsindex.value = index; rsfrom.len = fromlen; rsfrom.value = from; if (to != NULL && tolen > 0) { rsto.len = tolen; rsto.value = to; RIACK_RETRY_OP(riackstatus, connection, riack_2i_query_range_ext(connection->client, &rsbucket, type, &rsindex, &rsfrom, &rsto, &resultlist)); } else { RIACK_RETRY_OP(riackstatus, connection, riack_2i_query_exact_ext(connection->client, &rsbucket, type, &rsindex, &rsfrom, &resultlist)); } RFREE(connection->client, type); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresult); array_init(zresult); for (i=0; i<resultlist->string_count; ++i) { add_next_index_stringl(zresult, resultlist->strings[i].value, resultlist->strings[i].len, 1); } riack_free_string_list_p(connection->client, &resultlist); RETURN_ZVAL(zresult, 0, 1); }
/* {{{ proto array Riak\Bucket->indexQuery(IndexQuery $query[, IndexInput $input]) Apply given properties to this bucket */ PHP_METHOD(RiakBucket, indexQuery) { riak_connection *connection; riack_2i_query_req req; riack_string_list *result_keys; riack_string *continuation, *type; zval *zquery, *zinput, *zname, *zisrange, *zcontinuation, *zresult; int riackstatus; zinput = zquery = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O", &zquery, riak_index_query_ce, &zinput, riak_index_input_ce) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } // TODO Validate query have exact or ranged values connection = get_riak_connection(getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); memset(&req, 0, sizeof(req)); type = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); if (type != NULL) { req.bucket_type.len = type->len; req.bucket_type.value = type->value; } req.bucket = riack_name_from_bucket(getThis() TSRMLS_CC); MAKE_STD_ZVAL(zname); RIAK_CALL_METHOD(Riak_Query_IndexQuery, getName, zname, zquery); req.index.len = Z_STRLEN_P(zname); req.index.value = Z_STRVAL_P(zname); continuation = NULL; zcontinuation = NULL; if (zinput) { zval *zmaxresults; MAKE_STD_ZVAL(zmaxresults); RIAK_CALL_METHOD(Riak_Input_IndexInput, getMaxResults, zmaxresults, zinput); if (Z_TYPE_P(zmaxresults) == IS_LONG) { req.max_results = Z_LVAL_P(zmaxresults); } zval_ptr_dtor(&zmaxresults); MAKE_STD_ZVAL(zcontinuation); RIAK_CALL_METHOD(Riak_Input_IndexInput, getContinuation, zcontinuation, zinput); if (Z_TYPE_P(zcontinuation) == IS_STRING) { req.continuation_token.len = Z_STRLEN_P(zcontinuation); req.continuation_token.value = Z_STRVAL_P(zcontinuation); } } MAKE_STD_ZVAL(zisrange); RIAK_CALL_METHOD(Riak_Query_IndexQuery, isRangeQuery, zisrange, zquery); if (Z_BVAL_P(zisrange)) { zval *zmin, *zmax; // TODO Call getter instead, this is cheat zmin = zend_read_property(riak_index_query_ce, zquery, "minValue", sizeof("minValue")-1, 1 TSRMLS_CC); zmax = zend_read_property(riak_index_query_ce, zquery, "maxValue", sizeof("maxValue")-1, 1 TSRMLS_CC); req.search_min.len = Z_STRLEN_P(zmin); req.search_min.value = Z_STRVAL_P(zmin); req.search_max.len = Z_STRLEN_P(zmax); req.search_max.value = Z_STRVAL_P(zmax); RIACK_RETRY_OP(riackstatus, connection, riack_2i_query(connection->client, &req, &result_keys, &continuation)); } else { zval *zexact; zexact = zend_read_property(riak_index_query_ce, zquery, "exactValue", sizeof("exactValue")-1, 1 TSRMLS_CC); req.search_exact.len = Z_STRLEN_P(zexact); req.search_exact.value = Z_STRVAL_P(zexact); RIACK_RETRY_OP(riackstatus, connection, riack_2i_query(connection->client, &req, &result_keys, &continuation)); } zval_ptr_dtor(&zname); zval_ptr_dtor(&zisrange); if (zcontinuation) { zval_ptr_dtor(&zcontinuation); } RFREE(connection->client, type); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); zresult = riak_index_output_from_string_list_and_continuation(result_keys, continuation TSRMLS_CC); riack_free_string_p(connection->client, &continuation); riack_free_string_list_p(connection->client, &result_keys); RETURN_ZVAL(zresult, 0, 1); }