> --
> You received this message because you are subscribed to the Google Groups "xmemcached" group.
> To post to this group, send email to xmemc...@googlegroups.com.
> To unsubscribe from this group, send email to xmemcached+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/xmemcached?hl=en.
>
I tried but it doesn't work i'm very frustrated. Attached there is the c++ sent thrad part(you can extract it and try) and the getter memcached
--
You received this message because you are subscribed to the Google Groups "xmemcached" group.
To post to this group, send email to xmemc...@googlegroups.com.
To unsubscribe from this group, send email to xmemcached+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xmemcached?hl=en.
thank you for help
> <test.zip>
the 3 and 6 are not get. any idea?
Java:
public class SimpleExample {
public static void main(String[] args) {
MemcachedClient memcachedClient = getMemcachedClient(null);
if (memcachedClient == null) {
throw new NullPointerException(
"Null MemcachedClient,please check memcached has been started");
}
try {
List<String> keys = new ArrayList<String>();
for (int i = 0; i < 8; i++) {
keys.add("key" +String.valueOf(i + 1));
}
System.out.println(memcachedClient.get(keys));
Map<String, byte[]> entryes = memcachedClient.get(keys);
Iterator<Entry<String, byte[]>> iter = entryes.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, byte[]> entry = (Entry<String, byte[]>) iter.next();
System.out.println(entry.getKey());
}
} catch (MemcachedException e) {
System.err.println("MemcachedClient operation fail");
e.printStackTrace();
} catch (TimeoutException e) {
System.err.println("MemcachedClient operation timeout");
e.printStackTrace();
} catch (InterruptedException e) {
// ignore
}
try {
memcachedClient.shutdown();
} catch (Exception e) {
System.err.println("Shutdown MemcachedClient fail");
e.printStackTrace();
}
}
public static MemcachedClient getMemcachedClient(String servers) {
try {
// use text protocol by default
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("stgdev1:12000 stgdev2:12001"));
builder.setSessionLocator(new LibmemcachedKetamaSessionLocator());
return builder.build();
} catch (IOException e) {
System.err.println("Create MemcachedClient fail");
e.printStackTrace();
}
return null;
}
}
and c:
#include <iostream>
#include <string>
#include <libmemcached/memcached.h>
using namespace std;
void set(memcached_st *memc,string key,string value)
{
memcached_return_t rc;
rc=memcached_set(memc,key.c_str(),key.length(),value.c_str(),value.length(),0,0);
if(rc!=MEMCACHED_SUCCESS)
cout << "Error: set key fail "<< memcached_strerror(memc,rc)<< endl;
}
int main(int argc,char *argv[])
{
//connect server
memcached_st *memc;
memcached_return_t rc;
memcached_server_st *server;
time_t expiration;
uint32_t flags;
memc = memcached_create(NULL);
server = memcached_server_list_append(NULL,"stgdev1",12000,&rc);
rc=memcached_server_push(memc,server);
memcached_server_list_free(server);
server = memcached_server_list_append(NULL,"stgdev2",12001,&rc);
rc=memcached_server_push(memc,server);
memcached_server_list_free(server);
memcached_behavior_set(memc,MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY);
string key = "key";
string value = "value";
size_t value_length = value.length();
size_t key_length = key.length();
//Save data
set(memc,"key1","value1");
set(memc,"key2","value2");
set(memc,"key3","value3");
set(memc,"key4","value4");
set(memc,"key5","value5");
set(memc,"key6","value6");
set(memc,"key7","value7");
set(memc,"key8","value8");
// //Get data
// char* result = memcached_get(memc,key.c_str(),key_length,&value_length,&flags,&rc);
// cout<<rc<<endl;
// if(rc == MEMCACHED_SUCCESS)
// {
// cout<<"Get value:"<<result<<" sucessful!"<<endl;
// }
// //Delete data
// rc=memcached_delete(memc,key.c_str(),key_length,0);
// if(rc==MEMCACHED_SUCCESS)
// {
// cout<<"Delete key:"<<key<<" sucessful!"<<endl;
// }
//free
memcached_free(memc);
return 0;
}
On 10/gen/2011, at 03.52, boyan wrote:
> <test.zip>
stgdev2:
[dbuser@stgdev2 ~]$ <36 server listening (auto-negotiate)
<37 server listening (auto-negotiate)
<38 send buffer was 129024, now 268435456
<39 send buffer was 129024, now 268435456
<38 server listening (udp)
<39 server listening (udp)
<38 server listening (udp)
<39 server listening (udp)
<38 server listening (udp)
<39 server listening (udp)
<38 server listening (udp)
<39 server listening (udp)
<40 new auto-negotiating client connection
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
40: Client using the ascii protocol
<40 set key4 0 0 6
40: going from conn_parse_cmd to conn_nread
> NOT FOUND key4
>40 STORED
40: going from conn_nread to conn_write
40: going from conn_write to conn_new_cmd
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
<40 set key6 0 0 6
40: going from conn_parse_cmd to conn_nread
> NOT FOUND key6
>40 STORED
40: going from conn_nread to conn_write
40: going from conn_write to conn_new_cmd
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
<40 set key7 0 0 6
40: going from conn_parse_cmd to conn_nread
> NOT FOUND key7
>40 STORED
40: going from conn_nread to conn_write
40: going from conn_write to conn_new_cmd
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
<40 set key8 0 0 6
40: going from conn_parse_cmd to conn_nread
> NOT FOUND key8
>40 STORED
40: going from conn_nread to conn_write
40: going from conn_write to conn_new_cmd
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
<40 quit
40: going from conn_parse_cmd to conn_closing
<40 connection closed.
<40 new auto-negotiating client connection
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
40: Client using the ascii protocol
<40 get key3 key4 key5 key7 key8
> NOT FOUND key3
> FOUND KEY key4
>40 sending key key4
> NOT FOUND key5
> FOUND KEY key7
>40 sending key key7
> FOUND KEY key8
>40 sending key key8
>40 END
40: going from conn_parse_cmd to conn_mwrite
40: going from conn_mwrite to conn_new_cmd
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
<40 get key3 key4 key5 key7 key8
> NOT FOUND key3
> FOUND KEY key4
>40 sending key key4
> NOT FOUND key5
> FOUND KEY key7
>40 sending key key7
> FOUND KEY key8
>40 sending key key8
>40 END
40: going from conn_parse_cmd to conn_mwrite
40: going from conn_mwrite to conn_new_cmd
40: going from conn_new_cmd to conn_waiting
40: going from conn_waiting to conn_read
40: going from conn_read to conn_parse_cmd
<40 quit
40: going from conn_parse_cmd to conn_closing
<40 connection closed.
--
You received this message because you are subscribed to the Google Groups "xmemcached" group.
To post to this group, send email to xmemc...@googlegroups.com.
To unsubscribe from this group, send email to xmemcached+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xmemcached?hl=en.
> <test.tar.gz>