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 +0 -1
- data/Gemfile.lock +20 -0
- data/README.md +14 -24
- data/cassandra_cli_cmds +1 -0
- data/cqlsh_cmds +4 -0
- data/lib/redi2casa/hget.rb +4 -4
- data/lib/redi2casa/hgetall.rb +3 -5
- data/lib/redi2casa/hset.rb +1 -2
- data/lib/redi2casa/lpop.rb +1 -0
- data/lib/redi2casa/version.rb +1 -1
- data/lib/redi2casa.rb +9 -3
- data/redi2casa.gemspec +3 -0
- metadata +39 -4
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
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
|
-
|
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
|
-
|
9
|
+
#### Configuring cassandra
|
15
10
|
|
16
|
-
|
11
|
+
###### You need to install cassandra-2.0.x (please follow these instructions, https://gist.github.com/vireshas/7462447)
|
17
12
|
|
18
|
-
|
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 "
|
20
|
+
r = Redi2casa.new ["localhost"], 'redi2casa'
|
21
|
+
|
22
|
+
Available: [hset, hget, hincrby, lpush, ltrim, lpop, lrange, rpush, rpop]
|
32
23
|
|
33
|
-
|
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
|
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
|
|
data/cassandra_cli_cmds
ADDED
@@ -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
data/lib/redi2casa/hget.rb
CHANGED
@@ -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
|
5
|
-
resp
|
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
|
-
|
8
|
-
|
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
|
data/lib/redi2casa/hgetall.rb
CHANGED
@@ -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
|
10
|
-
resp
|
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
|
data/lib/redi2casa/hset.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hset namespace, key, value
|
3
|
-
|
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
|
data/lib/redi2casa/lpop.rb
CHANGED
data/lib/redi2casa/version.rb
CHANGED
data/lib/redi2casa.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
require "redi2casa/version"
|
2
|
-
require "
|
2
|
+
require "cql"
|
3
|
+
|
3
4
|
Gem.find_files("redi2casa/*.rb").each { |path| require path }
|
4
5
|
|
5
6
|
class Redi2casa
|
6
|
-
def initialize(
|
7
|
-
@db_conn =
|
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.
|
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
|
+
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:
|
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:
|
130
|
+
hash: 1475517929010687912
|
96
131
|
requirements: []
|
97
132
|
rubyforge_project:
|
98
133
|
rubygems_version: 1.8.25
|