[node. js] Operations Redis

Source: Internet
Author: User

Summary

In the actual development, it is unavoidable to operate Mysql,mongodb,redis and other data storage servers. Here's a quick introduction to how to operate Redis.

An example

The installation of Redis server is no longer introduced here, the focus is not here. Interested can be installed on their own.

For a new module, we need to install the Redis module in our project before it can be used.

Command

CNPM Install Redis

Create a new Redis.js file with the following code:

//Introducing RedisvarRedis = require ("Redis");//Create a Redis clientvarClient = Redis.createclient ("6379", "127.0.0.1");//Connection error HandlingClient.on ("Error",function(Error) {Console.log (error);});//Redis Authentication (This configuration may not be written if Redis does not have authentication enabled)Client.auth ("123456");//FindClient.select ("15",function(Error) {if(Error) {Console.log (error); } Else{Client.set ("Node_redis_key", Json.stringify ({"Name": "Wolfy", age:28}),function(Error, res) {if(Error) {Console.log (error); } Else{console.log (res);            }; //operation complete, turn off Redis connectionClient.end (true);    }); };});

Inquire

Summarize

The operation of Redis here only lists the additions and queries, others can try it yourself, similar methods.

[node. js] Operations Redis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.