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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e43c9e712abbadf2d40c505753886fce924bdecf
4
- data.tar.gz: 9e42990c5fcae1788120a943a916ce3fb56106a4
3
+ metadata.gz: 35b5e5cfc4873a689448142620660d1666616b8a
4
+ data.tar.gz: fb129440f8573bc3c27986ad89db70ff9f1dceb1
5
5
  SHA512:
6
- metadata.gz: 777f367a89886b87f333b1db07ba3dbd53eb21db75811b40b04dec5931c07d7b7ede74b638bcda6b91046e47b3d6a341eb398bea77e190e3eb35eeb20a0cf4c9
7
- data.tar.gz: 66495e184f84d9b55362d369525ed6cdfe5e56414e9a638f6f02fdd8dedbae24ac7a3165a524b27b1737b06c7b052d31fc6df141a0c6ed3eda47fd6f97ba6e1c
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.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.2)
10
+ cql-rb (1.1.3)
11
11
  diff-lcs (1.2.5)
12
- rake (10.1.0)
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 "delete from keyvalue where key = '#{key}'"
7
+ execute("delete from keyvalue where key = ?", key)
8
8
  elsif type == 'hash'
9
- execute "delete from hashes where key = '#{key}'"
9
+ execute("delete from hashes where key = ?", key)
10
10
  elsif type == 'list'
11
- execute "delete from lists where namespace = '#{key}'"
11
+ execute("delete from lists where namespace = ?", key)
12
12
  elsif type == 'set'
13
- execute "delete from sets where key = '#{key}'"
13
+ execute("delete from sets where key = ?", key)
14
14
  elsif type == 'sorted_set'
15
- execute "delete from sorted_sets where key = '#{key}'"
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 "select * from keyvalue where key = '#{key}'"
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 "select value from counters where KEY='#{key}' and column1 = '@'"
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
@@ -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 "delete from hashes where key = '#{key}' and column1 = '#{column1}'"
6
+ execute("delete from hashes where key = ? and column1 = ?", key, column1)
7
7
  end
8
8
  end
9
9
  end
@@ -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 "select value from hashes where key = '#{key}' and column1 = '#{column1}'"
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 "select value from counters where KEY='#{key}' and column1 = '#{column1}'"
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
@@ -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 "select * from counters where KEY='#{key}'"
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 "select * from hashes where key = '#{key}'"
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
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def hincrby key, column1, value = 1
3
- execute "update counters set value = value + #{value} where key='#{key}' and column1 = '#{column1}'"
3
+ execute("update counters set value = value + ? where key=? and column1 = ?", value, key, column1)
4
4
  end
5
5
  end
@@ -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 "select column1 from counters where key = '#{key}'"
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 "select column1 from hashes where key = '#{key}'"
8
- response.collect {|entry| entry["column1"]}
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
@@ -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 "select count(*) from hashes where key = '#{key}'"
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 "select count(*) from counters where key = '#{key}'"
9
- parse_response(response, "count").to_i
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
@@ -8,7 +8,7 @@ class Redi2casa
8
8
  raise RuntimeError.new("invalid table")
9
9
  end
10
10
 
11
- resp = execute "select column1, value from #{table} where key = '#{key}' and column1 IN ('#{column1s.join("','")}')"
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"]
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def hset key, column1, value
3
- execute "UPDATE hashes SET value = '#{value}' WHERE column1 = '#{column1}' and key = '#{key}'"
3
+ execute("UPDATE hashes SET value = ? WHERE column1 = ? and key = ?", value, column1, key)
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  class Redi2casa
2
2
  #has a read modify write problem
3
3
  def lpop namespace
4
- resp = execute "select values from lists where namespace='#{namespace}'"
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
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def lpush namespace, data
3
- execute "UPDATE lists SET values = ['#{data}'] + values WHERE namespace = '#{namespace}'"
3
+ execute("UPDATE lists SET values = ? + values WHERE namespace = ?", [ data], namespace)
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  class Redi2casa
2
2
  def lrange namespace, first, last
3
- resp = execute "select values from lists where namespace='#{namespace}'"
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]
@@ -1,6 +1,6 @@
1
1
  class Redi2casa
2
2
  def ltrim namespace, first, last
3
- resp = execute "select values from lists where namespace='#{namespace}'"
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 "UPDATE lists SET values = [] WHERE namespace = '#{namespace}'"
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 "UPDATE lists SET values = ['#{list.join("','")}'] WHERE namespace = '#{namespace}'"
25
+ execute("UPDATE lists SET values = ? WHERE namespace = ?", list, namespace)
26
26
  end
27
27
  end
@@ -1,6 +1,6 @@
1
1
  class Redi2casa
2
2
  def rpop namespace
3
- resp = execute "select values from lists where namespace='#{namespace}'"
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
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def rpush namespace, data
3
- execute "UPDATE lists SET values = values + ['#{data}'] WHERE namespace = '#{namespace}'"
3
+ execute("UPDATE lists SET values = values + [?] WHERE namespace = ?", data, namespace)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def sadd key, *members
3
- execute "update sets set members = members + {'#{members.join("','")}'} where key = '#{key}'"
3
+ execute("update sets set members = members + ? where key = ?", members, key)
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def sadd_with_expire( key, ttl, *members)
3
- execute "update sets using ttl #{ttl} set members = members + {'#{members.join("','")}'} where key = '#{key}'"
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
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def set key, value
3
- execute "UPDATE keyvalue set value = '#{value}' where key = '#{key}'"
3
+ execute("UPDATE keyvalue set value = ? where key = ?", value, key)
4
4
  end
5
5
  end
@@ -4,7 +4,7 @@ class Redi2casa
4
4
  if !(bit != 0 || bit != 1)
5
5
  raise RuntimeError.new("Invalid bit")
6
6
  end
7
- hset("#{key}","#{offset}", bit)
7
+ hset("#{key}","#{offset}", bit.to_s)
8
8
  end
9
9
  alias :setbit :set_bit
10
10
  end
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def setex key, ttl, value
3
- execute "UPDATE keyvalue using TTL #{ttl} set value = '#{value}' where key = '#{key}'"
3
+ execute("UPDATE keyvalue using TTL ? set value = ? where key = ?", ttl, value, key)
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  class Redi2casa
2
2
  def smembers key
3
- resp = execute "select * from sets where key = '#{key}'"
3
+ resp = execute("select * from sets where key = ?", key)
4
4
  if resp.first
5
5
  resp.first["members"].to_a
6
6
  else
@@ -1,5 +1,5 @@
1
1
  class Redi2casa
2
2
  def srem key, member
3
- execute "update sets set members = members - {'#{member}'} where key = '#{key}'"
3
+ execute("update sets set members = members - {'#{member}'} where key = ?", key)
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  class Redi2casa
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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 "insert into sorted_sets (key, score,value, random_text) values ('#{key}',#{score}, '#{value}', '#{Time.now.to_i}')"
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 "select value from sorted_sets where key = '#{key}' and score > #{lower_limit}"
5
+ resp = execute("select value from sorted_sets where key = ? and score > ?", key, lower_limit)
6
6
  else
7
- resp = execute "select value from sorted_sets where key = '#{key}' and score > #{lower_limit} and score < #{higher_limit}"
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']
@@ -1,8 +1,10 @@
1
1
  class Redi2casa
2
2
  def zrem key, member
3
- resp = execute "select * from sorted_sets where key = '#{key}'"
3
+ resp = execute("select * from sorted_sets where key = ?", key)
4
4
  resp.each do |entry|
5
- execute "delete from sorted_sets where key = '#{key}' and score = #{entry['score']} and value = '#{entry['value']}'" if entry['value'] == member.to_s
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
@@ -1,6 +1,6 @@
1
1
  class Redi2casa
2
2
  def zscore key, value
3
- resp = execute "select * from sorted_sets where key = '#{key}'"
3
+ resp = execute("select * from sorted_sets where key = ?", key)
4
4
  resp.each do |entry|
5
5
  return entry['score'] if entry['value'] == value.to_s
6
6
  end
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 query
24
+ def execute base_query, *args
25
25
  @failed ||= 0
26
- @db_conn.execute query
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:#{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
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-06 00:00:00.000000000 Z
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