3 static memcached_return
memcached_auto(memcached_st
*ptr
,
5 char *key
, size_t key_length
,
11 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
12 unsigned int server_key
;
15 return MEMCACHED_NO_KEY_PROVIDED
;
17 if (ptr
->hosts
== NULL
|| ptr
->number_of_hosts
== 0)
18 return MEMCACHED_NO_SERVERS
;
20 server_key
= memcached_generate_hash(ptr
, key
, key_length
);
22 send_length
= snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
23 "%s %.*s %u\r\n", verb
,
26 if (send_length
>= MEMCACHED_DEFAULT_COMMAND_SIZE
)
27 return MEMCACHED_WRITE_FAILURE
;
29 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, send_length
, 1);
30 if (rc
!= MEMCACHED_SUCCESS
)
33 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
36 So why recheck responce? Because the protocol is brain dead :)
37 The number returned might end up equaling one of the string
38 values. Less chance of a mistake with strncmp() so we will
39 use it. We still called memcached_response() though since it
40 worked its magic for non-blocking IO.
42 if (!strncmp(buffer
, "ERROR\r\n", 7))
45 rc
= MEMCACHED_PROTOCOL_ERROR
;
47 else if (!strncmp(buffer
, "NOT_FOUND\r\n", 11))
50 rc
= MEMCACHED_NOTFOUND
;
54 *value
= (uint64_t)strtoll(buffer
, (char **)NULL
, 10);
55 rc
= MEMCACHED_SUCCESS
;
61 memcached_return
memcached_increment(memcached_st
*ptr
,
62 char *key
, size_t key_length
,
68 LIBMEMCACHED_MEMCACHED_INCREMENT_START();
69 rc
= memcached_auto(ptr
, "incr", key
, key_length
, offset
, value
);
70 LIBMEMCACHED_MEMCACHED_INCREMENT_END();
75 memcached_return
memcached_decrement(memcached_st
*ptr
,
76 char *key
, size_t key_length
,
82 LIBMEMCACHED_MEMCACHED_DECREMENT_START();
83 rc
= memcached_auto(ptr
, "decr", key
, key_length
, offset
, value
);
84 LIBMEMCACHED_MEMCACHED_DECREMENT_END();