redis是当前流行的nosql数据库

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 是需要添加环境变量的,下图是我系统添加的环境变量 
Ubuntu安装redis并配置远程、密码以及开启php扩展

2.2配置密码登录

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

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

2.3重启redis

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


Ubuntu安装redis并配置远程、密码以及开启php扩展
Ubuntu安装redis并配置远程、密码以及开启php扩展

原因是我配置文件的第一行是无效的配置(/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:

posted @ 2016-12-12 16:26  3002059249  阅读(810)  评论(0编辑  收藏  举报