Skip to content

Instantly share code, notes, and snippets.

@adamnengland
Created November 15, 2012 02:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamnengland/4076309 to your computer and use it in GitHub Desktop.
Save adamnengland/4076309 to your computer and use it in GitHub Desktop.
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