ioredis.js tutorial

ioredis.js快速入门
本文介绍了一款新的Node.js Redis客户端ioredis.js,它支持ES6类型如Map和Set,并实现了对Promises的支持。文章详细展示了如何安装并实例化ioredis.js客户端,以及如何使用基本操作如set和get等。

每个项目产品都会让你加埋点,你是愿意花几天一个个加,还是愿意几分钟一个小时加完去喝茶聊天?来试试这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.

在车辆工程中,悬架系统的性能评估和优化一直是研究的热点。悬架不仅关乎车辆的乘坐舒适性,还直接影响到车辆的操控性和稳定性。为了深入理解悬架的动态行为,研究人员经常使用“二自由度悬架模型”来简化分析,并运用“传递函数”这一数学工具来描述悬架系统的动态特性。 二自由度悬架模型将复杂的车辆系统简化为两个独立的部分:车轮和车身。这种简化模型能够较准确地模拟出车辆在垂直方向上的运动行为,同时忽略了侧向和纵向的动态影响,这使得工程师能够更加专注于分析与优化与垂直动态相关的性能指标。 传递函数作为控制系统理论中的一种工具,能够描述系统输入和输出之间的关系。在悬架系统中,传递函数特别重要,因为它能够反映出路面不平度如何被悬架系统转化为车内乘员感受到的振动。通过传递函数,我们可以得到一个频率域上的表达式,从中分析出悬架系统的关键动态特性,如系统的振幅衰减特性和共振频率等。 在实际应用中,工程师通过使用MATLAB这类数学软件,建立双质量悬架的数学模型。模型中的参数包括车轮质量、车身质量、弹簧刚度以及阻尼系数等。通过编程求解,工程师可以得到悬架系统的传递函数,并据此绘制出传递函数曲线。这为评估悬架性能提供了一个直观的工具,使工程师能够了解悬架在不同频率激励下的响应情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值