tencent cloud

TencentDB for Tendis

Release Notes
Product Introduction
Overview
Strengths
Use Cases
Product Series
Performance
Command Compatibility
Regions and AZs
Relevant Concepts
Relevant Products
Purchase Guide
Billing Overview
Pricing
Payment Overdue Policy
Getting Started
Creating Tendis Instances
Connecting to Tendis Instances
iptables Forwarding
Operation Guide
Instance Connection Using Programming Languages
Instance Maintenance and Management
Monitoring Features
Configuring Security Groups
Disabling Commands
FAQs
General
Purchase
Connection and Login
Contact Us
Tendis Policy
Privacy Policy
Data Privacy and Security Agreement
Glossary

Node.js Connection Sample

PDF
Focus Mode
Font Size
Last updated: 2023-12-21 21:11:10
Preparations before running: Run the following command to install node-redis: npm install hiredis redis
Sample code:
var redis = require("redis");

/**Enter your Tendis instance private IP, port number, instance ID, and password in the following parameters*/
var host = "192.xx.xx.2",
port = "6379",
instanceid = "c53xx52f-55dc-4c22-a941-630xxx88",
pwd = "12as6zb";
// Connect to the Tendis instance
var client = redis.createClient(port, host, {detect_buffers: true});
// Connection error
client.on("error", function(error) {
console.log(error);
});
// Authenticate
client.auth(instanceid + ":" + pwd);

/**You can start manipulating the Tendis instance. */
// Set the key
client.set("redis", "tencent", function(err, reply){
if (err) {
console.log(err);
return;
}
console.log("set key redis " + reply.toString() + ", value is tencent");
});

// Get the key
client.get("redis", function (err, reply) {
if (err) {
console.log(err);
return;
}
console.log("get key redis is:" + reply.toString());
// End the program and close the client
client.end();
});
Execution results:


Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback