memkeys 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a37f2895bee4114c8e6a94c42a1212adb06cbbaf
4
+ data.tar.gz: 39bb411a7b89b4742e2e8bc1fe36a3708e38c667
5
+ SHA512:
6
+ metadata.gz: 3230faa39d51d3e78121c42c47714295653ed85037f50f5745cb9279e965de23440618af3edb56e394b937de9cabdb53738a90463627c7efb568146fd9b53fd6
7
+ data.tar.gz: 9c0b740de09250bf2196d270914e72181fd22307faee7b15c0e07da9b2da52c5abeda915b18c436a5d2bedee5bb176734d95480873110d8bebd7b363f3079bb8
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Memkeys
2
+
3
+ Lists keys currently listed in memcache, based on [this gist](https://gist.github.com/bkimble/1365005).
4
+
5
+ ## Sample usage
6
+
7
+ Open your terminal and run
8
+
9
+ memkeys
10
+
11
+ The output should look like:
12
+
13
+ | id | expires | bytes | cache_key |
14
+ | 6 | 2015-06-02 08:03:31 +0200 | 143 | _session_id:8b240b242330b0be921c78ffa7c4f6ff |
15
+ | 11 | 2015-06-02 20:03:23 +0200 | 807 | all_models_for_collection_cached |
16
+ | 13 | 2015-06-02 20:03:23 +0200 | 1210 | views/popular_items/c944e22bd654851ed47b502f569f8d4d |
17
+ | 20 | 2015-06-02 20:03:23 +0200 | 6082 | some_other_key |
18
+ | 31 | 2015-06-02 02:03:23 +0200 | 80259 | views/home/index |
19
+
20
+
21
+ ### Arguments
22
+
23
+ * `--host` The host
24
+ * `--port` The port
25
+ * `--timeout` The timeout
26
+
27
+ ## How to build & install gem
28
+
29
+ gem build memkeys.gemspec
30
+ gem install memkeys-0.1.0.gem
31
+
32
+ Or just clone the repo and run
33
+
34
+ ruby bin/memkeys
35
+
36
+ ## TODO
37
+
38
+ * Some kind of tests.
39
+ * Publish
40
+
41
+ ## Thanks
42
+
43
+ Big thanks to:
44
+ * [Ruby Co-Learning](http://www.meetup.com/opentechschool-berlin/events/219762691/)
45
+ * Jose Pio [GitHub](http://www.github.com/josetonyp)
data/Rakefile ADDED
File without changes
data/bin/memkeys ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/memkeys'
4
+
5
+ Memkeys.start(ARGV)
data/lib/memkeys.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'net/telnet'
2
+ require 'thor'
3
+
4
+ class Memkeys < Thor
5
+ desc "List Keys", "List Keys"
6
+ method_option :host, :aliases => "-h", :desc => "Specify a host"
7
+ method_option :port, :aliases => "-p", :desc => "Specify a port"
8
+ method_option :timeout, :aliases => "-t", :desc => "Specify a timeout"
9
+
10
+ default_task :list_keys
11
+
12
+ def list_keys
13
+ @options = default_options.merge(options || {})
14
+
15
+ headings = %w(id expires bytes cache_key)
16
+ rows = []
17
+
18
+ longest_key_len = 0
19
+ slabs.each do |slab|
20
+ localhost.cmd("String" => "stats cachedump #{slab['id']} #{slab['items']}", "Match" => /^END/) do |c|
21
+ c.scan(/^ITEM (.+?) \[(\d+) b; (\d+) s\]$/).each do |key_data|
22
+ cache_key, bytes, expires_time = key_data
23
+ rows << [slab['id'], Time.at(expires_time.to_i), bytes, cache_key]
24
+ longest_key_len = [longest_key_len,cache_key.length].max
25
+ end
26
+ end
27
+ end
28
+
29
+ row_format = %Q(|%8s | %28s | %12s | %-#{longest_key_len}s |)
30
+ puts row_format%headings
31
+ rows.each{|row| puts row_format%row}
32
+
33
+ localhost.close
34
+ end
35
+
36
+ private
37
+ def default_options
38
+ { host: "localhost", port: 11211, timeout: 3 }
39
+ end
40
+
41
+ def localhost
42
+ @localhost ||= Net::Telnet::new("Host" => @options[:host], "Port" => @options[:port], "Timeout" => @options[:timeout])
43
+ end
44
+
45
+ def slabs
46
+ matches.inject([]) { |items, item| items << Hash[*['id','items'].zip(item).flatten]; items }
47
+ end
48
+
49
+ def matches
50
+ localhost.cmd("String" => "stats items", "Match" => /^END/).scan(/STAT items:(\d+):number (\d+)/)
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Memkeys
2
+ VERSION = "0.1.0"
3
+ end
data/memkeys.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/memkeys/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'memkeys'
6
+ s.version = Memkeys::VERSION
7
+
8
+ s.date = '2016-02-04'
9
+ s.summary = "Memcache key lister"
10
+ s.description = "A simple hello world gem"
11
+ s.authors = ["Mike Rogers "]
12
+ s.email = 'me@mikerogers.io'
13
+ s.homepage = 'http://rubygems.org/gems/memkeys'
14
+ s.license = 'MIT'
15
+
16
+ s.require_paths = ["lib"]
17
+ s.executables = ["memkeys"]
18
+ s.files = `git ls-files`.split($\)
19
+
20
+ s.add_runtime_dependency "thor", "~> 0.19"
21
+ s.add_runtime_dependency "net-telnet", "~> 0.1"
22
+ s.add_runtime_dependency "rspec", "~> 3.4"
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Memkeys do
4
+
5
+ let(:memkeys){ Memkeys.new }
6
+
7
+ context "With no keys in memcache" do
8
+ it "just returns the headings" do
9
+ pending
10
+
11
+ #expect(STDOUT).to receive(:puts).with("| id | expires | bytes | cache_key |")
12
+ #memkeys.list_keys
13
+ end
14
+ end
15
+
16
+ context "with keys in memcache" do
17
+ it "just returns the headings" do
18
+ pending
19
+
20
+ #expect(STDOUT).to receive(:puts).with("| id | expires | bytes | cache_key |")
21
+ #expect(STDOUT).to receive(:puts).with("| 26 | 2016-02-05 04:12:26 +0000 | 24647 | views/home/index/1 |")
22
+ #memkeys.list_keys
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'memkeys'
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ config.before(:each) do
13
+ # Clear all the memcache keys?
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memkeys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 'Mike Rogers '
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-telnet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: A simple hello world gem
56
+ email: me@mikerogers.io
57
+ executables:
58
+ - memkeys
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - README.md
65
+ - Rakefile
66
+ - bin/memkeys
67
+ - lib/memkeys.rb
68
+ - lib/memkeys/version.rb
69
+ - memkeys.gemspec
70
+ - spec/memkeys_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: http://rubygems.org/gems/memkeys
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Memcache key lister
96
+ test_files: []