Created
June 12, 2013 09:40
-
-
Save ManjunathaN/5764032 to your computer and use it in GitHub Desktop.
In Redis, using Hash data type over String data type save half the memory.
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
jruby-1.7.1 :079 > redis_conn | |
=> #<Redis client v3.0.2 for redis://localhost:6379/0> | |
jruby-1.7.1 :080 > redis_conn.flushdb | |
=> "OK" | |
jruby-1.7.1 :081 > redis_conn.info "memory" | |
=> {"used_memory"=>"1081696", "used_memory_human"=>"1.03M", "used_memory_rss"=>"29933568", "used_memory_peak"=>"38219840", "used_memory_peak_human"=>"36.45M", "used_memory_lua"=>"31744", "mem_fragmentation_ratio"=>"27.67", "mem_allocator"=>"libc"} | |
jruby-1.7.1 :082 > 100000.times { |i| redis_conn.mset "USER"+i.to_s+"POSTS",(1+i).to_s, "USER"+i.to_s+"COMMENTS"+i.to_s,(2+i).to_s, "USER"+i.to_s+"LIKES"+i.to_s,(2+i).to_s, "USER"+i.to_s+"DISLIKES"+i.to_s,(2+i).to_s} | |
=> 100000 | |
jruby-1.7.1 :083 > redis_conn.info "memory" | |
=> {"used_memory"=>"36636112", "used_memory_human"=>"34.94M", "used_memory_rss"=>"42246144", "used_memory_peak"=>"38219840", "used_memory_peak_human"=>"36.45M", "used_memory_lua"=>"31744", "mem_fragmentation_ratio"=>"1.15", "mem_allocator"=>"libc"} | |
jruby-1.7.1 :084 > redis_conn.flushdb | |
=> "OK" | |
jruby-1.7.1 :085 > redis_conn.info "memory" | |
=> {"used_memory"=>"1081824", "used_memory_human"=>"1.03M", "used_memory_rss"=>"29749248", "used_memory_peak"=>"38219840", "used_memory_peak_human"=>"36.45M", "used_memory_lua"=>"31744", "mem_fragmentation_ratio"=>"27.50", "mem_allocator"=>"libc"} | |
jruby-1.7.1 :086 > 100000.times { |i| redis_conn.hmset "USER"+i.to_s, "USER"+i.to_s+"POSTS",(1+i).to_s, "USER"+i.to_s+"COMMENTS"+i.to_s,(2+i).to_s, "USER"+i.to_s+"LIKES"+i.to_s,(2+i).to_s, "USER"+i.to_s+"DISLIKES"+i.to_s,(2+i).to_s} | |
=> 100000 | |
jruby-1.7.1 :087 > redis_conn.info "memory" | |
=> {"used_memory"=>"22387968", "used_memory_human"=>"21.35M", "used_memory_rss"=>"30986240", "used_memory_peak"=>"38219840", "used_memory_peak_human"=>"36.45M", "used_memory_lua"=>"31744", "mem_fragmentation_ratio"=>"1.38", "mem_allocator"=>"libc"} | |
jruby-1.7.1 :088 > redis_conn.flushdb | |
=> "OK" | |
jruby-1.7.1 :089 > redis_conn.info "memory" | |
=> {"used_memory"=>"1081952", "used_memory_human"=>"1.03M", "used_memory_rss"=>"30253056", "used_memory_peak"=>"38219840", "used_memory_peak_human"=>"36.45M", "used_memory_lua"=>"31744", "mem_fragmentation_ratio"=>"27.96", "mem_allocator"=>"libc"} | |
jruby-1.7.1 :090 > 100000.times { |i| redis_conn.hmset "USER"+i.to_s, "POSTS",(1+i).to_s, "COMMENTS"+i.to_s,(2+i).to_s, "LIKES"+i.to_s,(2+i).to_s, "DISLIKES"+i.to_s,(2+i).to_s} | |
=> 100000 | |
jruby-1.7.1 :091 > redis_conn.info "memory" | |
=> {"used_memory"=>"18112928", "used_memory_human"=>"17.27M", "used_memory_rss"=>"30470144", "used_memory_peak"=>"38219840", "used_memory_peak_human"=>"36.45M", "used_memory_lua"=>"31744", "mem_fragmentation_ratio"=>"1.68", "mem_allocator"=>"libc"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment