zoukankan      html  css  js  c++  java
  • 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;
    }
    });
    });
    };*/

  • 相关阅读:
    shell脚本编程
    Linux系统C语言开发环境学习
    Linux系统用户管理及VIM配置
    实验二 Linux系统简单文件操作命令
    实验一 Linux系统与应用准备
    DS01-线性表
    c博客作业 指针
    C博客06-2019-结构体&文件
    c语言博客作业04 数组
    c语言博客作业03 函数
  • 原文地址:https://www.cnblogs.com/jayruan/p/5165090.html
Copyright © 2011-2022 走看看