示例#1
0
bool asc_read(aerospike *p_as, char *ns, char *file, char *buf, uint32_t size)
{
    // Prepare the key
    as_key key;
    as_key_init_str(&key, ns, SET, file);

    return asc_raw_read(p_as, &key, (uint8_t *)buf, size);
}
示例#2
0
/*
 * call-seq:
 *   new(namespace, set, value) -> AerospikeNative::Key
 *   new(namespace, set, value, digest) -> AerospikeNative::Key
 *
 * initialize new key
 */
VALUE key_initialize(int argc, VALUE* vArgs, VALUE vSelf)
{
    VALUE vNamespace, vSet, vValue, vDigest = Qnil;
    as_key *ptr;
    as_digest* digest = NULL;

    if (argc > 4 || argc < 3) {  // there should only be 3 or 4 arguments
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 3..4)", argc);
    }

    vNamespace = vArgs[0];
    Check_Type(vNamespace, T_STRING);

    vSet = vArgs[1];
    Check_Type(vSet, T_STRING);

    vValue = vArgs[2];

    if (argc == 4) {
        vDigest = vArgs[3];
    }

    Data_Get_Struct(vSelf, as_key, ptr);

    if(TYPE(vValue) != T_NIL) {
        switch(TYPE(vValue)) {
        case T_FIXNUM:
            as_key_init_int64(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), FIX2LONG( vValue ));
            break;
        case T_STRING:
            as_key_init_str(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValueCStr( vValue ));
            break;
        default: {
            VALUE vBytes = rb_funcall(vValue, rb_intern("to_msgpack"), 0);
            as_key_init_raw(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValuePtr(vBytes), RSTRING_LEN(vBytes));
        }
        }
    } else {
        Check_Type(vValue, T_NIL);
        Check_Type(vDigest, T_STRING);
        as_key_init_digest(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValuePtr( vDigest ));
    }

    if (digest == NULL) {
        digest = as_key_digest(ptr);
    }

    rb_iv_set(vSelf, "@namespace", vNamespace);
    rb_iv_set(vSelf, "@set", vSet);
    rb_iv_set(vSelf, "@value", vValue);
    rb_iv_set(vSelf, "@digest", rb_str_new( digest->value, AS_DIGEST_VALUE_SIZE));

    return vSelf;
}
示例#3
0
bool asc_size(aerospike *p_as, char *ns, char *file, uint32_t *size)
{
    as_status status;
    as_error err;

    // Prepare the key
    as_key key;
    as_key_init_str(&key, ns, SET, file);

    // Read metadata
    as_record *rec = NULL;
    status = aerospike_key_get(p_as, &err, NULL, &key, &rec);
    if (status != AEROSPIKE_OK) {
        ERROR("aerospike_key_get() returned %d - %s", err.code, err.message);
        return false;
    }
    *size = as_record_get_int64(rec, "size", 0);
    as_record_destroy(rec);

    return true;
}
//------------------------------------------------
// Parse command line options.
//
bool
example_get_opts(int argc, char* argv[], int which_opts)
{
	strcpy(g_host, DEFAULT_HOST);
	g_port = DEFAULT_PORT;
	strcpy(g_namespace, DEFAULT_NAMESPACE);
	strcpy(g_set, DEFAULT_SET);
	strcpy(g_key_str, DEFAULT_KEY_STR);
	g_n_keys = DEFAULT_NUM_KEYS;
	
	const char* short_options;
	struct option* long_options;
	
	if (which_opts) {
		short_options = short_options_multikey;
		long_options = long_options_multikey;
	}
	else  {
		short_options = short_options_basic;
		long_options = long_options_basic;
	}
	
	int option_index = 0;
	int c;
	
	while ((c = getopt_long(argc, argv, short_options, long_options, &option_index)) != -1) {
		switch (c) {
		case 'h':
			if (strlen(optarg) >= sizeof(g_host)) {
				LOG("ERROR: host exceeds max length");
				return false;
			}
			strcpy(g_host, optarg);
			break;

		case 'p':
			g_port = atoi(optarg);
			break;

		case 'U':
			strcpy(g_user, optarg);
			break;
			
		case 'P':
			as_password_prompt_hash(optarg, g_password);
			break;
				
		case 'n':
			if (strlen(optarg) >= sizeof(g_namespace)) {
				LOG("ERROR: namespace exceeds max length");
				return false;
			}
			strcpy(g_namespace, optarg);
			break;

		case 's':
			if (strlen(optarg) >= sizeof(g_set)) {
				LOG("ERROR: set name exceeds max length");
				return false;
			}
			strcpy(g_set, optarg);
			break;

		case 'k':
			if (strlen(optarg) >= sizeof(g_key_str)) {
				LOG("ERROR: key string exceeds max length");
				return false;
			}
			strcpy(g_key_str, optarg);
			break;

		case 'K':
			g_n_keys = atoi(optarg);
			break;

		default:
			usage(short_options);
			return false;
		}
	}

	if (strchr(short_options, 'h')) {
		LOG("host:           %s", g_host);
	}

	if (strchr(short_options, 'p')) {
		LOG("port:           %d", g_port);
	}

	if (strchr(short_options, 'U')) {
		LOG("user:           %s", g_user);
	}

	if (strchr(short_options, 'n')) {
		LOG("namespace:      %s", g_namespace);
	}

	if (strchr(short_options, 's')) {
		LOG("set name:       %s", g_set);
	}

	if (strchr(short_options, 'k')) {
		LOG("key (string):   %s", g_key_str);
	}

	if (strchr(short_options, 'K')) {
		LOG("number of keys: %u", g_n_keys);
	}

	// Initialize the test as_key object. We won't need to destroy it since it
	// isn't being created on the heap or with an external as_key_value.
	as_key_init_str(&g_key, g_namespace, g_set, g_key_str);

	return true;
}
示例#5
0
/**
 *	Initialize a stack allocated `as_key` to a NULL-terminated string value.
 */
as_key * as_key_init(as_key * key, const as_namespace ns, const as_set set, const char * value)
{
	return as_key_init_str(key, ns, set, value);
}
//------------------------------------------------
// Parse command line options.
//
bool
example_get_opts(int argc, char* argv[], const char* which_opts)
{
	strcpy(g_host, DEFAULT_HOST);
	g_port = DEFAULT_PORT;
	strcpy(g_namespace, DEFAULT_NAMESPACE);
	strcpy(g_set, DEFAULT_SET);
	strcpy(g_key_str, DEFAULT_KEY_STR);
	g_n_keys = DEFAULT_NUM_KEYS;

	int c;

	while ((c = getopt(argc, argv, which_opts)) != -1) {
		switch (c) {
		case 'h':
			if (strlen(optarg) >= sizeof(g_host)) {
				LOG("ERROR: host exceeds max length");
				return false;
			}
			strcpy(g_host, optarg);
			break;

		case 'p':
			g_port = atoi(optarg);
			break;

		case 'n':
			if (strlen(optarg) >= sizeof(g_namespace)) {
				LOG("ERROR: namespace exceeds max length");
				return false;
			}
			strcpy(g_namespace, optarg);
			break;

		case 's':
			if (strlen(optarg) >= sizeof(g_set)) {
				LOG("ERROR: set name exceeds max length");
				return false;
			}
			strcpy(g_set, optarg);
			break;

		case 'k':
			if (strlen(optarg) >= sizeof(g_key_str)) {
				LOG("ERROR: key string exceeds max length");
				return false;
			}
			strcpy(g_key_str, optarg);
			break;

		case 'K':
			g_n_keys = atoi(optarg);
			break;

		default:
			usage(which_opts);
			return false;
		}
	}

	if (strchr(which_opts, 'h')) {
		LOG("host:           %s", g_host);
	}

	if (strchr(which_opts, 'p')) {
		LOG("port:           %d", g_port);
	}

	if (strchr(which_opts, 'n')) {
		LOG("namespace:      %s", g_namespace);
	}

	if (strchr(which_opts, 's')) {
		LOG("set name:       %s", g_set);
	}

	if (strchr(which_opts, 'k')) {
		LOG("key (string):   %s", g_key_str);
	}

	if (strchr(which_opts, 'K')) {
		LOG("number of keys: %u", g_n_keys);
	}

	// Initialize the test as_key object. We won't need to destroy it since it
	// isn't being created on the heap or with an external as_key_value.
	as_key_init_str(&g_key, g_namespace, g_set, g_key_str);

	return true;
}