You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-85Lines changed: 83 additions & 85 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,91 +41,89 @@ Raw data storage is presented to clients via the Key/Value store interfaces. Ved
41
41
42
42
Under the KV store, both keys and values are treated as simple arrays of bytes, so content can be anything from ASCII strings, binary blob and even disk files. The KV store layer is presented to clients via a set of interfaces, these includes: [vedis_kv_store()](http://vedis.symisc.net/c_api/vedis_kv_store.html), [vedis_kv_append()](http://vedis.symisc.net/c_api/vedis_kv_append.html), [vedis_kv_fetch_callback()](http://vedis.symisc.net/c_api/vedis_kv_fetch_callback.html), [vedis_kv_append_fmt()](http://vedis.symisc.net/c_api/vedis_kv_append.html), etc.
43
43
44
-
45
-
46
-
vedis *pStore; /* Datastore handle */
47
-
int rc;
48
-
49
-
/* Create our datastore */
50
-
rc = vedis_open(&pStore,argc > 1 ? argv[1] /* On-disk DB */ : ":mem:"/* In-mem DB */);
51
-
if( rc != VEDIS_OK ){ /* Seriously? */ return; }
52
-
53
-
/* Execute the simplest command */
54
-
rc = vedis_exec(pStore,"SET test 'Hello World'",-1);
55
-
if( rc != VEDIS_OK ){ /* Handle error */ }
56
-
57
-
/* Another simple command (Multiple set) */
58
-
rc = vedis_exec(pStore,"MSET username james age 27 mail [email protected]",-1);
59
-
if( rc != VEDIS_OK ){ /* Handle error */ }
60
-
61
-
/* A quite complex command (Multiple hash set) using foreign data */
62
-
rc = vedis_exec_fmt(pStore,
63
-
"HMSET config pid %d user %s os %s scm %s",
64
-
1024 /* pid */,
65
-
"dean", /* user */
66
-
"FreeBSD", /* OS */
67
-
"Git" /* SCM */
68
-
);
69
-
if( rc != VEDIS_OK ){ /* Handle error */ }
70
-
71
-
/* Fetch some data */
72
-
rc = vedis_exec(pStore,"GET test",-1);
73
-
if( rc != VEDIS_OK ){ /* Seriously? */ }
74
-
75
-
/* Extract the return value of the last executed command (i.e. 'GET test') " */
76
-
vedis_exec_result(pStore,&pResult);
77
-
{
78
-
const char *zResponse;
79
-
/* Cast the vedis object to a string */
80
-
zResponse = vedis_value_to_string(pResult,0);
81
-
/* Output */
82
-
printf(" test ==> %s\n",zResponse); /* test ==> 'Hello world' */
83
-
}
84
-
85
-
vedis_exec(pStore,"GET mail",-1);
86
-
/* 'GET mail' return value */
87
-
vedis_exec_result(pStore,&pResult);
88
-
{
89
-
const char *zResponse;
90
-
/* Cast the vedis object to a string */
91
-
zResponse = vedis_value_to_string(pResult,0);
92
-
/* Output */
93
-
printf(" mail ==> %s\n",zResponse); /* Should be '[email protected]' */
94
-
}
95
-
96
-
/*
97
-
* A command which return multiple value in array.
98
-
*/
99
-
vedis_exec(pStore,"MGET username age",-1); /* james 27*/
100
-
vedis_exec_result(pStore,&pResult);
101
-
102
-
if( vedis_value_is_array(pResult) ){
103
-
/* Iterate over the elements of the returned array */
/* Finally, auto-commit the transaction and close our datastore */
125
+
vedis_close(pStore);
126
+
```
129
127
130
128
* The datastore is created on line 5 using a call to [vedis_open()](http://vedis.symisc.net/c_api/vedis_open.html). This is often the first Vedis API call that an application makes and is a prerequisite in order to play with Vedis.
131
129
* As you can see, executing commands (ala Redis) under Vedis is pretty simple and involve only a single call to vedis_exec() or vedis_exec_fmt(). This is done on line 9, 13, 17, 45 on our example regardless how much the executed command is complex.
0 commit comments