1. 下载
https://github.com/tporadowski/redis/releases
2. 启动
点击安装地址里面的 redis-cli.exe
const redis = require('redis')
const client = redis.createClient(6379, '127.0.0.1')
client.on('ready', function (res) {
console.log('ready')
})
client.on('error', err => {
console.log(err, 'err')
})
client.set('str1', 'str1wewe', redis.print)
client.get('str1', function (err, reply) {
console.log(reply, 'reply')
})
// 用Hash存取对象
/* client.hmset("ikc",{
'itme': 'koadeom',
'id': 666
})
client.hgetall("ikc", function(err, reply){
console.log(reply,'reply');
}) */
// 用Hash存取对象
https://blog.csdn.net/weixin_36541072/article/details/53944653?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
npm install redis-connection-pool
const redis = require('redis')
let redisPool = require('redis-connection-pool')('myRedisPool', {
host: '127.0.0.1', // default
port: 6379, //default
max_clients: 30, // defalut
perform_checks: false, // checks for needed push/pop functionality
database: 0, // database number to use
options: {
auth_pass: 'password'
} //options for createClient of node-redis, optional
});
redisPool.set('test-key', 'foobar', function (err) {
redisPool.get('test-key', function (err, reply) {
console.log(reply); // 'foobar'
});
});