1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

chore: use standard

This commit is contained in:
Ruben Bridgewater
2017-05-06 07:06:52 +02:00
parent 5d29f541e9
commit f1a7bcd735
106 changed files with 10706 additions and 10978 deletions

View File

@@ -1,84 +1,82 @@
'use strict';
'use strict'
var assert = require('assert');
var config = require('../lib/config');
var helper = require('../helper');
var redis = config.redis;
var Buffer = require('safe-buffer').Buffer
var assert = require('assert')
var config = require('../lib/config')
var helper = require('../helper')
var redis = config.redis
describe("The 'hgetall' method", function () {
describe('The \'hgetall\' method', function () {
helper.allTests(function (ip, args) {
describe('using ' + ip, function () {
var client
helper.allTests(function (ip, args) {
describe('regular client', function () {
beforeEach(function (done) {
client = redis.createClient.apply(null, args)
client.once('ready', function () {
client.flushdb(done)
})
})
describe('using ' + ip, function () {
var client;
it('handles simple keys and values', function (done) {
client.hmset(['hosts', 'hasOwnProperty', '1', 'another', '23', 'home', '1234'], helper.isString('OK'))
client.hgetall(['hosts'], function (err, obj) {
assert.strictEqual(3, Object.keys(obj).length)
assert.strictEqual('1', obj.hasOwnProperty.toString())
assert.strictEqual('23', obj.another.toString())
assert.strictEqual('1234', obj.home.toString())
done(err)
})
})
describe('regular client', function () {
it('handles fetching keys set using an object', function (done) {
client.batch().hmset('msgTest', { message: 'hello' }, undefined).exec()
client.hgetall('msgTest', function (err, obj) {
assert.strictEqual(1, Object.keys(obj).length)
assert.strictEqual(obj.message, 'hello')
done(err)
})
})
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.flushdb(done);
});
});
it('handles fetching a messing key', function (done) {
client.hgetall('missing', function (err, obj) {
assert.strictEqual(null, obj)
done(err)
})
})
})
it('handles simple keys and values', function (done) {
client.hmset(['hosts', 'hasOwnProperty', '1', 'another', '23', 'home', '1234'], helper.isString('OK'));
client.hgetall(['hosts'], function (err, obj) {
assert.strictEqual(3, Object.keys(obj).length);
assert.strictEqual('1', obj.hasOwnProperty.toString());
assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString());
done(err);
});
});
describe('binary client', function () {
var client
var args = config.configureClient(ip, {
returnBuffers: true
})
it('handles fetching keys set using an object', function (done) {
client.batch().hmset('msgTest', { message: 'hello' }, undefined).exec();
client.hgetall('msgTest', function (err, obj) {
assert.strictEqual(1, Object.keys(obj).length);
assert.strictEqual(obj.message, 'hello');
done(err);
});
});
beforeEach(function (done) {
client = redis.createClient.apply(null, args)
client.once('ready', function () {
client.flushdb(done)
})
})
it('handles fetching a messing key', function (done) {
client.hgetall('missing', function (err, obj) {
assert.strictEqual(null, obj);
done(err);
});
});
});
it('returns binary results', function (done) {
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', Buffer.from([0xAA, 0xBB, 0x00, 0xF0]), Buffer.from([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'))
client.hgetall('bhosts', function (err, obj) {
assert.strictEqual(4, Object.keys(obj).length)
assert.strictEqual('1', obj.mjr.toString())
assert.strictEqual('23', obj.another.toString())
assert.strictEqual('1234', obj.home.toString())
assert.strictEqual((Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3])
assert.strictEqual((Buffer.from([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'))
return done(err)
})
})
})
describe('binary client', function () {
var client;
var args = config.configureClient(ip, {
returnBuffers: true
});
beforeEach(function (done) {
client = redis.createClient.apply(null, args);
client.once('ready', function () {
client.flushdb(done);
});
});
it('returns binary results', function (done) {
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'));
client.hgetall('bhosts', function (err, obj) {
assert.strictEqual(4, Object.keys(obj).length);
assert.strictEqual('1', obj.mjr.toString());
assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString());
assert.strictEqual((new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]);
assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
return done(err);
});
});
});
afterEach(function () {
client.end(true);
});
});
});
});
afterEach(function () {
client.end(true)
})
})
})
})