redi2casa 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 687c3c2c393c650329494de0b2b9768cef684f2f
4
- data.tar.gz: 91f6d292884b3270a5ec8be1ce40d904bc68d851
3
+ metadata.gz: 6d5b3420d36a8292cb6d06c1a4e0233731ad4446
4
+ data.tar.gz: 415d1260880d010fbd378cdc5d33d8c024b9719a
5
5
  SHA512:
6
- metadata.gz: 2e3b99361d8f29511f3d4d5a4a84045a5ff80ec0fe292480ef1924c7fe75dcc931510770a89865dd8dc6bbe73cfac54bf05c17400f3d96c96e79645b2bac784d
7
- data.tar.gz: c82d6e0646d02d0d9efe12be7c596cb19772afa6aaa20ac28a53f1709287fc227320f6554cca2144ac301b48cc58ce1b18ddb09c5122bfb2b1da541cf4613ebd
6
+ metadata.gz: b1c2e4898460665dda13bc1c6ceeb97e21089a9d19445eb3bd8244c7e9d8ef874db846cba4323795c325588d69bb4dd66119f3090872e1adaa96f73e575a6067
7
+ data.tar.gz: 8163288c905fa1845881c8b359c576d0a5a7c6fdf0164910faf6142b230ff4221232607899277c52b3588548d8346cf7ac7ee386aa15d13f5e888c84b000320c
data/Examples.md CHANGED
@@ -1,52 +1,51 @@
1
1
  r = Redi2casa.new([localhost], 'redi2casa')
2
2
 
3
-
4
- # Do not mix counters and non-counter values in a single Hash
3
+ ### Do not mix counters and non-counter values in a single Hash
5
4
 
6
5
  Hash - counters
7
6
  ---------------
8
7
 
9
- Increment: r.hicnrby "c", "e", 10
10
- r.hget "c", "e" => 10
11
- Decrement: r.hincrby "c", "e", -10
12
- r.hget "c", "e" => 0
13
- r.hincrby "c", "a", 100
8
+ Increment: r.hicnrby "c", "e", 10
9
+ r.hget "c", "e" => 10
10
+ Decrement: r.hincrby "c", "e", -10
11
+ r.hget "c", "e" => 0
12
+ r.hincrby "c", "a", 100
13
+ r.hgetall "c" => { "a" => 100, "e" => 0 }
14
14
 
15
- r.hgetall "c" => { "a" => 100, "e" => 0 }
15
+ ## r.hset does not work for counters as yet ##
16
16
 
17
- ## r.hset does not work for counters as yet ##
18
17
 
19
18
  Hash - Non-counters
20
19
  -------------------
21
-
22
- r.hset "a", "b", "hello_world"
23
- r.hset "a", "b", "bye_world"
24
- r.hget "a", "b" => "hello_world"
25
-
26
- r.hgetall "a" => {"a" => "hello_world", "b" => "bye_world"}
20
+
21
+ r.hset "a", "b", "hello_world"
22
+ r.hset "a", "b", "bye_world"
23
+ r.hget "a", "b" => "hello_world"
24
+
25
+ r.hgetall "a" => {"a" => "hello_world", "b" => "bye_world"}
27
26
 
28
27
  List
29
28
  -----
30
29
 
31
- r.lpush "a", "hello"
32
- r.lpush "a", "hello1"
33
- r.rpush "a", "hello3"
34
-
35
- r.lrange "a", 0, -1 => ["hello", "hello1", "hello3"]
36
- r.lpop "a" => "hello"
37
- r.lrange "a", 0, -1 => ["hello1", "hello3"]
38
-
39
- r.rpop "a" => "hello3"
40
- r.lrange "a", 0, -1 => ["hello1"]
30
+ r.lpush "a", "hello"
31
+ r.lpush "a", "hello1"
32
+ r.rpush "a", "hello3"
33
+
34
+ r.lrange "a", 0, -1 => ["hello", "hello1", "hello3"]
35
+ r.lpop "a" => "hello"
36
+ r.lrange "a", 0, -1 => ["hello1", "hello3"]
37
+
38
+ r.rpop "a" => "hello3"
39
+ r.lrange "a", 0, -1 => ["hello1"]
41
40
 
42
41
 
43
42
  Key-value pairs
44
43
  ---------------
45
-
46
- r.set "a", "welcome"
47
- r.get "a" => "welcome"
48
-
49
- r.setex "a", 10, "c"
50
- r.get "a" => "c"
51
- ### after 10 seconds
52
- r.get "a" => nil
44
+
45
+ r.set "a", "welcome"
46
+ r.get "a" => "welcome"
47
+
48
+ r.setex "a", 10, "c"
49
+ r.get "a" => "c"
50
+ ### after 10 seconds
51
+ r.get "a" => nil
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redi2casa (0.0.3)
4
+ redi2casa (0.0.4)
5
+ bitwise
5
6
  cql-rb
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ bitwise (0.6.0)
10
12
  cql-rb (1.1.1)
11
13
  rake (10.1.0)
12
14
 
data/cassandra_cli_cmds CHANGED
@@ -1 +1,2 @@
1
1
  create column family counters with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'CounterColumnType' and key_validation_class = 'UTF8Type';
2
+ create column family hashes with column_type = 'Standard' and comparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and key_validation_class = 'UTF8Type';
data/cqlsh_cmds CHANGED
@@ -1,6 +1,5 @@
1
- CREATE KEYSPACE redi2casa WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
1
+ create keyspace redi2casa WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
2
2
  use redi2casa;
3
- create table hashes(namespace text primary key, key map<text, text>);
4
3
  create table lists(namespace text primary key, values list<text>);
5
4
  create table keyvalue(key text primary key, value text);
6
- create table sets(key text primary key, value set<text>);
5
+ create table sets(key text primary key, members set<text>);
@@ -0,0 +1,9 @@
1
+ class Redi2casa
2
+ def hdel key, column1, type = "counter"
3
+ if type == "counter"
4
+ @db_conn.execute("delete from counters where key = '#{key}' and column1 = '#{column1}'")
5
+ elsif type == "hash"
6
+ @db_conn.execute("delete from hashes where key = '#{key}' and column1 = '#{column1}'")
7
+ end
8
+ end
9
+ end
@@ -1,11 +1,11 @@
1
1
  class Redi2casa
2
- def hget namespace, key, type = "counters"
2
+ def hget key, column1, type = "counter"
3
3
  if type.to_s == "hash"
4
- resp = @db_conn.execute("select key from hashes where namespace = '#{namespace}'")
5
- parse_response(resp, "key")
6
- elsif type.to_s == "counters"
7
- resp = @db_conn.execute("select value from counters where KEY='#{namespace}' and column1 = '#{key}'")
4
+ resp = @db_conn.execute("select value from hashes where key = '#{key}' and column1 = '#{column1}'")
8
5
  parse_response(resp, "value")
6
+ elsif type.to_s == "counter"
7
+ resp = @db_conn.execute("select value from counters where KEY='#{key}' and column1 = '#{column1}'")
8
+ parse_response(resp, "value").to_i
9
9
  end
10
10
  end
11
11
  end
@@ -1,11 +1,11 @@
1
1
  class Redi2casa
2
- def hgetall key, type = "counters"
3
- if type.to_s == "counters"
2
+ def hgetall key, type = "counter"
3
+ if type.to_s == "counter"
4
4
  response = @db_conn.execute("select * from counters where KEY='#{key}'")
5
5
  response.inject({}) {|hsh, entry| hsh[entry["column1"]] = entry["value"]; hsh}
6
6
  elsif type.to_s == "hash"
7
- resp = @db_conn.execute("select key from hashes where namespace = '#{key}'")
8
- parse_response(resp, "key")
7
+ response = @db_conn.execute("select * from hashes where key = '#{key}'")
8
+ response.inject({}) {|hsh, entry| hsh[entry["column1"]] = entry["value"]; hsh}
9
9
  end
10
10
  end
11
11
  end
@@ -1,6 +1,5 @@
1
1
  class Redi2casa
2
- def hincrby namespace, key, value = 1
3
- query = "update counters set value = value + #{value} where key='#{namespace}' and column1 = '#{key}'"
4
- @db_conn.execute(query)
2
+ def hincrby key, column1, value = 1
3
+ @db_conn.execute("update counters set value = value + #{value} where key='#{key}' and column1 = '#{column1}'")
5
4
  end
6
5
  end
@@ -0,0 +1,11 @@
1
+ class Redi2casa
2
+ def hkeys key, type = "counter"
3
+ if type.to_s == "counter"
4
+ response = @db_conn.execute("select column1 from counters where key = '#{key}'")
5
+ response.collect {|entry| entry["column1"]}
6
+ elsif type.to_s == "hash"
7
+ response = @db_conn.execute("select column1 from hashes where key = '#{key}'")
8
+ response.collect {|entry| entry["column1"]}
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ class Redi2casa
2
+ # Supports only hashes now
3
+ def hlen key
4
+ response = @db_conn.execute("select count(*) from hashes where key = '#{key}'")
5
+ parse_response(response, "count").to_i
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
- def hset namespace, key, value
3
- @db_conn.execute("UPDATE hashes SET key = key + {'#{key}' : '#{value}'} WHERE namespace = '#{namespace}'")
2
+ def hset key, column1, value
3
+ @db_conn.execute("UPDATE hashes SET value = '#{value}' WHERE column1 = '#{column1}' and key = '#{key}'")
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
- def sadd_with_expire( key, ttl, members)
2
+ def sadd_with_expire( key, ttl, *members)
3
3
  @db_conn.execute("update sets using ttl #{ttl} set members = members + {'#{members.join("','")}'} where key = '#{key}'")
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ class Redi2casa
2
+ def scard key
3
+ smembers(key).size
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Redi2casa
2
+ def sismember key, value
3
+ smembers(key).include?(value)
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  class Redi2casa
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/redi2casa.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "cql-rb"
22
+ spec.add_runtime_dependency "bitwise"
22
23
 
23
24
  spec.add_development_dependency "cql-rb"
24
25
  spec.add_development_dependency "bundler"
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - vireshas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-29 00:00:00.000000000 Z
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cql-rb
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bitwise
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: cql-rb
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -87,9 +101,12 @@ files:
87
101
  - lib/redi2casa.rb
88
102
  - lib/redi2casa/del.rb
89
103
  - lib/redi2casa/get.rb
104
+ - lib/redi2casa/hdel.rb
90
105
  - lib/redi2casa/hget.rb
91
106
  - lib/redi2casa/hgetall.rb
92
107
  - lib/redi2casa/hincrby.rb
108
+ - lib/redi2casa/hkeys.rb
109
+ - lib/redi2casa/hlen.rb
93
110
  - lib/redi2casa/hset.rb
94
111
  - lib/redi2casa/lpop.rb
95
112
  - lib/redi2casa/lpush.rb
@@ -99,8 +116,10 @@ files:
99
116
  - lib/redi2casa/rpush.rb
100
117
  - lib/redi2casa/sadd.rb
101
118
  - lib/redi2casa/sadd_with_expire.rb
119
+ - lib/redi2casa/scard.rb
102
120
  - lib/redi2casa/set.rb
103
121
  - lib/redi2casa/setex.rb
122
+ - lib/redi2casa/sismember.rb
104
123
  - lib/redi2casa/smembers.rb
105
124
  - lib/redi2casa/spop.rb
106
125
  - lib/redi2casa/srem.rb