redi2casa 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -18
- data/lib/redi2casa/hget.rb +1 -1
- data/lib/redi2casa/hgetall.rb +1 -1
- data/lib/redi2casa/hincrby.rb +1 -1
- data/lib/redi2casa/lpop.rb +10 -0
- data/lib/redi2casa/lpush.rb +5 -0
- data/lib/redi2casa/lrange.rb +6 -0
- data/lib/redi2casa/ltrim.rb +26 -0
- data/lib/redi2casa/rpop.rb +10 -0
- data/lib/redi2casa/rpush.rb +5 -0
- data/lib/redi2casa/version.rb +1 -1
- metadata +11 -5
data/README.md
CHANGED
@@ -6,7 +6,8 @@ Redis datastructures using Cassandra
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem
|
9
|
+
gem "cassandra-cql", :git => "git://github.com/vireshas/cassandra-cql.git"
|
10
|
+
gem "redi2casa", :git => "git://github.com/vireshas/redi2casa.git"
|
10
11
|
|
11
12
|
And then execute:
|
12
13
|
|
@@ -17,29 +18,24 @@ Or install it yourself as:
|
|
17
18
|
$ gem install redi2casa
|
18
19
|
|
19
20
|
## Usage
|
20
|
-
|
21
|
+
|
22
|
+
#### configuring cassandra
|
23
|
+
|
24
|
+
create namespace: CREATE KEYSPACE redi2casa WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
|
21
25
|
cqlsh: create table sets(namespace text primary key, key map<text, text>);
|
22
26
|
cassandra-cli: create column family counters with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'CounterColumnType' and key_validation_class = 'UTF8Type';
|
23
|
-
|
27
|
+
|
24
28
|
### Now you can
|
25
|
-
require "redi2casa"
|
26
|
-
r = Redi2casa.new "127.0.0.1:9160", {:keyspace => 'keyspace1'}
|
27
|
-
|
28
|
-
#### hincrby & hget
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
r.hget "c", "e", "counters"
|
33
|
-
|
34
|
-
#### hset & hget
|
30
|
+
require "redi2casa"
|
31
|
+
r = Redi2casa.new "127.0.0.1:9160", {:keyspace => 'keyspace1'}
|
35
32
|
|
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
|
+
|
36
35
|
r.hset "a", "b", "hello_world"
|
37
|
-
r.hget "a", "b", "
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
r.hgetall "c", "counters"
|
42
|
-
r.hgetall "a", "sets"
|
36
|
+
r.hget "a", "b", "hash" #the last parameter is needed for hash
|
37
|
+
|
38
|
+
You can find more examples here: https://gist.github.com/vireshas/99bc322cf0ac42fbf7ee
|
43
39
|
|
44
40
|
## Contributing
|
45
41
|
|
data/lib/redi2casa/hget.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hget namespace, key, type = "counters"
|
3
|
-
if type.to_s == "
|
3
|
+
if type.to_s == "hash"
|
4
4
|
resp = @db_conn.execute("select * from sets where namespace = ?", namespace).fetch
|
5
5
|
resp.nil? ? nil : resp.to_hash['key'][key]
|
6
6
|
elsif type.to_s == "counters"
|
data/lib/redi2casa/hgetall.rb
CHANGED
@@ -5,7 +5,7 @@ class Redi2casa
|
|
5
5
|
hsh = {}
|
6
6
|
response.fetch {|resp| entry = resp.to_hash; hsh[entry["column1"]] = entry["value"] }
|
7
7
|
hsh
|
8
|
-
elsif type.to_s == "
|
8
|
+
elsif type.to_s == "hash"
|
9
9
|
resp = @db_conn.execute("select * from sets where namespace = ?", key).fetch
|
10
10
|
resp.nil? ? nil : resp.to_hash['key']
|
11
11
|
end
|
data/lib/redi2casa/hincrby.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
class Redi2casa
|
2
|
+
def lpop namespace
|
3
|
+
resp = @db_conn.execute("select values from lists where namespace='#{namespace}'")
|
4
|
+
values = []
|
5
|
+
resp.fetch {|entry| values = entry.to_hash["values"]}
|
6
|
+
resp = values.shift
|
7
|
+
lrepush(namespace, values)
|
8
|
+
resp
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Redi2casa
|
2
|
+
def ltrim namespace, first, last
|
3
|
+
resp = @db_conn.execute("select values from lists where namespace='#{namespace}'")
|
4
|
+
values = {}
|
5
|
+
resp.fetch {|entry| values = entry.to_hash["values"]}
|
6
|
+
values_count = values.count
|
7
|
+
#if first is greater than list length, redis returns empty list
|
8
|
+
#if negative value of last is equal or greater than list length a similar behaviour is shown
|
9
|
+
if (first > values_count) || (-last >= values_count)
|
10
|
+
lflush(namespace)
|
11
|
+
elsif last > values_count
|
12
|
+
last = values_count
|
13
|
+
else
|
14
|
+
new_list = values[first..last]
|
15
|
+
lrepush(namespace, new_list)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def lflush namespace
|
20
|
+
@db_conn.execute("UPDATE lists SET values = [] WHERE namespace = '#{namespace}'")
|
21
|
+
end
|
22
|
+
|
23
|
+
def lrepush namespace, list
|
24
|
+
@db_conn.execute("UPDATE lists SET values = [?] WHERE namespace = '#{namespace}'", list)
|
25
|
+
end
|
26
|
+
end
|
data/lib/redi2casa/version.rb
CHANGED
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -60,6 +60,12 @@ files:
|
|
60
60
|
- lib/redi2casa/hgetall.rb
|
61
61
|
- lib/redi2casa/hincrby.rb
|
62
62
|
- lib/redi2casa/hset.rb
|
63
|
+
- lib/redi2casa/lpop.rb
|
64
|
+
- lib/redi2casa/lpush.rb
|
65
|
+
- lib/redi2casa/lrange.rb
|
66
|
+
- lib/redi2casa/ltrim.rb
|
67
|
+
- lib/redi2casa/rpop.rb
|
68
|
+
- lib/redi2casa/rpush.rb
|
63
69
|
- lib/redi2casa/version.rb
|
64
70
|
- redi2casa.gemspec
|
65
71
|
homepage: https://github.com/vireshas/redi2casa
|
@@ -77,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
83
|
version: '0'
|
78
84
|
segments:
|
79
85
|
- 0
|
80
|
-
hash: -
|
86
|
+
hash: -990581828638707000
|
81
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
88
|
none: false
|
83
89
|
requirements:
|
@@ -86,10 +92,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
92
|
version: '0'
|
87
93
|
segments:
|
88
94
|
- 0
|
89
|
-
hash: -
|
95
|
+
hash: -990581828638707000
|
90
96
|
requirements: []
|
91
97
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.8.
|
98
|
+
rubygems_version: 1.8.25
|
93
99
|
signing_key:
|
94
100
|
specification_version: 3
|
95
101
|
summary: Moving redis calls to equivalent cassandra calls can be a pain unless you
|