Skip to content

Commit

Permalink
Added client_compression setting and passes it to driver is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Hannus committed Jun 15, 2016
1 parent b8c8909 commit a3051f3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ gemfiles/*.gemfile.lock
.ruby-version
spec/log
vendor/bundle
.idea
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ Post.consistency(:one).find_each { |post| puts post.title }

Both read and write consistency default to `QUORUM`.

### Compression ###

Cassandra supports [frame compression](http://datastax.github.io/ruby-driver/features/#compression),
which can give you a performance boost if your requests or responses are big. To enable it you can
specify `client_compression` to use in cequel.yaml.

```yaml
development:
host: '127.0.0.1'
port: 9042
keyspace: Blog
client_compression: :lz4
```

### ActiveModel Support ###

Cequel supports ActiveModel functionality, such as callbacks, validations,
Expand Down
4 changes: 4 additions & 0 deletions lib/cequel/metal/keyspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Keyspace
attr_reader :credentials
# @return [Hash] SSL Configuration options
attr_reader :ssl_config
# @return [Symbol] The client compression option
attr_reader :client_compression

#
# @!method write(statement, *bind_vars)
Expand Down Expand Up @@ -139,6 +141,7 @@ def configure(configuration = {})

@name = configuration[:keyspace]
@default_consistency = configuration[:default_consistency].try(:to_sym)
@client_compression = configuration[:client_compression].try(:to_sym)

# reset the connections
clear_active_connections!
Expand Down Expand Up @@ -284,6 +287,7 @@ def client_options
{hosts: hosts, port: port}.tap do |options|
options.merge!(credentials) if credentials
options.merge!(ssl_config) if ssl_config
options.merge!(compression: client_compression) if client_compression
end
end

Expand Down
12 changes: 12 additions & 0 deletions spec/examples/metal/keyspace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@
end
end

describe "#client_compression" do
let(:client_compression) { :lz4 }
let(:connect) do
Cequel.connect host: Cequel::SpecSupport::Helpers.host,
port: Cequel::SpecSupport::Helpers.port,
client_compression: client_compression
end
it "client compression settings get extracted correctly for sending to cluster" do
expect(connect.client_compression).to eq client_compression
end
end

describe "#execute" do
let(:statement) { "SELECT id FROM posts" }

Expand Down

0 comments on commit a3051f3

Please sign in to comment.