Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test Case for Redis Key Length Performance
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