From a3051f391bb333dc1f858d5a66bddaa846520dec Mon Sep 17 00:00:00 2001 From: Justin Hannus Date: Tue, 7 Jun 2016 16:20:28 -0400 Subject: [PATCH] Added client_compression setting and passes it to driver is set --- .gitignore | 1 + README.md | 14 ++++++++++++++ lib/cequel/metal/keyspace.rb | 4 ++++ spec/examples/metal/keyspace_spec.rb | 12 ++++++++++++ 4 files changed, 31 insertions(+) diff --git a/.gitignore b/.gitignore index 1874c4e8..bd52a5da 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ gemfiles/*.gemfile.lock .ruby-version spec/log vendor/bundle +.idea diff --git a/README.md b/README.md index af0d8a80..6a50577b 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/lib/cequel/metal/keyspace.rb b/lib/cequel/metal/keyspace.rb index 6bf054ec..6be0860b 100644 --- a/lib/cequel/metal/keyspace.rb +++ b/lib/cequel/metal/keyspace.rb @@ -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) @@ -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! @@ -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 diff --git a/spec/examples/metal/keyspace_spec.rb b/spec/examples/metal/keyspace_spec.rb index 85ff3b97..09e70d05 100644 --- a/spec/examples/metal/keyspace_spec.rb +++ b/spec/examples/metal/keyspace_spec.rb @@ -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" }