aab225388b2425900824984a32524dac15dad2ef
2 #include "memcached_io.h"
5 What happens if no servers exist?
7 char *memcached_get(memcached_st
*ptr
, char *key
, size_t key_length
,
10 memcached_return
*error
)
15 *error
= memcached_mget(ptr
, &key
, &key_length
, 1);
17 value
= memcached_fetch(ptr
, NULL
, NULL
,
18 value_length
, flags
, error
);
20 /* This is for historical reasons */
21 if (*error
== MEMCACHED_END
)
22 *error
= MEMCACHED_NOTFOUND
;
27 memcached_finish(ptr
);
32 memcached_return
memcached_mget(memcached_st
*ptr
,
33 char **keys
, size_t *key_length
,
34 unsigned int number_of_keys
)
37 memcached_return rc
= MEMCACHED_NOTFOUND
;
38 char *get_command
= "get ";
39 uint8_t get_command_length
= 4
41 LIBMEMCACHED_MEMCACHED_MGET_START();
42 ptr
->cursor_server
= 0;
44 if (number_of_keys
== 0)
45 return MEMCACHED_NOTFOUND
;
47 if (ptr
->number_of_hosts
== 0)
48 return MEMCACHED_NO_SERVERS
;
50 if (ptr
->flags
& MEM_SUPPORT_CAS
)
53 get_command_length
= 5;
56 memcached_finish(ptr
);
58 for (x
= 0; x
< number_of_keys
; x
++)
60 unsigned int server_key
;
62 server_key
= memcached_generate_hash(ptr
, keys
[x
], key_length
[x
]);
64 if (ptr
->hosts
[server_key
].cursor_active
== 0)
66 rc
= memcached_connect(ptr
, server_key
);
68 if ((memcached_io_write(ptr
, server_key
, get_command
, get_command_length
, 0)) == -1)
70 memcached_quit_server(ptr
, server_key
);
71 rc
= MEMCACHED_SOME_ERRORS
;
74 ptr
->hosts
[server_key
].cursor_active
= 1;
77 if ((memcached_io_write(ptr
, server_key
, keys
[x
], key_length
[x
], 0)) == -1)
79 ptr
->hosts
[server_key
].cursor_active
= 0;
80 memcached_quit_server(ptr
, server_key
);
81 rc
= MEMCACHED_SOME_ERRORS
;
85 if ((memcached_io_write(ptr
, server_key
, " ", 1, 0)) == -1)
87 ptr
->hosts
[server_key
].cursor_active
= 0;
88 memcached_quit_server(ptr
, server_key
);
89 rc
= MEMCACHED_SOME_ERRORS
;
95 Should we muddle on if some servers are dead?
97 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
99 if (ptr
->hosts
[x
].cursor_active
== 1)
101 /* We need to doo something about non-connnected hosts in the future */
102 if ((memcached_io_write(ptr
, x
, "\r\n", 2, 1)) == -1)
104 memcached_quit_server(ptr
, x
);
105 rc
= MEMCACHED_SOME_ERRORS
;
110 LIBMEMCACHED_MEMCACHED_MGET_END();