ffb2c5f6203b1b6b63b30c0f86307bc2e770f2d5
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
)
12 return memcached_get_by_key(ptr
, NULL
, 0, key
, key_length
, value_length
,
16 char *memcached_get_by_key(memcached_st
*ptr
,
17 char *master_key
, size_t master_key_length
,
18 char *key
, size_t key_length
,
21 memcached_return
*error
)
26 *error
= memcached_mget_by_key(ptr
,
29 &key
, &key_length
, 1);
31 value
= memcached_fetch(ptr
, NULL
, NULL
,
32 value_length
, flags
, error
);
34 /* This is for historical reasons */
35 if (*error
== MEMCACHED_END
)
36 *error
= MEMCACHED_NOTFOUND
;
41 memcached_finish(ptr
);
46 memcached_return
memcached_mget(memcached_st
*ptr
,
47 char **keys
, size_t *key_length
,
48 unsigned int number_of_keys
)
50 return memcached_mget_by_key(ptr
, NULL
, 0, keys
, key_length
, number_of_keys
);
53 memcached_return
memcached_mget_by_key(memcached_st
*ptr
,
54 char *master_key
, size_t master_key_length
,
55 char **keys
, size_t *key_length
,
56 unsigned int number_of_keys
)
59 memcached_return rc
= MEMCACHED_NOTFOUND
;
60 char *get_command
= "get ";
61 uint8_t get_command_length
= 4;
62 unsigned int master_server_key
= 0;
64 LIBMEMCACHED_MEMCACHED_MGET_START();
65 ptr
->cursor_server
= 0;
67 if (number_of_keys
== 0)
68 return MEMCACHED_NOTFOUND
;
70 if (ptr
->number_of_hosts
== 0)
71 return MEMCACHED_NO_SERVERS
;
73 if (ptr
->flags
& MEM_SUPPORT_CAS
)
76 get_command_length
= 5;
79 memcached_finish(ptr
);
81 if (master_key
&& master_key_length
)
82 master_server_key
= memcached_generate_hash(ptr
, master_key
, master_key_length
);
85 If a server fails we warn about errors and start all over with sending keys
88 for (x
= 0; x
< number_of_keys
; x
++)
90 unsigned int server_key
;
92 if (master_server_key
)
93 server_key
= master_server_key
;
95 server_key
= memcached_generate_hash(ptr
, keys
[x
], key_length
[x
]);
97 if (ptr
->hosts
[server_key
].cursor_active
== 0)
99 rc
= memcached_connect(ptr
, server_key
);
101 if ((memcached_io_write(ptr
, server_key
, get_command
, get_command_length
, 0)) == -1)
103 rc
= MEMCACHED_SOME_ERRORS
;
106 ptr
->hosts
[server_key
].cursor_active
++;
109 if ((memcached_io_write(ptr
, server_key
, keys
[x
], key_length
[x
], 0)) == -1)
111 ptr
->hosts
[server_key
].cursor_active
= 0;
112 rc
= MEMCACHED_SOME_ERRORS
;
116 if ((memcached_io_write(ptr
, server_key
, " ", 1, 0)) == -1)
118 ptr
->hosts
[server_key
].cursor_active
= 0;
119 rc
= MEMCACHED_SOME_ERRORS
;
125 Should we muddle on if some servers are dead?
127 for (x
= 0; x
< ptr
->number_of_hosts
; x
++)
129 if (ptr
->hosts
[x
].cursor_active
)
131 /* We need to doo something about non-connnected hosts in the future */
132 if ((memcached_io_write(ptr
, x
, "\r\n", 2, 1)) == -1)
134 rc
= MEMCACHED_SOME_ERRORS
;
136 memcached_server_response_increment(ptr
, x
);
140 LIBMEMCACHED_MEMCACHED_MGET_END();