Skip to content

Commit 47f726d

Browse files
authored
add syntax highlights on README.md
1 parent 5e664c5 commit 47f726d

File tree

1 file changed

+83
-85
lines changed

1 file changed

+83
-85
lines changed

README.md

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -41,91 +41,89 @@ Raw data storage is presented to clients via the Key/Value store interfaces. Ved
4141

4242
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.
4343

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 */
104-
vedis_value *pEntry;
105-
puts("Array entries:");
106-
while((pEntry = vedis_array_next_elem(pResult)) != 0 ){
107-
const char *zEntry;
108-
/* Cast to string and output */
109-
zEntry = vedis_value_to_string(pEntry,0);
110-
/* Output */
111-
printf("\t%s\n",zEntry);
112-
}
113-
}
114-
115-
/* Extract hashtable data */
116-
vedis_exec(pStore,"HGET config pid",-1); /* 1024 */
117-
vedis_exec_result(pStore,&pResult);
118-
{
119-
int pid;
120-
/* Cast to integer */
121-
pid = vedis_value_to_int(pResult);
122-
/* Output */
123-
printf("pid ==> %d\n",pid); /* Should be 1024 */
124-
}
125-
/* Finally, auto-commit the transaction and close our datastore */
126-
vedis_close(pStore);
127-
128-
44+
```cpp
45+
vedis *pStore; /* Datastore handle */
46+
int rc;
47+
48+
/* Create our datastore */
49+
rc = vedis_open(&pStore,argc > 1 ? argv[1] /* On-disk DB */ : ":mem:"/* In-mem DB */);
50+
if( rc != VEDIS_OK ){ /* Seriously? */ return; }
51+
52+
/* Execute the simplest command */
53+
rc = vedis_exec(pStore,"SET test 'Hello World'",-1);
54+
if( rc != VEDIS_OK ){ /* Handle error */ }
55+
56+
/* Another simple command (Multiple set) */
57+
rc = vedis_exec(pStore,"MSET username james age 27 mail [email protected]",-1);
58+
if( rc != VEDIS_OK ){ /* Handle error */ }
59+
60+
/* A quite complex command (Multiple hash set) using foreign data */
61+
rc = vedis_exec_fmt(pStore,
62+
"HMSET config pid %d user %s os %s scm %s",
63+
1024 /* pid */,
64+
"dean", /* user */
65+
"FreeBSD", /* OS */
66+
"Git" /* SCM */
67+
);
68+
if( rc != VEDIS_OK ){ /* Handle error */ }
69+
70+
/* Fetch some data */
71+
rc = vedis_exec(pStore,"GET test",-1);
72+
if( rc != VEDIS_OK ){ /* Seriously? */ }
73+
74+
/* Extract the return value of the last executed command (i.e. 'GET test') " */
75+
vedis_exec_result(pStore,&pResult);
76+
{
77+
const char *zResponse;
78+
/* Cast the vedis object to a string */
79+
zResponse = vedis_value_to_string(pResult,0);
80+
/* Output */
81+
printf(" test ==> %s\n",zResponse); /* test ==> 'Hello world' */
82+
}
83+
84+
vedis_exec(pStore,"GET mail",-1);
85+
/* 'GET mail' return value */
86+
vedis_exec_result(pStore,&pResult);
87+
{
88+
const char *zResponse;
89+
/* Cast the vedis object to a string */
90+
zResponse = vedis_value_to_string(pResult,0);
91+
/* Output */
92+
printf(" mail ==> %s\n",zResponse); /* Should be '[email protected]' */
93+
}
94+
95+
/*
96+
* A command which return multiple value in array.
97+
*/
98+
vedis_exec(pStore,"MGET username age",-1); /* james 27*/
99+
vedis_exec_result(pStore,&pResult);
100+
101+
if( vedis_value_is_array(pResult) ){
102+
/* Iterate over the elements of the returned array */
103+
vedis_value *pEntry;
104+
puts("Array entries:");
105+
while((pEntry = vedis_array_next_elem(pResult)) != 0 ){
106+
const char *zEntry;
107+
/* Cast to string and output */
108+
zEntry = vedis_value_to_string(pEntry,0);
109+
/* Output */
110+
printf("\t%s\n",zEntry);
111+
}
112+
}
113+
114+
/* Extract hashtable data */
115+
vedis_exec(pStore,"HGET config pid",-1); /* 1024 */
116+
vedis_exec_result(pStore,&pResult);
117+
{
118+
int pid;
119+
/* Cast to integer */
120+
pid = vedis_value_to_int(pResult);
121+
/* Output */
122+
printf("pid ==> %d\n",pid); /* Should be 1024 */
123+
}
124+
/* Finally, auto-commit the transaction and close our datastore */
125+
vedis_close(pStore);
126+
```
129127
130128
* 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.
131129
* 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

Comments
 (0)