redi2casa 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +3 -3
- data/lib/redi2casa/del.rb +7 -5
- data/lib/redi2casa/get.rb +2 -2
- data/lib/redi2casa/hdel.rb +1 -1
- data/lib/redi2casa/hget.rb +2 -2
- data/lib/redi2casa/hgetall.rb +2 -2
- data/lib/redi2casa/hincrby.rb +1 -1
- data/lib/redi2casa/hkeys.rb +5 -4
- data/lib/redi2casa/hlen.rb +5 -4
- data/lib/redi2casa/hmget.rb +1 -1
- data/lib/redi2casa/hset.rb +1 -1
- data/lib/redi2casa/lpop.rb +1 -1
- data/lib/redi2casa/lpush.rb +1 -1
- data/lib/redi2casa/lrange.rb +1 -1
- data/lib/redi2casa/ltrim.rb +3 -3
- data/lib/redi2casa/rpop.rb +1 -1
- data/lib/redi2casa/rpush.rb +1 -1
- data/lib/redi2casa/sadd.rb +1 -1
- data/lib/redi2casa/sadd_with_expire.rb +1 -1
- data/lib/redi2casa/set.rb +1 -1
- data/lib/redi2casa/set_bit.rb +1 -1
- data/lib/redi2casa/setex.rb +1 -1
- data/lib/redi2casa/smembers.rb +1 -1
- data/lib/redi2casa/srem.rb +1 -1
- data/lib/redi2casa/version.rb +1 -1
- data/lib/redi2casa/zadd.rb +1 -1
- data/lib/redi2casa/zrangebyscore.rb +2 -2
- data/lib/redi2casa/zrem.rb +4 -2
- data/lib/redi2casa/zscore.rb +1 -1
- data/lib/redi2casa.rb +4 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35b5e5cfc4873a689448142620660d1666616b8a
|
4
|
+
data.tar.gz: fb129440f8573bc3c27986ad89db70ff9f1dceb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a45ebd0bbedbf872526e0208c87172e7f28f736cbbf064bfb23baf39468bb0ab6bb5d0a1d1f6c06f4baa9d0091472c0b1cf4827b08ded1b51db7099305ac8d7e
|
7
|
+
data.tar.gz: b481b19b93d9a097e2ab2514e3158d1d0f6a457f807fb705804e50bf190549baa5865b7d005affdc5d5c209494308573f49382253ce5b015284c0615fb24c4e0
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
redi2casa
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p247
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
redi2casa (0.1.
|
4
|
+
redi2casa (0.1.5)
|
5
5
|
cql-rb
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
cql-rb (1.1.
|
10
|
+
cql-rb (1.1.3)
|
11
11
|
diff-lcs (1.2.5)
|
12
|
-
rake (10.1.
|
12
|
+
rake (10.1.1)
|
13
13
|
rspec (2.14.1)
|
14
14
|
rspec-core (~> 2.14.0)
|
15
15
|
rspec-expectations (~> 2.14.0)
|
data/lib/redi2casa/del.rb
CHANGED
@@ -4,15 +4,17 @@ class Redi2casa
|
|
4
4
|
if type == "counter"
|
5
5
|
raise RuntimeError.new("deleting counters is not supported")
|
6
6
|
elsif type == 'keyvalue'
|
7
|
-
execute
|
7
|
+
execute("delete from keyvalue where key = ?", key)
|
8
8
|
elsif type == 'hash'
|
9
|
-
execute
|
9
|
+
execute("delete from hashes where key = ?", key)
|
10
10
|
elsif type == 'list'
|
11
|
-
execute
|
11
|
+
execute("delete from lists where namespace = ?", key)
|
12
12
|
elsif type == 'set'
|
13
|
-
execute
|
13
|
+
execute("delete from sets where key = ?", key)
|
14
14
|
elsif type == 'sorted_set'
|
15
|
-
execute
|
15
|
+
execute("delete from sorted_sets where key = ?", key)
|
16
|
+
else
|
17
|
+
raise RuntimeError.new("Invalid type")
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
data/lib/redi2casa/get.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def get key, type = 'keyvalue'
|
3
3
|
if type == 'keyvalue'
|
4
|
-
resp = execute
|
4
|
+
resp = execute("select * from keyvalue where key = ?", key)
|
5
5
|
parse_response(resp, "value")
|
6
6
|
elsif type == 'counter'
|
7
7
|
# @ is a special column in counter used by incrby
|
8
|
-
resp = execute
|
8
|
+
resp = execute("select value from counters where KEY = ? and column1 = '@'", key)
|
9
9
|
parse_response(resp, "value").to_i
|
10
10
|
end
|
11
11
|
end
|
data/lib/redi2casa/hdel.rb
CHANGED
@@ -3,7 +3,7 @@ class Redi2casa
|
|
3
3
|
if type == "counter"
|
4
4
|
raise RuntimeError.new("deleting counters is not supported")
|
5
5
|
elsif type == "hash"
|
6
|
-
execute
|
6
|
+
execute("delete from hashes where key = ? and column1 = ?", key, column1)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/redi2casa/hget.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hget key, column1, type = "counter"
|
3
3
|
if type.to_s == "hash"
|
4
|
-
resp = execute
|
4
|
+
resp = execute("select value from hashes where key = ? and column1 = ?", key, column1)
|
5
5
|
parse_response(resp, "value")
|
6
6
|
elsif type.to_s == "counter"
|
7
|
-
resp = execute
|
7
|
+
resp = execute("select value from counters where key = ? and column1 = ?", key, column1)
|
8
8
|
parse_response(resp, "value").to_i
|
9
9
|
end
|
10
10
|
end
|
data/lib/redi2casa/hgetall.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hgetall key, type = "counter"
|
3
3
|
if type.to_s == "counter"
|
4
|
-
response = execute
|
4
|
+
response = 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
|
-
response = execute
|
7
|
+
response = execute("select * from hashes where KEY = ?", key)
|
8
8
|
response.inject({}) {|hsh, entry| hsh[entry["column1"]] = entry["value"]; hsh}
|
9
9
|
end
|
10
10
|
end
|
data/lib/redi2casa/hincrby.rb
CHANGED
data/lib/redi2casa/hkeys.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hkeys key, type = "counter"
|
3
3
|
if type.to_s == "counter"
|
4
|
-
response = execute
|
5
|
-
response.collect {|entry| entry["column1"]}
|
4
|
+
response = execute("select column1 from counters where key = ?", key)
|
6
5
|
elsif type.to_s == "hash"
|
7
|
-
response = execute
|
8
|
-
|
6
|
+
response = execute("select column1 from hashes where key = ?", key)
|
7
|
+
else
|
8
|
+
raise RuntimeError.new("Invalid type")
|
9
9
|
end
|
10
|
+
response.collect {|entry| entry["column1"]}
|
10
11
|
end
|
11
12
|
end
|
data/lib/redi2casa/hlen.rb
CHANGED
@@ -2,11 +2,12 @@ class Redi2casa
|
|
2
2
|
# Supports only hashes now
|
3
3
|
def hlen key, type = "hash"
|
4
4
|
if type == "hash"
|
5
|
-
response = execute
|
6
|
-
parse_response(response, "count").to_i
|
5
|
+
response = execute("select count(*) from hashes where key = ?", key)
|
7
6
|
elsif type == "counter"
|
8
|
-
response = execute
|
9
|
-
|
7
|
+
response = execute("select count(*) from counters where key = ?", key)
|
8
|
+
else
|
9
|
+
raise RuntimeError.new("Invalid type")
|
10
10
|
end
|
11
|
+
parse_response(response, "count").to_i
|
11
12
|
end
|
12
13
|
end
|
data/lib/redi2casa/hmget.rb
CHANGED
@@ -8,7 +8,7 @@ class Redi2casa
|
|
8
8
|
raise RuntimeError.new("invalid table")
|
9
9
|
end
|
10
10
|
|
11
|
-
resp = execute
|
11
|
+
resp = execute("select column1, value from #{table} where key = ? and column1 IN ?", key, column1s)
|
12
12
|
hash = {}
|
13
13
|
resp.each do |r|
|
14
14
|
hash[r["column1"]] = r["value"]
|
data/lib/redi2casa/hset.rb
CHANGED
data/lib/redi2casa/lpop.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
#has a read modify write problem
|
3
3
|
def lpop namespace
|
4
|
-
resp = execute
|
4
|
+
resp = execute("select values from lists where namespace = ?", namespace)
|
5
5
|
values = []
|
6
6
|
resp.each {|entry| values = entry.to_hash["values"]}
|
7
7
|
resp = values.shift
|
data/lib/redi2casa/lpush.rb
CHANGED
data/lib/redi2casa/lrange.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def lrange namespace, first, last
|
3
|
-
resp = execute
|
3
|
+
resp = execute("select values from lists where namespace = ?", namespace)
|
4
4
|
resp.each {|entry|
|
5
5
|
values = entry.to_hash["values"] || []
|
6
6
|
return values[first..last]
|
data/lib/redi2casa/ltrim.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def ltrim namespace, first, last
|
3
|
-
resp = execute
|
3
|
+
resp = execute("select values from lists where namespace = ?", namespace)
|
4
4
|
values = {}
|
5
5
|
resp.each {|entry| values = entry.to_hash["values"]}
|
6
6
|
values_count = values.count
|
@@ -17,11 +17,11 @@ class Redi2casa
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def lflush namespace
|
20
|
-
execute
|
20
|
+
execute("UPDATE lists SET values = [] WHERE namespace = ?", namespace)
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
def lrepush namespace, list
|
25
|
-
execute
|
25
|
+
execute("UPDATE lists SET values = ? WHERE namespace = ?", list, namespace)
|
26
26
|
end
|
27
27
|
end
|
data/lib/redi2casa/rpop.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def rpop namespace
|
3
|
-
resp = execute
|
3
|
+
resp = execute("select values from lists where namespace = ?", namespace)
|
4
4
|
values = []
|
5
5
|
resp.fetch {|entry| values = entry.to_hash["values"]}
|
6
6
|
resp = values.pop
|
data/lib/redi2casa/rpush.rb
CHANGED
data/lib/redi2casa/sadd.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def sadd_with_expire( key, ttl, *members)
|
3
|
-
execute
|
3
|
+
execute("update sets using ttl ? set members = members + ? where key = ?", ttl, members, key)
|
4
4
|
end
|
5
5
|
end
|
data/lib/redi2casa/set.rb
CHANGED
data/lib/redi2casa/set_bit.rb
CHANGED
data/lib/redi2casa/setex.rb
CHANGED
data/lib/redi2casa/smembers.rb
CHANGED
data/lib/redi2casa/srem.rb
CHANGED
data/lib/redi2casa/version.rb
CHANGED
data/lib/redi2casa/zadd.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
# Random text is an extra column added to make sure we have multiple entries with same key, score and value
|
3
3
|
def zadd key, score, value
|
4
|
-
execute
|
4
|
+
execute("insert into sorted_sets (key, score,value, random_text) values (?, ?, ?, ?)", key, score, value, Time.now.to_i.to_s)
|
5
5
|
end
|
6
6
|
end
|
@@ -2,9 +2,9 @@ class Redi2casa
|
|
2
2
|
# Ranges are exclusive
|
3
3
|
def zrangebyscore key, lower_limit, higher_limit = -1
|
4
4
|
if higher_limit == -1
|
5
|
-
resp = execute
|
5
|
+
resp = execute("select value from sorted_sets where key = ? and score > ?", key, lower_limit)
|
6
6
|
else
|
7
|
-
resp = execute
|
7
|
+
resp = execute("select value from sorted_sets where key = ? and score > ? and score < ?", key, lower_limit, higher_limit)
|
8
8
|
end
|
9
9
|
resp.collect do |entry|
|
10
10
|
entry['value']
|
data/lib/redi2casa/zrem.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def zrem key, member
|
3
|
-
resp = execute
|
3
|
+
resp = execute("select * from sorted_sets where key = ?", key)
|
4
4
|
resp.each do |entry|
|
5
|
-
|
5
|
+
if entry['value'] == member.to_s
|
6
|
+
execute("delete from sorted_sets where key = ? and score = ? and value = ?", key, entry['score'], entry['value'])
|
7
|
+
end
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
data/lib/redi2casa/zscore.rb
CHANGED
data/lib/redi2casa.rb
CHANGED
@@ -21,16 +21,17 @@ class Redi2casa
|
|
21
21
|
resp.map {|entry| entry[key].to_s }.first
|
22
22
|
end
|
23
23
|
|
24
|
-
def execute
|
24
|
+
def execute base_query, *args
|
25
25
|
@failed ||= 0
|
26
|
-
@db_conn.
|
26
|
+
statement = @db_conn.prepare(base_query)
|
27
|
+
statement.execute(*args)
|
27
28
|
rescue Cql::NotConnectedError, Cql::Io::ConnectionError, Cql::Io::ConnectionTimeoutError
|
28
29
|
reconnect
|
29
30
|
@failed += 1
|
30
31
|
retry if @failed < 3
|
31
32
|
raise
|
32
33
|
rescue Cql::QueryError
|
33
|
-
raise Redi2casaError.new("Cql::QueryError query:#{
|
34
|
+
raise Redi2casaError.new("Cql::QueryError query:#{base_query}, args: #{args.inspect}")
|
34
35
|
ensure
|
35
36
|
@failed = 0
|
36
37
|
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.1.
|
4
|
+
version: 0.1.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: 2014-01-
|
12
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cql-rb
|
@@ -75,6 +75,8 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
|
+
- .ruby-gemset
|
79
|
+
- .ruby-version
|
78
80
|
- Changes.md
|
79
81
|
- Examples.md
|
80
82
|
- Gemfile
|