Created
September 19, 2012 18:36
-
-
Save slaskis/3751363 to your computer and use it in GitHub Desktop.
A test for node_redis that shows some inconsistencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var redis = require('redis') | |
, client = redis.createClient() | |
, assert = require('assert'); | |
// redis.debug_mode = true; | |
client.on("error", function (err) { | |
console.log("Error " + err); | |
}); | |
function gen(i){ | |
var s = ''; | |
while(i--) | |
s += 'k'//String.fromCharCode(Math.random()*100+100); | |
return s; | |
} | |
// generate 1Mb of hash | |
var hash1024 = {}; | |
for(var l=100; l> 0; l--){ | |
// 1kb key, 9kb value | |
hash1024[gen(1024)] = gen(1024*9); | |
} | |
// generate a hash | |
var hash100 = {}; | |
for(var l=100; l> 0; l--){ | |
// 1b key, 1kb value | |
hash100['k'] = 'v'; | |
} | |
// select other db | |
client.select(2); | |
// clean out old keys | |
var multi = client.multi(); | |
multi.del('hi1') | |
multi.del('hi2') | |
multi.del('hi3') | |
multi.exec(function(err,results){ | |
assert.ifError(err) | |
assert.equal(results[0],'1') | |
assert.equal(results[1],'1') | |
assert.equal(results[2],'1') | |
}); | |
// select hash (large: 1024 or small: 100) | |
var hash = hash100; | |
// hmset | |
var multi = client.multi(); | |
multi.hmset('hi1',hash); | |
multi.hmset('hi2',hash); | |
multi.hmset('hi3',hash); | |
multi.exec(function(err,results){ | |
assert.ifError(err) | |
assert.equal(results[0],'OK') | |
assert.equal(results[1],'OK') | |
assert.equal(results[2],'OK') | |
// hmget | |
// watch out for QUEUED | |
var multi = client.multi(); | |
multi.hgetall('hi1') | |
multi.hgetall('hi2') | |
multi.hgetall('hi3') | |
multi.exec(function(err,results){ | |
assert.ifError(err); | |
console.log(results) | |
assert(results[0],'could not find result 0') | |
assert(results[1],'could not find result 1') | |
assert(results[2],'could not find result 2') | |
Object.keys(hash).forEach(function(k){ | |
assert(results[0][k],'could not find '+k+' in result 0') | |
assert(results[1][k],'could not find '+k+' in result 1') | |
assert(results[2][k],'could not find '+k+' in result 2') | |
assert.equal(results[0][k],hash[k]) | |
assert.equal(results[1][k],hash[k]) | |
assert.equal(results[2][k],hash[k]) | |
}) | |
client.quit() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment