Exemple #1
0
ERL_NIF_TERM as_ldt_lset_size(ErlNifEnv* env, handle_t* handle, void* obj)
{
    ldt_get_args_t* args = (ldt_get_args_t*)obj;

    as_status res;
	as_error err;
    uint32_t nsize;

    res = aerospike_lset_size(&handle->instance, &err, &args->policy, &args->key, &args->ldt, &nsize); 
    as_ldt_clean_get_args(env, args);

    if(res != AEROSPIKE_OK)
        return A_AS_ERROR(env, err);

    ERL_NIF_TERM returnValue;
    returnValue = enif_make_uint(env, nsize);
    
    return A_OK_VALUE(env, returnValue);
}
int lset_size_test(char * keystr, char * ldt_bin, uint32_t   * size) {
    static char * meth = "lset_size_test()";
    if( LSET_DEBUG ) {
        INFO("      [ENTER]:<%s:%s>:From %s", MOD, LDT, meth );
    }

    int rc = 0;

    cl_cluster * c     = lset_g_config->asc;
    cl_object  o_key;
    char       * ns    = lset_g_config->ns;
    char       * set   = lset_g_config->set;
    char       * bname = ldt_bin;

    citrusleaf_object_init_str( &o_key, keystr );

    //check size of lset
    rc = aerospike_lset_size( size,
                c, ns, set, &o_key, bname, lset_g_config->timeout_ms);

    citrusleaf_object_free( &o_key );
    return rc;
} 
/**
 ********************************************************************************************************
 * Get the current item count of the set.
 *
 * @param self                  AerospikeLSet object
 * @param args                  The args is a tuple object containing an argument
 *                              list passed from Python to a C function
 * @param kwds                  Dictionary of keywords
 * 
 * Returns the size of set.
 * In case of error,appropriate exceptions will be raised.
 ********************************************************************************************************
 */
PyObject * AerospikeLSet_Size(AerospikeLSet * self, PyObject * args, PyObject * kwds)
{
	long size = 0;
	PyObject* py_policy = NULL;
	as_policy_apply apply_policy;
	as_policy_apply* apply_policy_p = NULL;

	as_error err;
	as_error_init(&err);

	static char * kwlist[] = {"policy", NULL};

	// Python Function Argument Parsing
	if ( PyArg_ParseTupleAndKeywords(args, kwds, "|O:size", kwlist, 
				&py_policy) == false ) {
		return NULL;
	}

	if (!self || !self->client->as) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object");
		goto CLEANUP;
	}
	if (!self->client->is_conn_16) {
		as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster");
		goto CLEANUP;
	}

	// Convert python policy object to as_policy_apply
	pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p,
			&self->client->as->config.policies.apply);
	if ( err.code != AEROSPIKE_OK ) {
		goto CLEANUP;
	}

	aerospike_lset_size(self->client->as, &err, apply_policy_p, &self->key,
			&self->lset, (uint32_t *)&size);
	if(err.code != AEROSPIKE_OK) {
		as_error_update(&err, err.code, NULL);
	}

CLEANUP:

	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL, *py_key = NULL;
		PyObject *exception_type = raise_exception(&err);
		error_to_pyobject(&err, &py_err);
		if(PyObject_HasAttrString(exception_type, "key")) {
			key_to_pyobject(&err, &self->key, &py_key);
			PyObject_SetAttrString(exception_type, "key", py_key);
			Py_DECREF(py_key);
		} 
		if(PyObject_HasAttrString(exception_type, "bin")) {
			PyObject *py_bins = PyString_FromString((char *)&self->bin_name);
			PyObject_SetAttrString(exception_type, "bin", py_bins);
			Py_DECREF(py_bins);
		}
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}
	return PyLong_FromLong(size);
}