redi2casa 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in redi2casa.gemspec
4
- gem "cassandra-cql", :git => "git@github.com:vireshas/cassandra-cql.git"
5
4
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redi2casa (0.0.3)
5
+ cql-rb
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ cql-rb (1.1.1)
11
+ rake (10.1.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler
18
+ cql-rb
19
+ rake
20
+ redi2casa!
data/README.md CHANGED
@@ -1,39 +1,29 @@
1
- # Redi2casa
2
-
3
- Redis datastructures using Cassandra
1
+ # Redi2casa <a href="http://badge.fury.io/rb/redi2casa"><img src="https://badge.fury.io/rb/redi2casa@2x.png" alt="Gem Version" height="18"></a>
2
+
3
+ Redis datastructures using Cassandra.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- gem "cassandra-cql", :git => "git://github.com/vireshas/cassandra-cql.git"
10
- gem "redi2casa", :git => "git://github.com/vireshas/redi2casa.git"
11
-
12
- And then execute:
7
+ $ gem install redi2casa
13
8
 
14
- $ bundle install
9
+ #### Configuring cassandra
15
10
 
16
- Or install it yourself as:
11
+ ###### You need to install cassandra-2.0.x (please follow these instructions, https://gist.github.com/vireshas/7462447)
17
12
 
18
- $ gem install redi2casa
13
+ From the cloned location execute:
14
+ cqlsh -f cqlsh_cmds --debug
15
+ cassandra-cli -k redi2casa -f cassandra_cli_cmds
19
16
 
20
17
  ## Usage
21
18
 
22
- #### configuring cassandra
23
-
24
- create namespace: CREATE KEYSPACE redi2casa WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
25
- cqlsh: create table sets(namespace text primary key, key map<text, text>);
26
- cassandra-cli: create column family counters with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'CounterColumnType' and key_validation_class = 'UTF8Type';
27
-
28
- ### Now you can
29
-
30
19
  require "redi2casa"
31
- r = Redi2casa.new "127.0.0.1:9160", {:keyspace => 'keyspace1'}
20
+ r = Redi2casa.new ["localhost"], 'redi2casa'
21
+
22
+ Available: [hset, hget, hincrby, lpush, ltrim, lpop, lrange, rpush, rpop]
32
23
 
33
- You should keep one thing in mind while using hget with hash!, you should explicitly mention that you are using hget with hash
34
-
24
+ You should be passing an extra param(hash) when you call hget to retrieve a hash
35
25
  r.hset "a", "b", "hello_world"
36
- r.hget "a", "b", "hash" #the last parameter is needed for hash
26
+ r.hget "a", "b", "hash" #the last parameter is needed at the moment
37
27
 
38
28
  You can find more examples here: https://gist.github.com/vireshas/99bc322cf0ac42fbf7ee
39
29
 
@@ -0,0 +1 @@
1
+ create column family counters with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'CounterColumnType' and key_validation_class = 'UTF8Type';
data/cqlsh_cmds ADDED
@@ -0,0 +1,4 @@
1
+ CREATE KEYSPACE redi2casa WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
2
+ use redi2casa;
3
+ create table hashes(namespace text primary key, key map<text, text>);
4
+ create table lists(namespace text primary key, values list<text>);
@@ -1,11 +1,11 @@
1
1
  class Redi2casa
2
2
  def hget namespace, key, type = "counters"
3
3
  if type.to_s == "hash"
4
- resp = @db_conn.execute("select * from sets where namespace = ?", namespace).fetch
5
- resp.nil? ? nil : resp.to_hash['key'][key]
4
+ resp = @db_conn.execute("select key from hashes where namespace = '#{namespace}'")
5
+ parse_response(resp, "key")
6
6
  elsif type.to_s == "counters"
7
- response = @db_conn.execute("select * from counters where KEY='#{namespace}' and column1 = '#{key}'")
8
- response.fetch {|entry| return entry.to_hash["value"]}
7
+ resp = @db_conn.execute("select value from counters where KEY='#{namespace}' and column1 = '#{key}'")
8
+ parse_response(resp, "value")
9
9
  end
10
10
  end
11
11
  end
@@ -2,12 +2,10 @@ class Redi2casa
2
2
  def hgetall key, type = "counters"
3
3
  if type.to_s == "counters"
4
4
  response = @db_conn.execute("select * from counters where KEY='#{key}'")
5
- hsh = {}
6
- response.fetch {|resp| entry = resp.to_hash; hsh[entry["column1"]] = entry["value"] }
7
- hsh
5
+ response.inject({}) {|hsh, entry| hsh[entry["column1"]] = entry["value"]; hsh}
8
6
  elsif type.to_s == "hash"
9
- resp = @db_conn.execute("select * from sets where namespace = ?", key).fetch
10
- resp.nil? ? nil : resp.to_hash['key']
7
+ resp = @db_conn.execute("select key from hashes where namespace = '#{key}'")
8
+ parse_response(resp, "key")
11
9
  end
12
10
  end
13
11
  end
@@ -1,6 +1,5 @@
1
1
  class Redi2casa
2
2
  def hset namespace, key, value
3
- hash = {key => value}
4
- @db_conn.execute("UPDATE sets SET key = key + ? WHERE namespace = ?", hash, namespace)
3
+ @db_conn.execute("UPDATE hashes SET key = key + {'#{key}' : '#{value}'} WHERE namespace = '#{namespace}'")
5
4
  end
6
5
  end
@@ -1,4 +1,5 @@
1
1
  class Redi2casa
2
+ #has a read modify write problem
2
3
  def lpop namespace
3
4
  resp = @db_conn.execute("select values from lists where namespace='#{namespace}'")
4
5
  values = []
@@ -1,3 +1,3 @@
1
1
  class Redi2casa
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/redi2casa.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  require "redi2casa/version"
2
- require "cassandra-cql"
2
+ require "cql"
3
+
3
4
  Gem.find_files("redi2casa/*.rb").each { |path| require path }
4
5
 
5
6
  class Redi2casa
6
- def initialize(host, keyspace)
7
- @db_conn = CassandraCQL::Database.new(host, keyspace)
7
+ def initialize(hosts, keyspace)
8
+ @db_conn = Cql::Client.connect(:hosts => hosts)
9
+ @db_conn.use(keyspace)
10
+ end
11
+
12
+ def parse_response(resp, key)
13
+ resp.map {|entry| entry[key].to_s }.first
8
14
  end
9
15
  end
data/redi2casa.gemspec CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency "cql-rb"
22
+
23
+ spec.add_development_dependency "cql-rb"
21
24
  spec.add_development_dependency "bundler"
22
25
  spec.add_development_dependency "rake"
23
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redi2casa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-12 00:00:00.000000000 Z
12
+ date: 2013-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cql-rb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: cql-rb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  - !ruby/object:Gem::Dependency
15
47
  name: bundler
16
48
  requirement: !ruby/object:Gem::Requirement
@@ -52,9 +84,12 @@ extra_rdoc_files: []
52
84
  files:
53
85
  - .gitignore
54
86
  - Gemfile
87
+ - Gemfile.lock
55
88
  - LICENSE.txt
56
89
  - README.md
57
90
  - Rakefile
91
+ - cassandra_cli_cmds
92
+ - cqlsh_cmds
58
93
  - lib/redi2casa.rb
59
94
  - lib/redi2casa/hget.rb
60
95
  - lib/redi2casa/hgetall.rb
@@ -83,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
118
  version: '0'
84
119
  segments:
85
120
  - 0
86
- hash: -990581828638707000
121
+ hash: 1475517929010687912
87
122
  required_rubygems_version: !ruby/object:Gem::Requirement
88
123
  none: false
89
124
  requirements:
@@ -92,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
127
  version: '0'
93
128
  segments:
94
129
  - 0
95
- hash: -990581828638707000
130
+ hash: 1475517929010687912
96
131
  requirements: []
97
132
  rubyforge_project:
98
133
  rubygems_version: 1.8.25