peek-redis-1.2.0/0000755000175000017500000000000013152467246012600 5ustar pravipravipeek-redis-1.2.0/CHANGELOG.md0000644000175000017500000000052613152467246014414 0ustar pravipravi# 1.0.0 - Initial release. # 1.0.1 - Fixed a bug where Redis::Client may have a block passed to some methods and if not passed would return 0 instead of true or false. # 1.1.0 - Query count and Query time are now threadsafe. # 1.2.0 - Use prepend over chaining in Redis::Client - [#4](https://github.com/peek/peek-redis/pull/4) by @ys peek-redis-1.2.0/README.md0000644000175000017500000000136313152467246014062 0ustar pravipravi# Peek::Redis Take a peek into the Redis calls made within your Rails application. Things this peek view provides: - Total number of Redis commands called during the request - The duration of the calls made during the request ## Installation Add this line to your application's Gemfile: gem 'peek-redis' And then execute: $ bundle Or install it yourself as: $ gem install peek-redis ## Usage Add the following to your `config/initializers/peek.rb`: ```ruby Peek.into Peek::Views::Redis ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request peek-redis-1.2.0/lib/0000755000175000017500000000000013152467246013346 5ustar pravipravipeek-redis-1.2.0/lib/peek/0000755000175000017500000000000013152467246014272 5ustar pravipravipeek-redis-1.2.0/lib/peek/views/0000755000175000017500000000000013152467246015427 5ustar pravipravipeek-redis-1.2.0/lib/peek/views/redis.rb0000644000175000017500000000242713152467246017067 0ustar pravipravirequire 'redis' require 'atomic' # Instrument Redis time module Peek module RedisInstrumented def call(*args, &block) start = Time.now super(*args, &block) ensure duration = (Time.now - start) ::Redis::Client.query_time.update { |value| value + duration } ::Redis::Client.query_count.update { |value| value + 1 } end end end class Redis::Client prepend Peek::RedisInstrumented class << self attr_accessor :query_time, :query_count end self.query_count = Atomic.new(0) self.query_time = Atomic.new(0) end module Peek module Views class Redis < View def duration ::Redis::Client.query_time.value end def formatted_duration ms = duration * 1000 if ms >= 1000 "%.2fms" % ms else "%.0fms" % ms end end def calls ::Redis::Client.query_count.value end def results { :duration => formatted_duration, :calls => calls } end private def setup_subscribers # Reset each counter when a new request starts subscribe 'start_processing.action_controller' do ::Redis::Client.query_time.value = 0 ::Redis::Client.query_count.value = 0 end end end end end peek-redis-1.2.0/lib/peek-redis.rb0000644000175000017500000000012513152467246015721 0ustar pravipravirequire 'peek/views/redis' require 'peek-redis/version' require 'peek-redis/railtie' peek-redis-1.2.0/lib/peek-redis/0000755000175000017500000000000013152467246015376 5ustar pravipravipeek-redis-1.2.0/lib/peek-redis/railtie.rb0000644000175000017500000000012113152467246017346 0ustar pravipravimodule Peek module Redis class Railtie < ::Rails::Engine end end end peek-redis-1.2.0/lib/peek-redis/version.rb0000644000175000017500000000007313152467246017410 0ustar pravipravimodule Peek module Redis VERSION = '1.2.0' end end peek-redis-1.2.0/peek-redis.gemspec0000644000175000017500000000164313152467246016201 0ustar pravipravi# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'peek-redis/version' Gem::Specification.new do |gem| gem.name = 'peek-redis' gem.version = Peek::Redis::VERSION gem.authors = ['Garrett Bjerkhoel'] gem.email = ['me@garrettbjerkhoel.com'] gem.description = %q{Take a peek into the Redis calls made within your Rails application.} gem.summary = %q{Take a peek into the Redis calls made within your Rails application.} gem.homepage = 'https://github.com/peek/peek-redis' gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] gem.add_dependency 'peek' gem.add_dependency 'redis' gem.add_dependency 'atomic', '>= 1.0.0' end peek-redis-1.2.0/LICENSE.txt0000644000175000017500000000206113152467246014422 0ustar pravipraviCopyright (c) 2013 Garrett Bjerkhoel MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.peek-redis-1.2.0/.gitignore0000644000175000017500000000023213152467246014565 0ustar pravipravi*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp peek-redis-1.2.0/Rakefile0000644000175000017500000000003413152467246014242 0ustar pravipravirequire "bundler/gem_tasks" peek-redis-1.2.0/app/0000755000175000017500000000000013152467246013360 5ustar pravipravipeek-redis-1.2.0/app/views/0000755000175000017500000000000013152467246014515 5ustar pravipravipeek-redis-1.2.0/app/views/peek/0000755000175000017500000000000013152467246015441 5ustar pravipravipeek-redis-1.2.0/app/views/peek/views/0000755000175000017500000000000013152467246016576 5ustar pravipravipeek-redis-1.2.0/app/views/peek/views/_redis.html.erb0000644000175000017500000000022613152467246021500 0ustar pravipravi... / ... redis peek-redis-1.2.0/Gemfile0000644000175000017500000000013713152467246014074 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in peek-redis.gemspec gemspec