nchan_tools 0.1.6 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07a8230e83733a4948ee9cc9df50eea8b698f2762e7f70a054f9708c98bb7ea1
4
- data.tar.gz: 16ab41364f02c7996441a8f461bd969d9c11af023936e64f0be1f912f81ece88
3
+ metadata.gz: 65a7cdf81145f3dde05ac13e82dc9dcc09063eff263ec642a6b9e3682db033d1
4
+ data.tar.gz: 5d8d9ff2c06a5ebd982a123be59a3ed13310b99c7daa869e86e30832f69ee509
5
5
  SHA512:
6
- metadata.gz: 8f2f505b79a22588f37f38f12aa0c461cf5d9db9f3c89375f6a70a9a0df3b8a62f2b778425fbb71bc4b7eb9b8b4fdf275c08cf365dd9d89b57e5396ed5312e1e
7
- data.tar.gz: 6c4bfe8a215370d37319144375b633bbbb868d1f50ac4dc1f6c2736dce057f78edd30e3995d7be34a5534d80f0ee4cd50f5d0633b63da085c28620c24751a979
6
+ metadata.gz: b771ba51b4108c2c01805e06730590c79f5150180d62bad58662e7f6f6f1ed250257c94acf992274292195381262ca01164f249df147ba3eabd149f0ad730259
7
+ data.tar.gz: 5b422326b465e2df1f70315edad5dda73766c861aa18f4d65cbc64093bbf229a2a0845de7f207620751442e6a6b47887ebfd44f5002757ef2abf6c690220b0fe
@@ -4,32 +4,26 @@ require "redis"
4
4
  require "optparse"
5
5
  require 'nchan_tools/rdsck'
6
6
 
7
- $opt = {
7
+ opt = {
8
8
  url: "redis://127.0.0.1:6379/",
9
9
  verbose: false,
10
10
  command: nil
11
11
  }
12
12
 
13
- def dbg(...)
14
- if $opt[:verbose]
15
- print("# ")
16
- puts(...)
17
- end
18
- end
19
-
20
13
  opt_parser=OptionParser.new do |opts|
21
- opts.on("--url", "--url REDIS_URL (#{$opt[:url]})", "Redis server and port..") do |v|
22
- $opt[:url]=v
14
+ opts.on("--url", "--url REDIS_URL (#{opt[:url]})", "Redis server and port..") do |v|
15
+ opt[:url]=v
23
16
  end
24
17
  opts.on("-q", "--quiet", "output only results without any other information") do
25
- $opt[:quiet]=false
18
+ opt[:quiet]=false
19
+ opts[:verbose] = !opt[:quiet]
26
20
  end
27
21
  opts.on("--list-channels", "list all Nchan channels on Redis server or cluster") do |v|
28
- $opt[:command]=:filter_channels
22
+ opt[:command]=:filter_channels
29
23
  end
30
24
  opts.on("--filter-channels-min-subscribers=[NUMBER]") do |v|
31
- $opt[:command]=:filter_channels
32
- $opt[:min_subscribers]=v.to_i
25
+ opt[:command]=:filter_channels
26
+ opt[:min_subscribers]=v.to_i
33
27
  end
34
28
  end
35
29
  opt_parser.banner= <<~EOB
@@ -46,16 +40,16 @@ opt_parser.banner= <<~EOB
46
40
  EOB
47
41
  opt_parser.parse!
48
42
 
49
- rdsck = Rdsck.new $opt
43
+ rdsck = Rdsck.new opt
50
44
  if not rdsck.connect
51
- STDERR.puts "failed to connect to #{$opt[:url]}"
45
+ STDERR.puts "failed to connect to #{opt[:url]}"
52
46
  exit 1
53
47
  end
54
48
 
55
- case $opt[:command]
49
+ case opt[:command]
56
50
  when :filter_channels
57
- puts "# scanning for channels #{$opt[:min_subscribers] && "with subscribers >= #{$opt[:min_subscribers]}"}"
58
- chans = rdsck.filter_channels(min_subscribers: $opt[:min_subscribers])
51
+ puts "# scanning for channels #{opt[:min_subscribers] && "with subscribers >= #{opt[:min_subscribers]}"}"
52
+ chans = rdsck.filter_channels(min_subscribers: opt[:min_subscribers])
59
53
  puts "# found #{chans.count} channel#{chans.count != 1 && "s"}#{chans.count == 0 ? "." : ":"}"
60
54
  puts chans.join("\n")
61
55
  else
@@ -1,10 +1,19 @@
1
1
  class Rdsck
2
2
  attr_accessor :url, :verbose, :namespace
3
3
  attr_accessor :redis, :masters
4
+
5
+ def dbg(*args)
6
+ if @verbose
7
+ print("# ")
8
+ puts(*args)
9
+ end
10
+ end
11
+
4
12
  def initialize(opt)
5
13
  @url=opt[:url]
6
14
  @verbose=opt[:verbose]
7
15
  @namespace=opt[:namespace]
16
+ @channel_id=opt[:channel_id]
8
17
  end
9
18
 
10
19
  def cluster?
@@ -13,7 +22,8 @@ class Rdsck
13
22
 
14
23
  def connect
15
24
  begin
16
- @redis=Redis.new url: $opt[:url]
25
+ puts "connect to #{@url}"
26
+ @redis=Redis.new url: @url
17
27
  mode = redis.info["redis_mode"]
18
28
  rescue StandardError => e
19
29
  STDERR.puts e.message
@@ -23,7 +33,8 @@ class Rdsck
23
33
  if mode == "cluster"
24
34
  @redis.close
25
35
  begin
26
- @redis=Redis.new cluster: [$opt[:url]]
36
+ puts "cluster-connect to #{@url}"
37
+ @redis=Redis.new cluster: [@url]
27
38
  @redis.ping
28
39
  rescue StandardError => e
29
40
  STDERR.puts e.message
@@ -49,7 +60,7 @@ class Rdsck
49
60
  end
50
61
 
51
62
  def key(subkey=nil)
52
- k = "{channel:#{$opt[:namespace]}/#{$opt[:channel_id]}}"
63
+ k = "{channel:#{@namespace}/#{@channel_id}}"
53
64
  return subkey ? "#{k}:#{subkey}" : k
54
65
  end
55
66
 
@@ -90,7 +101,7 @@ class Rdsck
90
101
  EOF
91
102
 
92
103
  results = []
93
- batch_size=2
104
+ batch_size=500
94
105
  masters.each do |m|
95
106
  hash = m.script "load", script
96
107
  cursor, pattern = "0", "{channel:*}"
@@ -1,3 +1,3 @@
1
1
  module NchanTools
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "celluloid"
30
30
  spec.add_dependency "celluloid-io"
31
31
  spec.add_dependency "HDRHistogram"
32
+ spec.add_dependency "redis", "~>4.2.0"
32
33
 
33
34
  spec.add_dependency "websocket-driver"
34
35
  spec.add_dependency 'websocket-extensions'
@@ -38,6 +39,6 @@ Gem::Specification.new do |spec|
38
39
  spec.add_dependency 'http-2'
39
40
  end
40
41
  spec.add_development_dependency "pry"
41
- spec.add_development_dependency "bundler", "~> 1.16"
42
- spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "bundler"
43
+ spec.add_development_dependency "rake"
43
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nchan_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Ponomarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redis
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.2.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.2.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: websocket-driver
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -182,30 +196,30 @@ dependencies:
182
196
  name: bundler
183
197
  requirement: !ruby/object:Gem::Requirement
184
198
  requirements:
185
- - - "~>"
199
+ - - ">="
186
200
  - !ruby/object:Gem::Version
187
- version: '1.16'
201
+ version: '0'
188
202
  type: :development
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
- - - "~>"
206
+ - - ">="
193
207
  - !ruby/object:Gem::Version
194
- version: '1.16'
208
+ version: '0'
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: rake
197
211
  requirement: !ruby/object:Gem::Requirement
198
212
  requirements:
199
- - - "~>"
213
+ - - ">="
200
214
  - !ruby/object:Gem::Version
201
- version: '10.0'
215
+ version: '0'
202
216
  type: :development
203
217
  prerelease: false
204
218
  version_requirements: !ruby/object:Gem::Requirement
205
219
  requirements:
206
- - - "~>"
220
+ - - ">="
207
221
  - !ruby/object:Gem::Version
208
- version: '10.0'
222
+ version: '0'
209
223
  description: publishing, subscribing, testing, and benchmarking utilities for Nchan.
210
224
  email:
211
225
  - leo@nchan.io