redis是当前流行的nosql数据库,很多网站都用它来做缓存,今天我们来安装并配置下redis

二、安装并配置redis

1、安装redis

sudo apt-get install redis-server//安装redis

安装完可以执行redis-cli 启动命令行模式,并写入查看数据试下

2、配置redis

2.1 配置远程登录

默认redis是不允许远程登录的,需要我们配置

#编辑redis配置文件 sudo vim /etc/redis/redis.conf #注释下面这一行 我的是69行 可以搜索bind查找 #bind 127.0.0.1

修改完重启下redis,详见2.3重启redis。

接下来我们测试远程登录是否成功,远程登录需要执行登录的服务器已经安装了redis,我这是虚拟机Ubuntu,我本机window已经配置了redis

#启动window下的redis #进入cmd命令模式 注:redis-cli -h (ip 地址) -p (端口号 默认是6379) 注意参数要和具体指要空格隔开redis-cli 是需要添加环境变量的,下图是我系统添加的环境变量 

2.2配置密码登录

修改之后如果不用密码直接登录也是可以的不过不可以操作,提示需要认证

我们使用密码登录就可以正常操作了

2.3重启redis

我这边重启以及强制关闭再开启会报错


原因是我配置文件的第一行是无效的配置(/etc/redis/redis.conf line 1),我删除后重启就好了

三、安装php扩展

安装完之后重启下php,apacheh或者nginx等查看phpinfo 查看或者php -m|grep redis 查看扩展

Let’s start with a quick introduction to arrow functions. Before ES6, anytime we were using function expressions and wanted to refer this from outer context, we had to do some workarounds which are (arguably) a bit unnatural, especially comparing to other major programming languages.

Let’s do some pseudo-object-oriented programming with javascript (ES5) to illustrate a possible issue with function expressions :

function Order() { this.id = Math.floor((Math.random() * 10000000) + 1); // don't do it in a production code ;) this.items = []; } Order.prototype.addItem = function(item) { this.items.push(item); } Order.prototype.logItems = function() { this.items.forEach(function(item) { console.log("item description: " + item.description + " for order with id: " + this.id); }); } var order = new Order(); order.addItem({ description: 'Glimmer 2 rockzzz' }); order.logItems(); // whooops

We have a simple class-like functionality using constructor function and prototype to implement Order with some questionable ( ;) ) way of assigning id and some items . We can add more items with Order.prototype.addItem function and we can log them with Order.prototype.logItems function.

But there’s a problem: logItems function doesn’t log id , but logs undefined instead. Why is that?

Function expressionscreate their own context and define own this , so it no longer refers to the outer context, which is the order instance. There are several ways to solve this problem.

The most obvious is to assign outer this to some other variable, like that or self :

Order.prototype.logItems = function() { var self = this; this.items.forEach(function(item) { console.log("item description: " + item.description + " for order with id: " + self.id); }); }

You can also pass outer this as a second argument to forEach function:

Order.prototype.logItems = function() { this.items.forEach(function(item) { console.log("item description: " + item.description + " for order with id: " + this.id); }, this); }

You can even explicitly bind outer this to callback argument inside forEach function:

Order.prototype.logItems = function() { this.items.forEach(function(item) { console.log("item description: " + item.description + " for order with id: " + this.id); }.bind(this)); }

All these solutions work, but aren’t really that clean. Fortunately, since ES6, we can use arrow function expressions which preserve outer context and don’t define own this . After little refactoring Order.prototype.logItems could look like this:

Order.prototype.logItems = function() { this.items.forEach((item) => { console.log("item description: " + item.description + " for order with id: " + this.id); }); }

Much Better!

As great as it looks like, it may not be a good idea to apply arrow function expressions everywhere, especially for Ember computed properties .

Ember Computed Properties And Arrow Functions? - Not A Good Idea

Recently I was doing some refactoring in one Ember app. The syntax in one of the models was a bit mixed and there were some function expressions and arrow function expressions which looked a bit like this:

redis是当前流行的nosql数据库的更多相关文章

  1. mongodb,redis,hbase 三者都是nosql数据库,他们的最大区别和不同定位是什么?

      不严谨地讲,Redis定位在"快",HBase定位于"大",mongodb定位在"灵活". NoSQL的优点正好就是SQL的软肋,而其弱 ...

  2. SnappyDB—Android上的NoSQL数据库简介

    参考:http://www.open-open.com/lib/view/open1420816891937.html 参考:http://android-arsenal.com/details/1/ ...

  3. NoSQL数据库Mongodb副本集架构(Replica Set)高可用部署

    NoSQL数据库Mongodb副本集架构(Replica Set)高可用部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. MongoDB 是一个基于分布式文件存储的数据库.由 C ...

  4. 性能超越 Redis 的 NoSQL 数据库 SSDB

    idea's blog - 性能超越 Redis 的 NoSQL 数据库 SSDB 性能超越 Redis 的 NoSQL 数据库 SSDB C/C++语言编程, SSDB Views: 8091 | ...

  5. NoSql数据库简介及Redis学习

    NO-Sql数据库:Not Only不仅仅是SQL 定义:非关系型数据库:NoSQL用于超大规模数据的存储.(例如谷歌或Facebook每天为他们的用户收集万亿比特的数据).这些类型的数据存储不需要固 ...

  6. 企业级nosql数据库应用与实战-redis

    一.NoSQL简介 1.1 常见的优化思路和方向 1.1.1 MySQL主从读写分离 由于数据库的写入压力增加,Memcached只能缓解数据库的读取压力.读写集中在一个数据库上让数据库不堪重负,大部 ...

  7. Redis - NoSQL数据库技术(一)

    NoSQL入门概述(一) 作者 : Stanley 罗昊 [转载请注明出处和署名,谢谢!] 什么是NoSQL NoSQL(NoSQL - Not Only SQL),意“不仅仅是SQL”: 泛指非关系 ...

  8. Python操作nosql数据库之redis

    一.NoSQL的操作 NoSQL,泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得力不 ...

  9. redis学习笔记-02:为什么使用NoSQL数据库

    一.第一代:单机版的MySQL 1.静态网页,动态交互类型的网站不多. 2.架构:APP---->DAL---->MySQL Instance 3.数据存储的瓶颈: (1)数据量总大小超过 ...

随机推荐

  1. vue 生产环境和测试环境的配置

    我们引用的是axios 给src目录增加 api 文件夹 里面写上index.js // 配置API接口地址 var root = process.env.API_ROOT // 引用axios va ...

  2. 抓取摩拜单车API数据,并做可视化分析

    抓取摩拜单车API数据,并做可视化分析 纵聊天下 百家号|04-19 15:16 关注 警告:此篇文章仅作为学习研究参考用途,请不要用于非法目的. 摩拜是最早进入成都的共享单车,每天我从地铁站下来的时 ...

  3. eureka注册中心设置用户名密码

    1.加入安全认证依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...

  4. 1.开始Spring

    1 对Spring的认识 为了实现控制反转,我们可以想象java创建了一个工厂类,工厂类可以去读取配置文件 比如一个.property文件.通过这个文件中的配置,反射创建一些对象,当外界需要某个类的对 ...

  5. LOJ 6497 图

    LOJ 6497 图 题意 有图\(n\)点,每点可为黑或白,其中一些点颜色已定. 初时图无边,于每对\(i<j\),可由\(i\)向\(j\)连有向边,或不连. 称黑白相间之路径为交错路径. ...

  6. NoClassDefFoundError: Could not initialize class org.apache.cxf.jaxrs.provider.ProviderFactory org.springframework.aop.support.AopUtils.isCglibProxyClass

    报错: 2018-05-03 10:35:20 377 ERROR org.apache.juli.logging.DirectJDKLog.log:181 - Servlet.service() f ...

  7. 查看linux系统的文件inode号码使用情况

    :~$ df -i 文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点 udev % /dev tmpfs % /run /dev/sda2 % / tmpfs % /dev/shm ...

  8. .NET2.0引用.NET3.5的System.Core.dll&Dapper在.NET2.0下的配置

    微软MSDN对.NET2.0,3.0,3.5的描述: .NET Framework 版本 2.0.3.0 和 3.5 是使用同一 CLR 版本 (CLR 2.0) 生成的. 这些版本表示单个安装的连续 ...

  9. NOIP2017解题报告

    啊不小心点发布了,懒得删了就这样吧,虽然还没写完,也不打算写了大概. d1t1 结论题 没什么好说的 d1t2 模拟 没什么好说的 d1t3 70分算法其实比较好想. 没有0边,就跑最短路,然后按di ...

  10. ubuntu查看并杀死进程

    Ubuntu 查看和杀死进程 今天在netbeans中关闭webrick时,发现没有关闭掉,打入localhost:3000 依然显示页面,发现无法从nb中再次关闭 只有进入ubuntu的进程下关闭 ...