sensu-redis 0.1.16 → 1.0.0

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
  SHA1:
3
- metadata.gz: 1d7f07a6e071e7ae61e84a617d601bf50fcf9886
4
- data.tar.gz: c2f1fdbc495ed15aa2df1ac982b62c65b162dcfb
3
+ metadata.gz: 0dae25950d9ec8203bef3290d8adfde8b7f386f9
4
+ data.tar.gz: 16df8c052d883948fdb9f2da3ee7dfce403cebde
5
5
  SHA512:
6
- metadata.gz: 8937e06d6f251ae0c1a56810a7ec4708712ee4cfb4300c5adff3ae666cbf7550577ff45c6b86f8bb8d7737d15f423bb77510bb2252e78ac7538937c219153b47
7
- data.tar.gz: 37f29c2433f8cb5246c192124446e1b04f4716329aafe26626d3c1a07044388b780f27b82c6ffd12657d5aa01c80be7e492d75a490f8466cfd8502956ab6dcc6
6
+ metadata.gz: 5cad7ce7683b5413149f297a339b4810fa793a555d8c026f2a407c6d34d17176508b9293ab0d0097bf3e2009958be892b89f9186b7f17493ea21cbe16b66b5f3
7
+ data.tar.gz: 3d7aa804184980ba22272b93127bef236d5e684b91206c8e85e71ab38647a765daf6f68f1246a3f4d4035c541fe947acf3a78210040a843125d2ff50ea896358
data/.travis.yml CHANGED
@@ -1,4 +1,17 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.0
9
+ - 2.2.0
3
10
  - 2.2.3
4
- before_install: gem install bundler -v 1.10.6
11
+ - jruby-1.7.23
12
+ services:
13
+ - redis
14
+ notifications:
15
+ irc:
16
+ - "irc.freenode.net#sensu"
17
+ script: "bundle exec rspec . --tag ~sentinel"
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Heavy Water Operations, LLC.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,36 +1,38 @@
1
1
  # Sensu::Redis
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sensu/redis`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/sensu/sensu-redis.svg?branch=master)](https://travis-ci.org/sensu/sensu-redis)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ [![Code Climate](https://codeclimate.com/github/sensu/sensu-redis.png)](https://codeclimate.com/github/sensu/sensu-redis)
6
+ [![Code Climate Coverage](https://codeclimate.com/github/sensu/sensu-redis/coverage.png)](https://codeclimate.com/github/sensu/sensu-redis)
6
7
 
7
8
  ## Installation
8
9
 
9
10
  Add this line to your application's Gemfile:
10
11
 
11
- ```ruby
12
- gem 'sensu-redis'
13
- ```
12
+ gem 'sensu-redis'
14
13
 
15
14
  And then execute:
16
15
 
17
16
  $ bundle
18
17
 
19
- Or install it yourself as:
20
-
21
- $ gem install sensu-redis
22
-
23
18
  ## Usage
24
19
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
20
+ This library provides the Redis client, with Sentinel support, for
21
+ Sensu's components. It's documentation can be found
22
+ [here](http://rubydoc.info/github/sensu/sensu-redis/Sensu/Redis).
28
23
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+ ## Contributing
30
25
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+ Please do not submit a pull request to add features that Sensu does
27
+ not nor will not require.
32
28
 
33
- ## Contributing
29
+ 1. [Fork it](https://github.com/sensu/sensu-redis/fork)
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sensu-redis.
35
+ ## License
36
36
 
37
+ Sensu-Redis is released under the [MIT
38
+ license](https://raw.github.com/sensu/sensu-redis/master/LICENSE.txt).
@@ -113,23 +113,15 @@ module Sensu
113
113
  @connected = false
114
114
  end
115
115
 
116
- # Determine the byte size of a string.
117
- #
118
- # @param string [String]
119
- # @return [Integer] string byte size.
120
- def get_size(string)
121
- string.respond_to?(:bytesize) ? string.bytesize : string.size
122
- end
123
-
124
116
  # Send a Redis command using RESP multi bulk. This method sends
125
117
  # data to Redis using EM connection `send_data()`.
126
118
  #
127
119
  # @param [Array<Object>] *arguments
128
120
  def send_command_data(*arguments)
129
- data = "*#{arguments.size}#{DELIM}"
121
+ data = "*#{arguments.length}#{DELIM}"
130
122
  arguments.each do |value|
131
123
  value = value.to_s
132
- data << "$#{get_size(value)}#{DELIM}#{value}#{DELIM}"
124
+ data << "$#{value.bytesize}#{DELIM}#{value}#{DELIM}"
133
125
  end
134
126
  send_data(data)
135
127
  end
@@ -325,7 +317,7 @@ module Sensu
325
317
  # You can read about RESP @ http://redis.io/topics/protocol
326
318
  #
327
319
  # @param line [String]
328
- def parse_resp_line(line)
320
+ def parse_response_line(line)
329
321
  # Trim off the response type and delimiter (\r\n).
330
322
  response = line.slice(1..-3)
331
323
  # First character indicates response type.
@@ -335,11 +327,11 @@ module Sensu
335
327
  when PLUS # String, e.g. +OK
336
328
  dispatch_response(response)
337
329
  when DOLLAR # Bulk string, e.g. $3\r\nfoo\r\n
338
- response_size = Integer(response)
339
- if response_size == -1 # No data, return nil.
330
+ response_length = Integer(response)
331
+ if response_length == -1 # No data, return nil.
340
332
  dispatch_response(nil)
341
- elsif @buffer.size >= response_size + 2 # Complete data.
342
- dispatch_response(@buffer.slice!(0, response_size))
333
+ elsif @buffer.length >= response_length + 2 # Complete data.
334
+ dispatch_response(@buffer.slice!(0, response_length))
343
335
  @buffer.slice!(0,2) # Discard delimeter (\r\n).
344
336
  else # Incomplete, have data pushed back into buffer.
345
337
  return INCOMPLETE
@@ -367,7 +359,7 @@ module Sensu
367
359
  (@buffer ||= '') << data
368
360
  while index = @buffer.index(DELIM)
369
361
  line = @buffer.slice!(0, index+2)
370
- if parse_resp_line(line) == INCOMPLETE
362
+ if parse_response_line(line) == INCOMPLETE
371
363
  @buffer[0...0] = line
372
364
  break
373
365
  end
data/lib/sensu/redis.rb CHANGED
@@ -61,7 +61,7 @@ module Sensu
61
61
  end
62
62
  options[:host] ||= "127.0.0.1"
63
63
  options[:port] ||= 6379
64
- if options[:sentinels].is_a?(Array) && options[:sentinels].size > 0
64
+ if options[:sentinels].is_a?(Array) && options[:sentinels].length > 0
65
65
  connect_via_sentinel(options, &block)
66
66
  else
67
67
  connect_direct(options, &block)
data/sensu-redis.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-redis"
5
- spec.version = "0.1.16"
5
+ spec.version = "1.0.0"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu Redis client library"
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), "helpers")
2
+ require "sensu/redis/client"
3
+
4
+ describe "Sensu::Redis::Client" do
5
+ include Helpers
6
+
7
+ it "can connect to a redis instance" do
8
+ async_wrapper do
9
+ redis.callback do
10
+ expect(redis.connected?).to eq(true)
11
+ async_done
12
+ end
13
+ end
14
+ end
15
+
16
+ it "can do a modified multi/exec" do
17
+ async_wrapper do
18
+ redis.callback do
19
+ redis.multi
20
+ redis.set("foo", "bar")
21
+ redis.sadd("baz", "qux")
22
+ redis.smembers("baz")
23
+ redis.exec do |response|
24
+ expect(response).to eq(["qux"])
25
+ redis.get("foo") do |value|
26
+ expect(value).to eq("bar")
27
+ async_done
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
data/spec/helpers.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rspec"
2
2
  require "eventmachine"
3
+ require "sensu/redis/client"
3
4
 
4
5
  unless RUBY_VERSION < "1.9" || RUBY_PLATFORM =~ /java/
5
6
  require "codeclimate-test-reporter"
@@ -26,4 +27,8 @@ module Helpers
26
27
  def async_done
27
28
  EM.stop_event_loop
28
29
  end
30
+
31
+ def redis
32
+ @redis ||= EM.connect("127.0.0.1", 6379, Sensu::Redis::Client)
33
+ end
29
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -92,6 +92,7 @@ files:
92
92
  - ".gitignore"
93
93
  - ".travis.yml"
94
94
  - Gemfile
95
+ - LICENSE.txt
95
96
  - README.md
96
97
  - Rakefile
97
98
  - bin/console
@@ -102,6 +103,7 @@ files:
102
103
  - lib/sensu/redis/client/errors.rb
103
104
  - lib/sensu/redis/sentinel.rb
104
105
  - sensu-redis.gemspec
106
+ - spec/client_spec.rb
105
107
  - spec/helpers.rb
106
108
  - spec/redis_spec.rb
107
109
  homepage: https://github.com/sensu/sensu-redis
@@ -129,6 +131,6 @@ signing_key:
129
131
  specification_version: 4
130
132
  summary: The Sensu Redis client library
131
133
  test_files:
134
+ - spec/client_spec.rb
132
135
  - spec/helpers.rb
133
136
  - spec/redis_spec.rb
134
- has_rdoc: