You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-12-25 00:40:59 +03:00
move to use CommonJS
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import * as oldRedis from 'redis-old';
|
||||
import * as newRedis from 'redis-new';
|
||||
import { promisify } from 'util';
|
||||
import { once } from 'events';
|
||||
|
||||
const ITERATIONS = 1_000_000;
|
||||
const oldRedis = require('redis-old'),
|
||||
newRedis = require('redis-new'),
|
||||
{promisify} = require('util'),
|
||||
{once} = require('events'),
|
||||
ITERATIONS = 1_000_000;
|
||||
|
||||
function benchmarkCallback(name, fn) {
|
||||
return new Promise(resolve => {
|
||||
const start = process.hrtime.bigint();
|
||||
|
||||
let counter = 0;
|
||||
|
||||
function iterationCallback(err) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
@@ -20,6 +20,7 @@ function benchmarkCallback(name, fn) {
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < ITERATIONS; i++) {
|
||||
fn(iterationCallback);
|
||||
}
|
||||
@@ -38,17 +39,19 @@ async function benchmarkPromise(name, fn) {
|
||||
console.log(`${name} took ${process.hrtime.bigint() - start} nanoseconds`);
|
||||
}
|
||||
|
||||
const oldClient = oldRedis.createClient();
|
||||
oldClient.flushallAsync = promisify(oldClient.flushall).bind(oldClient);
|
||||
await once(oldClient, 'connect');
|
||||
await oldClient.flushallAsync();
|
||||
await benchmarkCallback('oldClient.ping', cb => {
|
||||
oldClient.ping('key', cb);
|
||||
});
|
||||
(async () => {
|
||||
const oldClient = oldRedis.createClient();
|
||||
oldClient.flushallAsync = promisify(oldClient.flushall).bind(oldClient);
|
||||
await once(oldClient, 'connect');
|
||||
await oldClient.flushallAsync();
|
||||
await benchmarkCallback('oldClient.ping', cb => {
|
||||
oldClient.ping('key', cb);
|
||||
});
|
||||
|
||||
const newClient = newRedis.createClient();
|
||||
await newClient.connect();
|
||||
await newClient.flushAll();
|
||||
await benchmarkPromise('newClient.ping', () => {
|
||||
return newClient.ping();
|
||||
});
|
||||
const newClient = newRedis.createClient();
|
||||
await newClient.connect();
|
||||
await newClient.flushAll();
|
||||
await benchmarkPromise('newClient.ping', () => {
|
||||
return newClient.ping();
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user