原文地址:http://www.cnblogs.com/zhongweiv/p/node_redis.html

安装前准备

win64:

Install python: http://www.python.org/getit/windows/
Install Microsoft Visual Studio C++ 2012 Express version: http://go.microsoft.com/?linkid=9816758
Install node-gyp: npm install -g node-gyp

linux (debian):

python / make are pre-installed!
just install gcc: sudo apt-get install g++
and then install node-gyp: sudo npm install -g node-gyp

 

简介和安装

  • redis简介:
  1. 开源高性能key-value存储;采用内存中(in-memory)数据集的方式,也可以采用磁盘存储方式(前者性能高,但数据可能丢失,后者正好相反)
  2. 支持字符串(strings)、哈希(hashes)、列表(lists)、集合(sets)和 有序集合(sorted sets)等;支持对复杂数据结构的高速操作。
  3. 特性多,支持主从同步、pub/sub等
  4. 支持多种客户端(http://redis.io/clients
  5. ...

  注:应用场景没有提到,暂时没有太多实际体会,不瞎说,以免误导人,但是从它的简介和特性来说,起码缓存场景是不错的!

  Redis下载地址: https://github.com/dmajkic/redis/downloads  

  node.js客户端:node_redis https://github.com/mranney/node_redis/

  • redis安装(Windows平台)

   redis非常方便,直接下载解压就可以使用,因为开发环境是win7 64位,直接下载(示例下载的安装包:redis-2.4.5-win32-win64.zip)

  • redis运行

  解压到后运行"64bit"文件夹下的redis-server.exe即可,但是这样运行会出现一个如下警告提示:

  #Warning: no config file specified,using the default config. In order to specify a config file use ‘redis-server /path/to/redis.conf’

nodejs笔记--与Redis的交互篇(六)

  提示也比较明显,没有明确的配置文件,使用的是默认配置,请使用‘redis-server /path/to/redis.conf’指定明确的配置文件

   根据提示运行redis成功(如下图)

nodejs笔记--与Redis的交互篇(六)

  在redis-server.exe同级目录下可以看到一个redis.conf文件,这就是配置文件

  • node_redis安装
npm install redis
或者
npm install hiredis redis

  我这里采用 npm install hiredis redis 安装

  注:两种都可用,区别在于性能,hiredis是非阻塞的,而且速度更快;如果安装了hiredis,node_redis则会默认以它为解析器,没安装就会用纯javascript解释器,对于学习或者开发环境,用哪个都无所谓

redis.createClient()连接到redis服务器

  环境都准备好了,就开始写一代简单的代码测试用nodejs连接一下服务器

nodejs笔记--与Redis的交互篇(六)

var redis = require('redis'),
    client = redis.createClient();

client.on('ready',function(err){
    console.log('ready');
});

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2021-09-15
  • 2021-06-08
  • 2022-12-23
  • 2022-01-22
  • 2021-11-30
猜你喜欢
  • 2021-07-07
  • 2021-11-01
  • 2021-08-03
  • 2021-08-11
  • 2021-12-24
  • 2021-05-17
  • 2022-12-23
相关资源
相似解决方案