ioredis.js tutorial

每个项目产品都会让你加埋点,你是愿意花几天一个个加,还是愿意几分钟一个小时加完去喝茶聊天?来试试这520web工具, 高效加埋点,目前我们公司100号前端都在用,因为很好用,所以很自然普及开来了,推荐给大家吧

http://www.520webtool.com/

自己开发所以免费,埋点越多越能节约时间,点两下埋点就加上了,还不会犯错,里面有使用视频,反正免费 😄

Introduction

ioredis.js is a new, performance focused Redis client for Node.js. It is used by the online commerce company, Alibaba. It also supports ES6 types such as Map and Set and also implements support for Promises, which the other big Redis client, <a href=“https://github.com/mranney/node_redis”>node_redis</a>, is not. <a href=“https://github.com/luin/ioredis”>ioredis.js</a> is newly released so in the next sections of this blog post I will show you some basic usage of this client.

Installing the client

npm install ioredis

Instantiating the client

var Redis = require("ioredis");
//basic constructor - Connect to 127.0.0.1:6379
var redis = new Redis();

There are multiple ways to instantiate the Redis client. Above I presented the basic method of doing it and bellow I will show you more methods:

//127.0.0.1:6400
var Redis = new Redis(6400);
// 192.168.1.1:6379
var Redis = new Redis(6379, '192.168.1.1');
// 192.168.1.1:6379
var Redis = new Redis(6379, '192.168.1.1');
// 127.0.0.1:6380, db 4
new Redis('redis://:authpassword@127.0.0.1:6380/4');   
new Redis('/tmp/redis.sock');   
new Redis({
  port: 6379,          // Redis port
  host: '127.0.0.1',   // Redis host
  family: 4,           // 4(IPv4) or 6(IPv6)
  password: 'auth'
  db: 0
})

I also suggest, as best practice in general to use environment variables for connectivity credentials/urls/ports.

Basic functionality

The two basic Redis operations set and get can be done pretty straight forward with ioredis.js.

Set:

redis.set('key', 'value');

Get using callbacks:

redis.get('key', function (err, result) {
  console.log(result); //will display 'value'
});

Get using promises:

redis.get('key').then(function (result) {
  console.log(result); //will display 'value'
});

Adding a set of values:

// Arguments to commands are flatten, so the following are same
redis.sadd('set', 1, 3, 5, 7);
// or 
redis.sadd('set', [1, 3, 5, 7]);

Getting a set of values using callback:

redis.smembers('set', function(err, result) {
  console.log(result); //will display '1, 3, 5, 7'
});

Getting a set of values using promises:

redis.smembers('set').then(function(result) {
  console.log(result); //will display '1, 3, 5, 7'
});

All Redis commands are supported by ioredis.js, both using callbacks or promises. Just use each command as a method name for the Redis client.

Handling binary data

ioredis.js also handles binary data by adding and retrieving buffers.

Adding:

redis.set('key', new Buffer('value'));

Every command has a method that returns a buffer. By doing that you have to append “Buffer” to the command name.

Retrieving:

redis.getBuffer('key', function (err, result) {
  // result is a buffer.
});

ioredis.js also supports pipelining, transactions, offline queues, Sentinel and Cluster. For these advanced operations you can find a pretty detailed description here.

I hope this tutorial is informative enough to give you a start with ioredis.js.

购物商城项目采用PHP+mysql有以及html+css jq以及layer.js datatables bootstorap等插件等开发,采用了MVC模式,建立一个完善的电商系统,通过不同用户的不同需求,进行相应的调配和处理,提高对购买用户进行配置….zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值