zoukankan      html  css  js  c++  java
  • Node.js与Sails~redis组件的使用

    有段时间没写关于NodeJs的文章了,今天也是为了解决高并发的问题,而想起了这个东西,IIS的站点在并发量达到200时有了一个瓶颈,于是想到了这个对高并发支持比较好的框架,nodeJs在我之前写出一些文章,主要为sails框架为主,介绍了一些使用方法,今天主要说下redis组件!

    项目:SailsMvc

    开发工具:webstorm

    语言:nodejs

    框架:sails

    包:redis

    主要介绍几个用法,为string,set,hash和list的使

    测试redis组件的代码

        index: function (req, res) {
    
            // redis 链接
            var redis   = require('redis');
            var client  = redis.createClient('6379', '127.0.0.1');
    
            // redis 链接错误
            client.on("error", function(error) {
                console.log(error);
            });
           //redis list使用
            client.lpush('ok', 'Hello World!', function(error, res) {
                if(error) {
                    console.log(error);
                } else {
                    console.log(res);
                }
    
            });
          
            // redis 验证 (reids.conf未开启验证,此项可不需要)
            client.auth("foobared");
    
            //选数据库,使用set结构
            client.select('0', function(error){
                if(error) {
                    console.log(error);
                } else {
                    // set
                    client.set('str_key_0', '0', function(error, res) {
                        if(error) {
                            console.log(error);
                        } else {
                            console.log(res);
                        }
    
                    });
                }
            });
           //使用hash结构
            client.hmset("nodejs","zzl01","OK", function(error, res) {
                if (error) {
                    console.log(error);
                } else {
                    console.log(res);
                }
    
            });
    
           //关闭连接
           client.end();
             
    
            return res.send("OK");
            //return res.view("view_name",data)//view_name参数为空表示用当前的action
        }

    我们对知识的总结,有时候很重点!

    所以,请将你所学的东西总结起来,分享起来吧!

  • 相关阅读:
    Css预编语言以及区别
    CSS完成视差滚动效果
    理解ASP.NET Core验证模型 Claim, ClaimsIdentity, ClaimsPrincipal
    EF Expression 扩展
    总结 jion,group join 基于方法的查询与查询表达式 对比
    EF 查询表达式 join
    EF中 GroupJoin 与 Join
    css中“~”和“>”是什么意思
    jquery基于form-data文件上传
    针对 easyui boolean 布尔值 的处理
  • 原文地址:https://www.cnblogs.com/lori/p/6395649.html
Copyright © 2011-2022 走看看