Keep in mind that node.js is primarily used to build high-performance, highly scalable server and client applications, and it is geared toward "live Web".
The goal of Node.js is to provide an "easy way to build scalable Web servers", which is impacted by event machines from the Ruby language (events Machine) and the twisted framework from Python.
Redis is an open source, with the use of ANSI C language, support network, can be based on memory can also be persistent log-type, Key-value database, and provide a variety of language APIs. From March 15, 2010 onwards, Redis's development work is hosted by VMware.
1, install the Redis node.js Drive
Copy Code code as follows:
thinkpad:~/work$ mkdir Redis-node
thinkpad:~/work$ CD Redis-node
thinkpad:~/work/redis-node$ ls
thinkpad:~/work/redis-node$ NPM Install Redis
NPM HTTP GET Https://registry.npmjs.org/redis
The computer is stuck here, NPM remote server connection is very slow, how to do?
Consider using NPM's domestic mirror server.
There are three different ways:
1) using config command
Copy Code code as follows:
NPM Config Set Registry http://registry.cnpmjs.org
NPM Info underscore (if the above configuration is correct, this command will have a string response)
2) command line designation
Copy Code code as follows:
NPM--registry http://registry.cnpmjs.org Info underscore
3) Edit ~/.NPMRC to add the following:
Copy Code code as follows:
Registry = http://registry.cnpmjs.org
To perform the Redis-driven installation again:
Copy Code code as follows:
thinkpad:~/work/redis-node$ NPM Install Redis
NPM HTTP GET Http://registry.cnpmjs.org/redis
NPM http 304 Http://registry.cnpmjs.org/redis
redis@0.10.0 Node_modules/redis
Get!
2. Write test procedure
Copy Code code as follows:
Redis-test.js
var Redis = require ("Redis"),
Client = Redis.createclient (6379, "10.3.30.186");
Client.on ("Error", function (Err) {
Console.log ("Error:" + err);
});
Client.on ("Connect", function () {
Start server ();
Client.set ("Name_key", "Hello World", function (err, reply) {
Console.log (Reply.tostring ());
});
Client.get ("Name_key", function (err, reply) {
Console.log (Reply.tostring ());
});
})
3. Execution procedure
Copy Code code as follows:
thinkpad:~/work/redis-node$ node Redis-test.js
Ok
Hello World
Program Description: First connect the remote Redis server, and then write a key/value to Redis, and then read out the key value according to the key name.