Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Edited README.md via GitHub

  • Loading branch information...
commit 6f4e02275ea22b80071d7322e672ca9a31838c25 1 parent 5e78d40
Arnout Kazemier authored April 20, 2011

Showing 1 changed file with 53 additions and 40 deletions. Show diff stats Hide diff stats

  1. 93  README.md
93  README.md
Source Rendered
@@ -16,11 +16,12 @@ The client is configurable on different levels. There's a global configuration t
16 16
 ## Setting up the client
17 17
 
18 18
 The constructor of the nMemcached client take 2 different arguments `server locations` and `options`. Syntax:
19  
-
20  
-	var nMemcached = require('nMemcached');
21  
-	var memcached = new nMemcached(Server locations, options);
22  
-
  19
+``` js
  20
+var nMemcached = require('nMemcached');
  21
+var memcached = new nMemcached(Server locations, options);
  22
+```
23 23
 ### Server locations
  24
+
24 25
 The server locations is designed to work with different formats. These formats are all internally parsed to the correct format so our consistent hashing scheme can work with it. You can either use:
25 26
 
26 27
 1.	**String**, this only works if you have are running a single server instance of Memcached.
@@ -43,10 +44,11 @@ The server locations is designed to work with different formats. These formats a
43 44
 	distribution of the keys.
44 45
 
45 46
 If you would implement one of the above formats, your constructor would something like this:
46  
-
47  
-	var memcache = new nMemcached({ '192.168.0.102:11212': 1, '192.168.0.103:11212': 2, '192.168.0.104:11212': 1 });
48  
-	var memcache = new nMemcached([ '192.168.0.102:11212', '192.168.0.103:11212', '192.168.0.104:11212' ]);
49  
-	var memcache = new nMemcached('192.168.0.102:11212');
  47
+``` js
  48
+var memcache = new nMemcached({ '192.168.0.102:11212': 1, '192.168.0.103:11212': 2, '192.168.0.104:11212': 1 });
  49
+var memcache = new nMemcached([ '192.168.0.102:11212', '192.168.0.103:11212', '192.168.0.104:11212' ]);
  50
+var memcache = new nMemcached('192.168.0.102:11212');
  51
+```
50 52
 
51 53
 ### Options
52 54
 
@@ -67,14 +69,16 @@ There 2 kinds of options that can be configured. A global configuration that wil
67 69
 * `keyCompression`: *true*, compress keys using md5 if they exceed the maxKeySize option.
68 70
 
69 71
 Example usage:
70  
-
71  
-	var memcache = new nMemcached('localhost:11212', {retries:10,retry:10000,remove:true,failOverServers:['192.168.0.103:11212']});
  72
+``` js
  73
+var memcache = new nMemcached('localhost:11212', {retries:10,retry:10000,remove:true,failOverServers:['192.168.0.103:11212']});
  74
+```
72 75
 
73 76
 If you wish to configure the options globally:
74  
-
75  
-	var nMemcached = require( 'nMemcached' ).Client;
76  
-	// all global configurations should be applied to the .config object of the Client.
77  
-	nMemcached.config.poolSize = 25;
  77
+``` js
  78
+var nMemcached = require( 'nMemcached' ).Client;
  79
+// all global configurations should be applied to the .config object of the Client.
  80
+nMemcached.config.poolSize = 25;
  81
+```
78 82
 
79 83
 ## API
80 84
 
@@ -96,10 +100,12 @@ If there are issues with the server connection, we are going to respond with cac
96 100
 `callback`: *Function*, The callback function that receives the net.Stream connection. It will be called with 2 arguments `error` and `connection`.
97 101
 
98 102
 Example
99  
-	memcached.connect( '192.168.0.103:11212', function( err, conn ){
100  
-		if( err ) throw new Error( err );
101  
-		console.log( conn.server );
102  
-	});
  103
+``` js
  104
+memcached.connect( '192.168.0.103:11212', function( err, conn ){
  105
+	if( err ) throw new Error( err );
  106
+	console.log( conn.server );
  107
+});
  108
+```
103 109
 ---------------------------------------
104 110
 #### .multi
105 111
 A small wrapper function that makes it easier to query multiple Memcached servers. It will return the location for each key or the complete list of servers.
@@ -116,13 +122,15 @@ A small wrapper function that makes it easier to query multiple Memcached server
116 122
 4.	`total`: *Number*, The total amount server retrieved.
117 123
 
118 124
 Example
119  
-	memcached.multi( false, function( server, key, index, totals ){
120  
-		if( err ) throw new Error( err );
121  
-		
122  
-		this.connect( server, function( err, conn ){
123  
-			console.log( "connection ready" )
124  
-		})
125  
-	});
  125
+``` js
  126
+memcached.multi( false, function( server, key, index, totals ){
  127
+	if( err ) throw new Error( err );
  128
+	
  129
+	this.connect( server, function( err, conn ){
  130
+		console.log( "connection ready" )
  131
+	})
  132
+});
  133
+```
126 134
 ---------------------------------------
127 135
 #### .command
128 136
 
@@ -137,16 +145,18 @@ is written to the Memcached server.
137 145
 `server`: *String*, The server the to connect. This is only needed when the metaData object doesn't contain a key property to retrieve the server from. 
138 146
 
139 147
 Example
140  
-	memcached.command({
141  
-		key: 'key', callback: function(){ console.dir( arguments ); },
142  
-
143  
-		// validate the arguments
144  
-		validate: [[ 'key', String ], [ 'callback', Function ]],
145  
-
146  
-		// used for the query
147  
-		type: 'delete',
148  
-		command: 'delete key'
149  
-	});
  148
+``` js
  149
+memcached.command({
  150
+	key: 'key', callback: function(){ console.dir( arguments ); },
  151
+
  152
+	// validate the arguments
  153
+	validate: [[ 'key', String ], [ 'callback', Function ]],
  154
+
  155
+	// used for the query
  156
+	type: 'delete',
  157
+	command: 'delete key'
  158
+});
  159
+```
150 160
 ---------------------------------------
151 161
 #### .connectionIssue
152 162
 
@@ -162,7 +172,9 @@ all these cases. For example server could crash or the Memcached server could re
162 172
 `callback`: *Function* **(optional)**, The callback function of a potential request, it will be marked as cache miss if it was provided
163 173
 
164 174
 Example
165  
-	memcached.connectionIssue( "Server down", connectionReference );
  175
+``` js
  176
+memcached.connectionIssue( "Server down", connectionReference );
  177
+```
166 178
 ## Callbacks
167 179
 
168 180
 Each method requires a callback function. Once this function get executed there will be 2 variables applied:
@@ -216,7 +228,8 @@ There are `5` different events that the nMemcached client emits when connection
216 228
 * `remove`: removing the server from our consistent hashing.
217 229
 
218 230
 Example implementations:
219  
-
220  
-	var memcached = new nMemcached([ '192.168.0.102:11212', '192.168.0.103:11212' ]);
221  
-	memcached.on('failure', function( details ){ sys.error( "Server " + details.server + "went down due to: " + details.messages.join( '' ) ) });
222  
-	memcached.on('reconnecting', function( details ){ sys.debug( "Total downtime caused by server " + details.server + " :" + details.totalDownTime + "ms")})
  231
+``` js
  232
+var memcached = new nMemcached([ '192.168.0.102:11212', '192.168.0.103:11212' ]);
  233
+memcached.on('failure', function( details ){ sys.error( "Server " + details.server + "went down due to: " + details.messages.join( '' ) ) });
  234
+memcached.on('reconnecting', function( details ){ sys.debug( "Total downtime caused by server " + details.server + " :" + details.totalDownTime + "ms")});
  235
+```

0 notes on commit 6f4e022

Please sign in to comment.
Something went wrong with that request. Please try again.