Updating server_st to keep client buffers per server.
[awesomized/libmemcached] / src / execute.c
1 /*
2 Execute a memcached_set() a set of pairs.
3 Return the number of rows set.
4 */
5
6 #include <stdio.h>
7 #include "execute.h"
8
9 unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
10 {
11 memcached_return rc;
12 unsigned int x;
13 unsigned int pairs_sent;
14
15 for (x= 0, pairs_sent= 0; x < number_of; x++)
16 {
17 rc= memcached_set(memc, pairs[x].key, pairs[x].key_length,
18 pairs[x].value, pairs[x].value_length,
19 0, 0);
20 if (rc != MEMCACHED_SUCCESS)
21 fprintf(stderr, "Failured on insert of %.*s\n",
22 (unsigned int)pairs[x].key_length, pairs[x].key);
23 else
24 pairs_sent++;
25 }
26
27 return pairs_sent;
28 }
29
30 /*
31 Execute a memcached_get() on a set of pairs.
32 Return the number of rows retrieved.
33 */
34 unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
35 {
36 memcached_return rc;
37 unsigned int x;
38 unsigned int retrieved;
39
40
41 for (retrieved= 0,x= 0; x < number_of; x++)
42 {
43 char *value;
44 size_t value_length;
45 uint16_t flags;
46 unsigned int fetch_key;
47
48 fetch_key= random() % number_of;
49
50 value= memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length,
51 &value_length, &flags, &rc);
52
53 if (rc != MEMCACHED_SUCCESS)
54 fprintf(stderr, "Failured on read of %.*s\n",
55 (unsigned int)pairs[fetch_key].key_length, pairs[fetch_key].key);
56 else
57 retrieved++;
58
59 free(value);
60 }
61
62 return retrieved;
63 }