Created
April 10, 2012 12:02
-
-
Save stefan-mees/2350893 to your computer and use it in GitHub Desktop.
redis zmap
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
ruby redis_keys.rb zipmap | |
redis-cli info | grep used_memory_human | |
used_memory_human:18.54M | |
ruby redis_keys.rb hash | |
redis-cli info | grep used_memory_human | |
used_memory_human:69.92M | |
ruby redis_keys.rb plain | |
redis-cli info | grep used_memory_human | |
used_memory_human:69.92M | |
http://redis.io/topics/memory-optimization | |
http://download.redis.io/redis-stable/src/zipmap.c |
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
require 'redis' | |
modi = ARGV[0] || 'hash' | |
NUMBER_OF_KEYS = 1_000_000 | |
KEYS_PER_ZIPMAP = 512 | |
OFFSET = 1_000_000 | |
redis = Redis.new | |
modulo_zmap = (NUMBER_OF_KEYS / KEYS_PER_ZIPMAP).ceil | |
NUMBER_OF_KEYS.times do |i| | |
key = OFFSET + i | |
if modi == 'hash' | |
redis.hset("hash", key.to_s, 10_000.to_s) | |
elsif modi == 'zipmap' | |
hash_key = key % modulo_zmap | |
redis.hset("z#{hash_key}", key.to_s, 10_000.to_s) | |
elsif modi == 'plain' | |
redis.set(key, 10_000.to_s) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment