You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Thrown errors might kill the users app. By emitting the errors the user is able to catch all errors in one place without the app going down
109 lines
4.0 KiB
JavaScript
109 lines
4.0 KiB
JavaScript
'use strict';
|
|
|
|
var assert = require('assert');
|
|
var config = require("../lib/config");
|
|
var helper = require('../helper');
|
|
var redis = config.redis;
|
|
var uuid = require('uuid');
|
|
|
|
describe("The 'mset' method", function () {
|
|
|
|
helper.allTests(function(parser, ip, args) {
|
|
|
|
describe("using " + parser + " and " + ip, function () {
|
|
var key, value, key2, value2;
|
|
|
|
beforeEach(function () {
|
|
key = uuid.v4();
|
|
value = uuid.v4();
|
|
key2 = uuid.v4();
|
|
value2 = uuid.v4();
|
|
});
|
|
|
|
describe("when not connected", function () {
|
|
var client;
|
|
|
|
beforeEach(function (done) {
|
|
client = redis.createClient.apply(redis.createClient, args);
|
|
client.once("error", done);
|
|
client.once("connect", function () {
|
|
client.quit();
|
|
});
|
|
client.on('end', function () {
|
|
return done();
|
|
});
|
|
});
|
|
|
|
it("reports an error", function (done) {
|
|
client.mset(key, value, key2, value2, function (err, res) {
|
|
assert(err.message.match(/Redis connection gone/));
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("when connected", function () {
|
|
var client;
|
|
|
|
beforeEach(function (done) {
|
|
client = redis.createClient.apply(redis.createClient, args);
|
|
client.once("error", done);
|
|
client.once("connect", function () {
|
|
done();
|
|
});
|
|
});
|
|
|
|
afterEach(function () {
|
|
client.end();
|
|
});
|
|
|
|
describe("and a callback is specified", function () {
|
|
describe("with valid parameters", function () {
|
|
it("sets the value correctly", function (done) {
|
|
client.mset(key, value, key2, value2, function(err) {
|
|
if (err) {
|
|
return done(err);
|
|
}
|
|
client.get(key, helper.isString(value));
|
|
client.get(key2, helper.isString(value2, done));
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("with undefined 'key' parameter and missing 'value' parameter", function () {
|
|
it("reports an error", function (done) {
|
|
client.mset(undefined, function (err, res) {
|
|
helper.isError()(err, null);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
describe("and no callback is specified", function () {
|
|
describe("with valid parameters", function () {
|
|
it("sets the value correctly", function (done) {
|
|
client.mset(key, value2, key2, value);
|
|
client.get(key, helper.isString(value2));
|
|
client.get(key2, helper.isString(value, done));
|
|
});
|
|
});
|
|
|
|
describe("with undefined 'key' and missing 'value' parameter", function () {
|
|
// this behavior is different from the 'set' behavior.
|
|
it("emits an error", function (done) {
|
|
client.on('error', function (err) {
|
|
assert.equal(err.message, "ERR wrong number of arguments for 'mset' command");
|
|
done();
|
|
});
|
|
|
|
client.mset();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|