示例#1
0
void
ctteststrings(void)
{
  int rc;
  const char *str;
  vedis *store = NULL;
  vedis_value *res = NULL;

  rc = vedis_open(&store, NULL /* in memory */);
  assert(rc == VEDIS_OK);

  EXEC_CMD("GET misc");
  assert(vedis_value_is_null(res));

  EXEC_CMD("SET misc smthg");
  assert(vedis_value_is_bool(res));
  assert(vedis_value_to_bool(res));

  EXEC_CMD("GET misc");
  assert(vedis_value_is_string(res));
  assert(str = vedis_value_to_string(res, NULL));
  assert(!strcmp(str, "smthg"));

  vedis_close(store);
}
示例#2
0
static mrb_value mrb_vedis_open(mrb_state *mrb, mrb_value self)
{
    int ret, argc;
    vedis *vstore;
    mrb_value db_file;

    vstore = (vedis *)DATA_PTR(self);
    if (vstore) {
        mrb_free(mrb, vstore);
    }
    DATA_TYPE(self) = &vedis_ctx_type;
    DATA_PTR(self) = NULL;

    argc = mrb_get_args(mrb, "|o", &db_file);
    ret = vedis_open(&vstore, argc == 0 ? ":mem:" : RSTRING_PTR(db_file));
    if (ret != VEDIS_OK) {
        mrb_vedis_error(mrb, 0, "Out of memory");
    }
    DATA_PTR(self) = vstore;

    return self;
}
示例#3
0
static php_vedis_t *
php_vedis_new(char *storage, int storage_len, zend_bool is_persistent TSRMLS_DC)
{
    php_vedis_t *vedis;
    char *filepath = NULL, *stragepath = NULL;

    vedis = pecalloc(1, sizeof(php_vedis_t), is_persistent);

    if (!storage || storage_len <= 0) {
        stragepath = NULL;
    } else if (strcmp(storage, ":mem:") != 0) {
        if (!(filepath = expand_filepath(storage, NULL TSRMLS_CC))) {
            pefree(vedis, is_persistent);
            return NULL;
        }
        stragepath = filepath;
    } else {
        stragepath = storage;
    }

    if (vedis_open(&(vedis->store), stragepath) != VEDIS_OK) {
        if (filepath) {
            efree(filepath);
        }
        pefree(vedis, is_persistent);
        return NULL;
    }

    if (filepath) {
        efree(filepath);
    }

    vedis->storage = storage;
    vedis->is_persistent = is_persistent;
    vedis->pid = getpid();

    return vedis;
}
示例#4
0
int main(int argc,char *argv[])
{
	vedis *pStore;                /* Database handle */
	char zKey[14];               /* Random generated key */
	char zData[32];              /* Dummy data */
	int i,rc;

	puts(zBanner);

	/* Open our datastore */
	rc = vedis_open(&pStore,argc > 1 ? argv[1] /* On-disk DB */ : ":mem:" /* In-mem DB */);
	if( rc != VEDIS_OK ){
		Fatal(0,"Out of memory");
	}
	
	printf("Starting insertions of %d random records...\n",MAX_RECORDS);
	
	/* Start the random insertions */
	for( i = 0 ; i < MAX_RECORDS; ++i ){
		
		/* Genearte the random key first */
		vedis_util_random_string(pStore,zKey,sizeof(zKey));

		/* Perform the insertion */
		rc = vedis_kv_store(pStore,zKey,sizeof(zKey),zData,sizeof(zData));
		if( rc != VEDIS_OK ){
			/* Something goes wrong */
			break;
		}

		if( i == 79125 ){
			/* Insert a sentinel record */

			/* time(&tt); pTm = localtime(&tt); ... */
			vedis_kv_store_fmt(pStore,"sentinel",-1,"I'm a sentinel record inserted on %d:%d:%d\n",14,15,18); /* Dummy time */
		}
	}
	
	/* If we are OK, then manually commit the transaction */
	if( rc == VEDIS_OK ){
		/* 
		 * In fact, a call to vedis_commit() is not necessary since Vedis
		 * will automatically commit the transaction during a call to vedis_close().
		 */
		rc = vedis_commit(pStore);
		if( rc != VEDIS_OK ){
			/* Rollback the transaction */
			rc = vedis_rollback(pStore);
		}
	}
	
	if( rc != VEDIS_OK ){
		/* Something goes wrong, extract the datastore error log and exit */
		Fatal(pStore,0);
	}
	puts("Done...Fetching the 'sentinel' record: ");

	/* Fetch the sentinel */
	rc = vedis_kv_fetch_callback(pStore,"sentinel",-1,DataConsumerCallback,0);
	if( rc != VEDIS_OK ){
		/* Can't happen */
		Fatal(0,"Sentinel record not found");
	}

	/* All done, close our datastore */
	vedis_close(pStore);
	return 0;
}