NCached is a Memcached-compatible server written in node.js
Install globally using npm:
npm i -g ncached
Start the server from the command line:
ncached
Flag | Description | Default value |
---|---|---|
-p | Port where the server will listen for new clients | 11212 |
-l | Logger level. Available options: error , info , verbose , debug |
info |
Retrieval commands:
- get
- gets
Storage commands:
- set
- add
- replace
- append
- prepend
- cas
To learn more about how memcached commands work, have a look at this guide
Connect to an NCached server via telnet:
telnet <server_ip> <server_port>
You can store and retrieve data just as with a normal memcached server:
set foo 0 20 3
bar
And then:
get foo
Will return:
VALUE foo 0 3
bar
END
Using memcached library:
const Memcached = require('memcached')
const memcached = new Memcached('localhost:11212')
memcached.set('foo', 'bar', 20, (err) => {
// you can use 'gets' command to retrieve the cas_token
memcached.gets('foo', (err, data) => {
// change value with 'cas' command
memcached.cas('foo', 'redis', data.cas, 20, err => { /* stuff */ })
})
})
Go to installation folder and run:
npm run test