Skip to content

Instantly share code, notes, and snippets.

@qpfiffer
Created July 18, 2015 17:05
Show Gist options
  • Save qpfiffer/088ed2efd8df150029a9 to your computer and use it in GitHub Desktop.
Save qpfiffer/088ed2efd8df150029a9 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <olegdb/oleg.h>
/* Compile with:
* gcc -g3 -O2 basic.c -o test_basic -loleg
*/
int main(int argc, char *argv[]) {
const char *key = "mykey";
const int keylen = strlen(key);
ol_database *db = NULL;
const int features = OL_F_APPENDONLY | OL_F_LZ4 | OL_F_AOL_FFLUSH | OL_F_SPLAYTREE;
unsigned char *raw_data = NULL;
size_t dsize = 0;
db = ol_open("/tmp/test_oleg/", "test_oleg", features);
if (db == NULL)
return 1;
if (ol_exists(db, key, keylen)) {
printf("First run!\n");
int counter = 1;
if (ol_jar(db, key, keylen, (unsigned char *)&counter, sizeof(int)) != 0) {
ol_close(db);
return 1;
}
} else {
ol_unjar(db, key, keylen, &raw_data, &dsize);
printf("You already ran me %i times.\n", (int)*raw_data);
int *counter = (int *)raw_data;
*counter += 1;
if (ol_jar(db, key, keylen, (unsigned char *)counter, sizeof(int)) != 0) {
free(raw_data);
ol_close(db);
return 1;
}
free(raw_data);
}
ol_close(db);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment