1
- var sys = require ( "sys" ) ;
2
1
var memc = require ( "../lib/client" ) ;
3
2
4
3
var client = new memc . Connection ( ) ;
@@ -7,7 +6,10 @@ client.parser.chunked = false;
7
6
client . parser . encoding = memc . constants . encodings . UTF8 ;
8
7
9
8
var key = "node-memcached-test" ;
10
- var value = "hello" ;
9
+ var value = "12345" ;
10
+
11
+ var port = process . argv [ 2 ] || 11211 ;
12
+ var host = process . argv [ 3 ] || "127.0.0.1" ;
11
13
12
14
/*
13
15
{"method": "connect", "params":"port, host, cb"}
@@ -40,59 +42,53 @@ var value = "hello";
40
42
{"method": "flushq", "params":"expiration, cb"}
41
43
*/
42
44
43
- client . connect ( "/tmp/memcached.sock" , null , function ( ) {
44
- sys . puts ( "connected" ) ;
45
+ client . connect ( port , host , function ( ) {
46
+ console . log ( "connected" ) ;
45
47
client . flush ( null , function ( message ) {
46
- sys . puts ( "FLUSH: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
48
+ console . log ( "FLUSH: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
47
49
} ) ;
48
50
client . version ( function ( message ) {
49
- sys . puts ( "VERSION: " + message . body ) ;
51
+ console . log ( "VERSION: " + message . body ) ;
50
52
} ) ;
51
53
client . noop ( function ( message ) {
52
- sys . puts ( "NOOP: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
54
+ console . log ( "NOOP: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
53
55
} ) ;
54
56
client . set ( key , value , 0x01 , 3600 , function ( message ) {
55
57
if ( message . header . status == memc . constants . status . NO_ERROR ) {
56
- sys . puts ( "SET: OK" ) ;
57
- client . getq ( key , function ( message ) {
58
- sys . puts ( "GETQ: " + message . body ) ;
59
- } ) ;
60
- client . getkq ( key , function ( message ) {
61
- sys . puts ( "GETKQ: " + message . body ) ;
62
- } ) ;
63
- client . getk ( key , function ( message ) {
64
- sys . puts ( "GETK: " + message . body ) ;
65
- } ) ;
58
+ console . log ( "SET: OK" ) ;
66
59
client . get ( key , function ( message ) {
67
- sys . puts ( "GET: " + message . body ) ;
60
+ console . log ( "GET: " + message . body ) ;
68
61
var stat = { } ;
69
62
client . stat ( null , function ( message ) {
70
63
if ( message . header . bodylen > 0 ) {
71
64
stat [ message . key ] = message . body ;
72
65
}
73
66
else {
74
- sys . puts ( "STAT:\n" + JSON . stringify ( stat , null , "\t" ) ) ;
67
+ console . log ( "STAT:\n" + JSON . stringify ( stat , null , "\t" ) ) ;
75
68
client . delete ( key , function ( message ) {
76
- sys . puts ( "DELETE: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
69
+ console . log ( "DELETE: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
77
70
client . quit ( function ( message ) {
78
- sys . puts ( "QUIT: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
71
+ console . log ( "QUIT: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
79
72
} ) ;
80
73
} ) ;
81
74
}
82
75
} ) ;
83
76
} ) ;
84
77
}
85
78
else {
86
- sys . puts ( "SET: Error = " + message . header . status ) ;
79
+ console . log ( "SET: Error = " + message . header . status ) ;
80
+ client . quit ( function ( message ) {
81
+ console . log ( "QUIT: " + ( message . header . status == memc . constants . status . NO_ERROR ?"OK" :"FAIL" ) ) ;
82
+ } ) ;
87
83
}
88
84
} ) ;
89
85
} ) ;
90
86
91
87
client . on ( "error" , function ( err ) {
92
- sys . puts ( "client error\n" + JSON . stringify ( err , null , "\t" ) ) ;
88
+ console . log ( "client error\n" + JSON . stringify ( err , null , "\t" ) ) ;
93
89
} ) ;
94
90
95
91
client . on ( "close" , function ( ) {
96
- sys . puts ( "client closed" ) ;
92
+ console . log ( "client closed" ) ;
97
93
} ) ;
98
94
0 commit comments