Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (71 sloc) 2.854 kb
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
1 node.js memcached client
2 ========================
3
3e7d6e2 @iamcal consistent casing
iamcal authored
4 A pure-JavaScript memcached library for node.
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
5
6
47ea96a @iamcal added test instructions to the readme
iamcal authored
7 Tests
8 -----
9
3a68086 @iamcal more readme action
iamcal authored
10 To run the test suite, first insall <a href="http://github.com/visionmedia/expresso">expresso</a>,
11 then run <code>make test</code>.
12
13 If you have <a href="http://github.com/visionmedia/node-jscoverage">node-jscoverage</a> you can
14 also <code>make test-cov</code> for coverage, but that's pretty nerdy.
47ea96a @iamcal added test instructions to the readme
iamcal authored
15
16
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
17 Usage
18 -----
19
20 Create a Client object to start working.
21 Host and port can be passed to the constructor or set afterwards.
22 They have sensible defaults.
23
24 var memcache = require('./memcache');
25
26 var client = new memcache.Client(port, host);
27 client.port = 11211;
4842c6e @elbart fixed some typos
elbart authored
28 client.host = 'localhost';
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
29
30 The Client object emits 4 important events - connect, close, timeout and error.
31
32 client.on('connect', function(){
33 // no arguments - we've connected
34 });
35
36 client.on('close', function(){
37 // no arguments - connection has been closed
38 });
39
40 client.on('timeout', function(){
41 // no arguments - socket timed out
42 });
43
4842c6e @elbart fixed some typos
elbart authored
44 client.on('error', function(e){
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
45 // there was an error - exception is 1st argument
46 });
47
48 After connecting, you can start to make requests.
49
ac76422 @iamcal implemented all of the store operations. updated the readme docs
iamcal authored
50 client.get('key', function(result, error){
51
52 // all of the callbacks have two arguments.
53 // 'result' may contain things which aren't great, but
54 // aren't really errors, like 'NOT_STORED'
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
55
ac76422 @iamcal implemented all of the store operations. updated the readme docs
iamcal authored
56 });
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
57
e063e8c @iamcal readme fixes
iamcal authored
58 client.set('key', 'value', function(result, error){
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
59
ac76422 @iamcal implemented all of the store operations. updated the readme docs
iamcal authored
60 // lifetime is optional. the default is
61 // to never expire (0)
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
62
63 }, lifetime);
64
e063e8c @iamcal readme fixes
iamcal authored
65 client.delete('key', function(result, error){
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
66
67 // delete a key from cache.
68 });
69
e063e8c @iamcal readme fixes
iamcal authored
70 client.version(function(result, error)){
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
71
47acb60 @iamcal some readme updates
iamcal authored
72 // grab the server version
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
73 });
74
ac76422 @iamcal implemented all of the store operations. updated the readme docs
iamcal authored
75
3a68086 @iamcal more readme action
iamcal authored
76 There are all the commands you would expect.
77
ac76422 @iamcal implemented all of the store operations. updated the readme docs
iamcal authored
78 // all of the different "store" operations
79 // (lifetime & flags are both optional)
80 client.set(key, value, callback, lifetime, flags);
81 client.add(key, value, callback, lifetime, flags);
82 client.replace(key, value, callback, lifetime, flags);
83 client.append(key, value, callback, lifetime, flags);
84 client.prepend(key, value, callback, lifetime, flags);
85 client.cas(key, value, unique, callback, lifetime, flags);
86
3a68086 @iamcal more readme action
iamcal authored
87 // increment and decrement (named differently to the server commands - for now!)
ac76422 @iamcal implemented all of the store operations. updated the readme docs
iamcal authored
88 // (value is optional, defaults to 1)
89 client.increment('key', value, callback);
90 client.decrement('key', value, callback);
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
91
53e5a7c @iamcal added support for 'stats' operations
iamcal authored
92 // statistics. the success argument to the callback
93 // is a key=>value object
94 client.stats(callback);
95 client.stats('settings', callback);
96 client.stats('items', callback);
97 client.stats('mongeese', callback);
98
cd26b8b @iamcal moving the readme to use markdown. added a bunch of docs. still a work i...
iamcal authored
99 Once you're done, close the connection.
100
101 client.close();
102
3a68086 @iamcal more readme action
iamcal authored
103 There might be bugs. I'd like to know about them.
e063e8c @iamcal readme fixes
iamcal authored
104
3e7d6e2 @iamcal consistent casing
iamcal authored
105 I bet you also want to read the <a href="http://github.com/memcached/memcached/blob/master/doc/protocol.txt">memcached
e063e8c @iamcal readme fixes
iamcal authored
106 protocol doc</a>. It's exciting! It also explains possible error messages.
Something went wrong with that request. Please try again.