• redis


    var redis = require('redis'),
    RDS_PORT = 6379, //端口号
    RDS_HOST = '192.168.1.125', //服务器IP
    RDS_OPTS = {}; //设置项
    var client = redis.createClient(RDS_PORT,RDS_HOST,RDS_OPTS);
    client.on("error", function(err){
    console.log("Error: " + err);
    });
    client.on('ready',function(res){
    console.log('ready');
    });
    client.on("connect", function(){
    //key,value
    client.set("name_key", "hello world", function(err, reply){
    console.log(reply.toString());
    });
    client.get("name_key", function(err, reply){
    console.log(reply.toString());
    });


    //json 自动转成json
    //client.hmset(["key", "test keys 1", "test val 1", "test keys 2", "test val 2"], function (err, res) {});
    //client.hmset("key", ["test keys 1", "test val 1", "test keys 2", "test val 2"], function (err, res) {});
    //client.hmset("key", "test keys 1", "test val 1", "test keys 2", "test val 2", function (err, res) {});
    client.hmset('sessionid', { username: 'kris', password: 'password' }, function(err) {
    console.log(err)
    })
    client.hgetall('sessionid', function(err, object) {
    console.log(object)
    })
    client.keys('session*', function (err, keys) {
    console.log(keys);
    })

    //[]
    client.hset("hash key", "hashtest 1","");
    client.hset(["hash key", "hashtest 2",""]);
    client.hkeys("hash key", function (err, replies) {
    console.log(replies);
    })
    client.incr('uid');
    client.get("uid", function(err, reply){
    console.log(reply);
    });
    client.get('uid',function(err,uid){
    //建立索引集合,username--id
    var username="rjy";
    var password="rjy";
    client.set('username:'+username,uid);
    client.hmset("user:"+uid,'username',username,'password',password,function(err){
    if(err){
    return 0;
    }
    else{
    return 1;
    }
    });
    });

    client.keys('*', function (err, keys) {
    console.log(keys);
    })
    /*

    username:zhou=>1
    user:1=>{username='zhou',password='123'}


    client.get('username:'+username,function(err,uid){
    if(err){
    return callback(err);
    }
    client.hget('user:'+uid,'password',function(err,pass){
    client.get("uid", function(err, reply){
    console.log(reply);
    });
    console.log("--AA--");
    */
    //
    //handle_regist("rjy","rjy");
    // client.incr('uid');

    })
    /*
    exports.handle_regist = function(username,password){
    client.incr('uid');
    client.get('uid',function(err,uid){
    //建立索引集合,username--id
    client.set('username:'+username,uid);
    client.hmset("user:"+uid,'username',username,'password',password,function(err){
    if(err){
    return 0;
    }
    else{
    return 1;
    }
    });
    });
    };*/

  • 相关阅读:
    兄弟连,一般人来不起,来的肯定不是一般人!
    50天之脱变,66期第一个项目感受。切记平常心
    2016十大影响事件
    为什么要写年终总结
    20161228阅读笔记
    为什么要认识牛人
    李笑来:演讲能力是我这一生有幸学到的最重要能力
    张辉:工作几年就应该给自己“清零”
    小马宋:目标决定方法~坚持目标而不是方法
    李笑来的财务自由法~把一份时间卖出很多份
  • 原文地址:https://www.cnblogs.com/jayruan/p/5165090.html
Copyright © 2020-2023  润新知