Created
November 15, 2012 02:44
-
-
Save adamnengland/4076309 to your computer and use it in GitHub Desktop.
Test Case for Redis Key Length Performance
This file contains 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
redis = require "redis" | |
randomString = (length) -> | |
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
result = "" | |
i = length | |
while i > 0 | |
result += chars[Math.round(Math.random() * (chars.length - 1))] | |
--i | |
result | |
writeTest = (keyLength) -> | |
console.log "1000 set statements for #{keyLength} character keys" | |
keys = [] | |
for x in [1..1000] | |
keys.push randomString(keyLength) | |
startTime = new Date().getTime() | |
for x in keys | |
client.set x, randomString(10000) | |
client.quit -> | |
console.log "1000 keys inserted in #{new Date().getTime() - startTime} ms" | |
readTest(keys) | |
readTest = (keys) -> | |
client = redis.createClient() | |
startTime = new Date().getTime() | |
for x in keys | |
client.get x | |
client.quit -> | |
console.log "1000 keys retreived in #{new Date().getTime() - startTime} ms" | |
client = redis.createClient() | |
client.flushdb -> | |
writeTest(20000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment