Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Last active April 28, 2018 09:24
Show Gist options
  • Save alekseyl/76c37965c347b9e253580bde33fcd79e to your computer and use it in GitHub Desktop.
Save alekseyl/76c37965c347b9e253580bde33fcd79e to your computer and use it in GitHub Desktop.
redis memory optimisation
# def to_base62
# Base62.encode(to_s)
# end
2.4.1 :001 > redis = Redis.new
=> #<Redis client v4.0.1 for redis://127.0.0.1:6379/0>
2.4.1 :002 > redis.flushdb
2.4.1 :003 > redis.info(:memory)['used_memory_human']
=> "670.55K"
2.4.1 :004 > redis.pipelined { 100000.times{|i| redis.incr( "user:#{i}" ) }; }; :done
2.4.1 :005 > redis.info(:memory)['used_memory_human']
=> "7.76M"
2.4.1 :006 > redis.flushdb
2.4.1 :007 > redis.pipelined { 100000.times{|i| redis.incr( "u:#{i.to_base62}" ) }; }; :done
2.4.1 :008 > redis.info(:memory)['used_memory_human']
=> "6.23M"
2.4.1 :010 > (670.kilobytes.to_f / 1.megabyte).round(2)
=> 0.65
2.4.1 :011 > ((7.76 - 0.65)/(6.23 - 0.65)).round(2)
=> 1.27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment