Skip to content

Instantly share code, notes, and snippets.

@jimfleming
Created January 23, 2012 04:31
Show Gist options
  • Save jimfleming/1660597 to your computer and use it in GitHub Desktop.
Save jimfleming/1660597 to your computer and use it in GitHub Desktop.
Generates random data for a redis database
#!/usr/bin/env coffee
guid = (length = 32) ->
chars = '0123456789abcdef'
result = ''
while length--
result += chars[Math.floor(Math.random() * chars.length)]
return result
random_count = 1000
redis = require('redis').createClient(9174, 'angler.redistogo.com')
redis.auth('b8e94f882df490a108318fd72c910f38')
redis.flushall()
redis.select(0)
multi = redis.multi()
multi.set('my_str', 'The quick brown fox jumped over the lazy dog.')
multi.set('my_json_str', '{"sample":"This is some sample text."}')
multi.lpush('my_list', 'black')
multi.lpush('my_list', 'white')
multi.lpush('my_list', 'red')
multi.lpush('my_list', 'green')
multi.lpush('my_list', 'blue')
multi.lpush('my_list', 'yellow')
multi.lpush('my_list', 'orange')
multi.lpush('my_list', 'purple')
multi.lpush('my_list', 'brown')
multi.sadd('my_set', 'first')
multi.sadd('my_set', 'second')
multi.sadd('my_set', 'third')
multi.sadd('my_set', 'fourth')
multi.sadd('my_set', 'fifth')
multi.sadd('my_set', 'sixth')
multi.sadd('my_set', 'seventh')
multi.sadd('my_set', 'eighth')
multi.sadd('my_set', 'nineth')
multi.sadd('my_set', 'tenth')
multi.zadd('my_zset', 100, 'first')
multi.zadd('my_zset', 200, 'second')
multi.zadd('my_zset', 300, 'third')
multi.zadd('my_zset', 400, 'fourth')
multi.zadd('my_zset', 500, 'fifth')
multi.zadd('my_zset', 600, 'sixth')
multi.zadd('my_zset', 700, 'seventh')
multi.zadd('my_zset', 800, 'eighth')
multi.zadd('my_zset', 900, 'nineth')
multi.zadd('my_zset', 1000, 'tenth')
multi.hmset('my_hset', 'make', 'Toyota', 'model', 'RAV4', 'color', 'black', 'year', '2003')
random_values_key = "#{random_count}_values"
multi.sadd(random_values_key, value = guid()) for i in [0..random_count]
multi.exec ->
console.log 'Done creating test data. DB0'
redis.select(1)
multi = redis.multi()
multi.set(key = guid(), "This key's value is \"#{key}\"") for i in [0..random_count]
multi.exec ->
console.log 'Done creating random data. DB1'
redis.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment