Example #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);
}
Example #2
0
static mrb_value mrb_vedis_close(mrb_state *mrb, mrb_value self)
{
    int ret;
    vedis *vstore = DATA_PTR(self);

    ret = vedis_close(vstore);
    if (ret != VEDIS_OK) {
        mrb_vedis_error(mrb, vstore, 0);
    }

    return self;
}
Example #3
0
static void php_vedis_store_destroy(php_vedis_t *vedis)
{
    vedis_close(vedis->store);
    pefree(vedis, vedis->is_persistent);
}
Example #4
0
static void mrb_vedis_ctx_free(mrb_state *mrb, void *p)
{
    vedis_close(p);
}
Example #5
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;
}