redi2casa 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -3
- data/lib/.DS_Store +0 -0
- data/lib/redi2casa/del.rb +5 -5
- data/lib/redi2casa/get.rb +2 -2
- data/lib/redi2casa/hdel.rb +2 -2
- 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 +2 -2
- data/lib/redi2casa/hlen.rb +2 -2
- data/lib/redi2casa/hmget.rb +1 -1
- data/lib/redi2casa/hset.rb +1 -1
- data/lib/redi2casa/keys.rb +5 -0
- data/lib/redi2casa/lpop.rb +2 -2
- data/lib/redi2casa/lpush.rb +1 -1
- data/lib/redi2casa/lrange.rb +5 -2
- data/lib/redi2casa/ltrim.rb +5 -4
- 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/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 +3 -2
- data/lib/redi2casa/zrem.rb +2 -2
- data/lib/redi2casa/zscore.rb +1 -1
- data/lib/redi2casa.rb +22 -2
- data/redi2casa.gemspec +1 -1
- data/spec/bitwise_spec.rb +40 -0
- data/spec/counters_spec.rb +55 -0
- data/spec/hashs_spec.rb +85 -0
- data/spec/keyvalue_spec.rb +28 -0
- data/spec/lists_spec.rb +70 -0
- data/spec/redis2casa_spec.rb +9 -0
- data/spec/sets_spec.rb +105 -0
- data/spec/sorted-sets_spec.rb +82 -0
- data/spec/spec_helper.rb +1 -0
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02835343d420037160bf3308faa4fb3bcd6b5b2b
|
4
|
+
data.tar.gz: b3a5cbe64a8c618a6a73c63e29ceff6556f1f946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07fb0ee657a3775de3c25ab8c923b9d16fe5ea80e0686e45b1c960cfeead6e0bbdbf41c69b7b685059e1f962d6bfdb9321cbfe632bea9ccaa117113692763a79
|
7
|
+
data.tar.gz: f18b64faf51f072b439bf330796054f653a1da30b6491b74ffa36b47cb4199845bf110da3c165988b1a0cd275226bab39af03dbd6e0dcef343a3def01fa24661
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
redi2casa (0.
|
4
|
+
redi2casa (0.1.1)
|
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.2)
|
11
|
+
diff-lcs (1.2.5)
|
11
12
|
rake (10.1.0)
|
13
|
+
rspec (2.14.1)
|
14
|
+
rspec-core (~> 2.14.0)
|
15
|
+
rspec-expectations (~> 2.14.0)
|
16
|
+
rspec-mocks (~> 2.14.0)
|
17
|
+
rspec-core (2.14.7)
|
18
|
+
rspec-expectations (2.14.4)
|
19
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
+
rspec-mocks (2.14.4)
|
12
21
|
|
13
22
|
PLATFORMS
|
14
23
|
ruby
|
15
24
|
|
16
25
|
DEPENDENCIES
|
17
26
|
bundler
|
18
|
-
cql-rb
|
19
27
|
rake
|
20
28
|
redi2casa!
|
29
|
+
rspec
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/redi2casa/del.rb
CHANGED
@@ -4,15 +4,15 @@ class Redi2casa
|
|
4
4
|
if type == "counter"
|
5
5
|
raise RuntimeError.new("deleting counters is not supported")
|
6
6
|
elsif type == 'keyvalue'
|
7
|
-
|
7
|
+
execute "delete from keyvalue where key = '#{key}'"
|
8
8
|
elsif type == 'hash'
|
9
|
-
|
9
|
+
execute "delete from hashes where key = '#{key}'"
|
10
10
|
elsif type == 'list'
|
11
|
-
|
11
|
+
execute "delete from lists where namespace = '#{key}'"
|
12
12
|
elsif type == 'set'
|
13
|
-
|
13
|
+
execute "delete from sets where key = '#{key}'"
|
14
14
|
elsif type == 'sorted_set'
|
15
|
-
|
15
|
+
execute "delete from sorted_sets where key = '#{key}'"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
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 =
|
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 =
|
8
|
+
resp = execute "select value from counters where KEY='#{key}' and column1 = '@'"
|
9
9
|
parse_response(resp, "value").to_i
|
10
10
|
end
|
11
11
|
end
|
data/lib/redi2casa/hdel.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hdel key, column1, type = "counter"
|
3
3
|
if type == "counter"
|
4
|
-
|
4
|
+
raise RuntimeError.new("deleting counters is not supported")
|
5
5
|
elsif type == "hash"
|
6
|
-
|
6
|
+
execute "delete from hashes where key = '#{key}' and column1 = '#{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 =
|
4
|
+
resp = execute "select value from hashes where key = '#{key}' and column1 = '#{column1}'"
|
5
5
|
parse_response(resp, "value")
|
6
6
|
elsif type.to_s == "counter"
|
7
|
-
resp =
|
7
|
+
resp = execute "select value from counters where KEY='#{key}' and column1 = '#{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 =
|
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 =
|
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
@@ -1,5 +1,5 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hincrby key, column1, value = 1
|
3
|
-
|
3
|
+
execute "update counters set value = value + #{value} where key='#{key}' and column1 = '#{column1}'"
|
4
4
|
end
|
5
5
|
end
|
data/lib/redi2casa/hkeys.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def hkeys key, type = "counter"
|
3
3
|
if type.to_s == "counter"
|
4
|
-
response =
|
4
|
+
response = execute "select column1 from counters where key = '#{key}'"
|
5
5
|
response.collect {|entry| entry["column1"]}
|
6
6
|
elsif type.to_s == "hash"
|
7
|
-
response =
|
7
|
+
response = execute "select column1 from hashes where key = '#{key}'"
|
8
8
|
response.collect {|entry| entry["column1"]}
|
9
9
|
end
|
10
10
|
end
|
data/lib/redi2casa/hlen.rb
CHANGED
@@ -2,10 +2,10 @@ class Redi2casa
|
|
2
2
|
# Supports only hashes now
|
3
3
|
def hlen key, type = "hash"
|
4
4
|
if type == "hash"
|
5
|
-
response =
|
5
|
+
response = execute "select count(*) from hashes where key = '#{key}'"
|
6
6
|
parse_response(response, "count").to_i
|
7
7
|
elsif type == "counter"
|
8
|
-
response =
|
8
|
+
response = execute "select count(*) from counters where key = '#{key}'"
|
9
9
|
parse_response(response, "count").to_i
|
10
10
|
end
|
11
11
|
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 =
|
11
|
+
resp = execute "select column1, value from #{table} where key = '#{key}' and column1 IN ('#{column1s.join("','")}')"
|
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,9 +1,9 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
#has a read modify write problem
|
3
3
|
def lpop namespace
|
4
|
-
resp =
|
4
|
+
resp = execute "select values from lists where namespace='#{namespace}'"
|
5
5
|
values = []
|
6
|
-
resp.
|
6
|
+
resp.each {|entry| values = entry.to_hash["values"]}
|
7
7
|
resp = values.shift
|
8
8
|
lrepush(namespace, values)
|
9
9
|
resp
|
data/lib/redi2casa/lpush.rb
CHANGED
data/lib/redi2casa/lrange.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def lrange namespace, first, last
|
3
|
-
resp =
|
4
|
-
resp.
|
3
|
+
resp = execute "select values from lists where namespace='#{namespace}'"
|
4
|
+
resp.each {|entry|
|
5
|
+
values = entry.to_hash["values"] || []
|
6
|
+
return values[first..last]
|
7
|
+
}
|
5
8
|
end
|
6
9
|
end
|
data/lib/redi2casa/ltrim.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def ltrim namespace, first, last
|
3
|
-
resp =
|
3
|
+
resp = execute "select values from lists where namespace='#{namespace}'"
|
4
4
|
values = {}
|
5
|
-
resp.
|
5
|
+
resp.each {|entry| values = entry.to_hash["values"]}
|
6
6
|
values_count = values.count
|
7
7
|
#if first is greater than list length, redis returns empty list
|
8
8
|
#if negative value of last is equal or greater than list length a similar behaviour is shown
|
@@ -17,10 +17,11 @@ class Redi2casa
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def lflush namespace
|
20
|
-
|
20
|
+
execute "UPDATE lists SET values = [] WHERE namespace = '#{namespace}'"
|
21
21
|
end
|
22
22
|
|
23
|
+
private
|
23
24
|
def lrepush namespace, list
|
24
|
-
|
25
|
+
execute "UPDATE lists SET values = ['#{list.join("','")}'] WHERE namespace = '#{namespace}'"
|
25
26
|
end
|
26
27
|
end
|
data/lib/redi2casa/rpop.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def rpop namespace
|
3
|
-
resp =
|
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
|
-
|
3
|
+
execute "update sets using ttl #{ttl} set members = members + {'#{members.join("','")}'} where key = '#{key}'"
|
4
4
|
end
|
5
5
|
end
|
data/lib/redi2casa/set.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
|
-
|
4
|
+
execute "insert into sorted_sets (key, score,value, random_text) values ('#{key}',#{score}, '#{value}', '#{Time.now.to_i}')"
|
5
5
|
end
|
6
6
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Redi2casa
|
2
|
+
# Ranges are exclusive
|
2
3
|
def zrangebyscore key, lower_limit, higher_limit = -1
|
3
4
|
if higher_limit == -1
|
4
|
-
resp =
|
5
|
+
resp = execute "select value from sorted_sets where key = '#{key}' and score > #{lower_limit}"
|
5
6
|
else
|
6
|
-
resp =
|
7
|
+
resp = execute "select value from sorted_sets where key = '#{key}' and score > #{lower_limit} and score < #{higher_limit}"
|
7
8
|
end
|
8
9
|
resp.collect do |entry|
|
9
10
|
entry['value']
|
data/lib/redi2casa/zrem.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Redi2casa
|
2
2
|
def zrem key, member
|
3
|
-
resp =
|
3
|
+
resp = execute "select * from sorted_sets where key = '#{key}'"
|
4
4
|
resp.each do |entry|
|
5
|
-
|
5
|
+
execute "delete from sorted_sets where key = '#{key}' and score = #{entry['score']} and value = '#{entry['value']}'" if entry['value'] == member.to_s
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/redi2casa/zscore.rb
CHANGED
data/lib/redi2casa.rb
CHANGED
@@ -5,11 +5,31 @@ Gem.find_files("redi2casa/*.rb").each { |path| require path }
|
|
5
5
|
|
6
6
|
class Redi2casa
|
7
7
|
def initialize(hosts, keyspace)
|
8
|
-
@
|
9
|
-
@
|
8
|
+
@hosts = hosts
|
9
|
+
@keyspace = keyspace
|
10
|
+
connect
|
10
11
|
end
|
11
12
|
|
13
|
+
def connect
|
14
|
+
@db_conn = Cql::Client.connect(:hosts => @hosts)
|
15
|
+
@db_conn.use(@keyspace)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias :reconnect :connect
|
19
|
+
|
12
20
|
def parse_response(resp, key)
|
13
21
|
resp.map {|entry| entry[key].to_s }.first
|
14
22
|
end
|
23
|
+
|
24
|
+
def execute query
|
25
|
+
@failed ||= 0
|
26
|
+
@db_conn.execute query
|
27
|
+
rescue Cql::NotConnectedError
|
28
|
+
reconnect
|
29
|
+
@failed += 1
|
30
|
+
retry if @failed < 3
|
31
|
+
raise
|
32
|
+
ensure
|
33
|
+
@failed = 0
|
34
|
+
end
|
15
35
|
end
|
data/redi2casa.gemspec
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "bitwise" do
|
5
|
+
KEY = "test_bitwise"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
$r.del(KEY, "sorted_set")
|
9
|
+
end
|
10
|
+
|
11
|
+
def r
|
12
|
+
$r
|
13
|
+
end
|
14
|
+
it "set two bits to 1 and getbits" do
|
15
|
+
r.set_bit KEY, 5, 1
|
16
|
+
r.set_bit KEY, 10, 1
|
17
|
+
r.get_bit(KEY, 5).should == 1
|
18
|
+
r.get_bit(KEY, 10).should == 1
|
19
|
+
r.get_bit(KEY, 8).should == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it "set two bits to 1 and set it back to 0 and then getbits" do
|
23
|
+
r.set_bit KEY, 5, 1
|
24
|
+
r.set_bit KEY, 5, 0
|
25
|
+
r.get_bit(KEY, 5).should == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "clear bits should clear all the set bits" do
|
29
|
+
r.set_bit KEY, 5, 1
|
30
|
+
r.set_bit KEY, 10, 1
|
31
|
+
r.clear_bits KEY
|
32
|
+
r.get_bit(KEY, 5).should == 0
|
33
|
+
r.get_bit(KEY, 10).should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "unset bits are by default 0" do
|
37
|
+
r.get_bit(KEY, 25).should == 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "counters" do
|
5
|
+
KEY = "test_counters"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
end
|
9
|
+
|
10
|
+
def r
|
11
|
+
$r
|
12
|
+
end
|
13
|
+
|
14
|
+
it "hincryby" do
|
15
|
+
a = r.hget(KEY, "c1", "counter")
|
16
|
+
r.hincrby(KEY, "c1", 1)
|
17
|
+
r.hget(KEY, "c1", "counter").should == a + 1
|
18
|
+
r.hincrby(KEY, "c1", 5)
|
19
|
+
r.hget(KEY, "c1", "counter").should == a + 6
|
20
|
+
end
|
21
|
+
|
22
|
+
it "hkeys" do
|
23
|
+
r.hincrby(KEY, "c1")
|
24
|
+
r.hincrby(KEY, "c2")
|
25
|
+
r.hkeys(KEY, "counter").include?("c1").should == true
|
26
|
+
r.hkeys(KEY, "counter").include?("c2").should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "hlen" do
|
30
|
+
r.hincrby(KEY, "c1")
|
31
|
+
r.hincrby(KEY, "c2")
|
32
|
+
r.hlen(KEY, "counter").should >= 2
|
33
|
+
end
|
34
|
+
|
35
|
+
it "hget" do
|
36
|
+
a = r.hget(KEY, "c1", "counter")
|
37
|
+
r.hincrby(KEY, "c1", 5)
|
38
|
+
r.hget(KEY, "c1", "counter").should == a + 5
|
39
|
+
end
|
40
|
+
|
41
|
+
it "hmget" do
|
42
|
+
a = r.hget(KEY, "c1", "counter")
|
43
|
+
b = r.hget(KEY, "c2", "counter")
|
44
|
+
r.hmget(KEY, "counter", "c1", "c2").should == [ a, b]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "hgetall" do
|
48
|
+
a = r.hget(KEY, "c1")
|
49
|
+
b = r.hget(KEY, "c2")
|
50
|
+
resp = r.hgetall(KEY, "counter")
|
51
|
+
resp["c1"].should == a
|
52
|
+
resp["c2"].should == b
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/hashs_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "hashes" do
|
5
|
+
KEY = "test_hash"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
$r.del KEY, "hash"
|
9
|
+
end
|
10
|
+
def r
|
11
|
+
$r
|
12
|
+
end
|
13
|
+
|
14
|
+
context "hdel & hget" do
|
15
|
+
it "should delete a entry already present" do
|
16
|
+
r.hset KEY, "a", "5"
|
17
|
+
r.hget(KEY, "a", "hash").should == "5"
|
18
|
+
r.hdel(KEY, "a", "hash")
|
19
|
+
r.hget(KEY, "a", "hash").should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should ignore if the entry is not already present" do
|
23
|
+
r.hset(KEY, "b", "25")
|
24
|
+
r.hdel(KEY, "a", "hash")
|
25
|
+
r.hget(KEY, "b", "hash").should == "25"
|
26
|
+
r.hget(KEY, "a", "hash").should == nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "hget" do
|
31
|
+
it "should get item which is already set" do
|
32
|
+
r.hset KEY, "a", "5"
|
33
|
+
r.hget(KEY, "a", "hash").should == "5"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return nil if the element dows not exist" do
|
37
|
+
r.hget(KEY, "a", "hash").should == nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "hgetall" do
|
42
|
+
it "get all elements as a hash" do
|
43
|
+
r.hset KEY, "a", "5"
|
44
|
+
r.hset KEY, "b", "10"
|
45
|
+
r.hset KEY, "c", "15"
|
46
|
+
r.hgetall(KEY, "hash").should == {"a" => "5", "b" => "10", "c" => "15"}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return empty hash if it does not exist" do
|
50
|
+
r.hgetall(KEY, "hash").should == {}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "hlen" do
|
55
|
+
it "returns number of elements in the hash" do
|
56
|
+
r.hset KEY, "a", "5"
|
57
|
+
r.hset KEY, "b", "10"
|
58
|
+
r.hset KEY, "c", "15"
|
59
|
+
r.hset KEY, "d", "15"
|
60
|
+
r.hlen(KEY).should == 4
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns 0 if hash does not exists" do
|
64
|
+
r.hlen(KEY).should == 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "hmget" do
|
69
|
+
it "returns multiple elements in a hash" do
|
70
|
+
r.hset KEY, "a", "5"
|
71
|
+
r.hset KEY, "b", "10"
|
72
|
+
r.hset KEY, "c", "15"
|
73
|
+
r.hset KEY, "d", "15"
|
74
|
+
r.hmget(KEY, "hash", "a", "b", "f").should == ["5", "10", nil]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "hset" do
|
79
|
+
it "sets a value to hash" do
|
80
|
+
r.hset KEY, "z", "2000"
|
81
|
+
r.hget(KEY, "z", "hash").should == "2000"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "keyvalue" do
|
5
|
+
KEY = "test_keyvalye"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
$r.del(KEY, "keyvalue")
|
9
|
+
end
|
10
|
+
|
11
|
+
def r
|
12
|
+
$r
|
13
|
+
end
|
14
|
+
|
15
|
+
it "get and set -- before setting element should be nil then the set value after set" do
|
16
|
+
r.get(KEY).should == nil
|
17
|
+
r.set(KEY, "z")
|
18
|
+
r.get(KEY).should == "z"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "get and setex the set key should remain for ttl only" do
|
22
|
+
r.setex(KEY, 5, "z")
|
23
|
+
r.get(KEY).should == "z"
|
24
|
+
sleep 7
|
25
|
+
r.get(KEY).should == nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/lists_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "lists" do
|
5
|
+
KEY = "test_list"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
$r.del(KEY, "list")
|
9
|
+
end
|
10
|
+
|
11
|
+
def r
|
12
|
+
$r
|
13
|
+
end
|
14
|
+
|
15
|
+
context "lpop" do
|
16
|
+
it "pop the first element out" do
|
17
|
+
r.lpush KEY, "a"
|
18
|
+
r.lpush KEY, "b"
|
19
|
+
r.lpush KEY, "f"
|
20
|
+
r.lpush KEY, "g"
|
21
|
+
r.lpop(KEY).should == "g"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "return nil if the list is empty" do
|
25
|
+
r.lpop(KEY).should == nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "lpush & lrange" do
|
30
|
+
it "pushes to the start of the list" do
|
31
|
+
r.lpush KEY, "a"
|
32
|
+
r.lpush KEY, "b"
|
33
|
+
r.lpush KEY, "f"
|
34
|
+
r.lpush KEY, "g"
|
35
|
+
r.lrange(KEY, 0, -1).should == ["g", "f", "b", "a"]
|
36
|
+
r.lrange(KEY, 2, 3).should == ["b", "a"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "lrange" do
|
41
|
+
it "return empty list in case the list is empty" do
|
42
|
+
r.lrange(KEY, 0, -1).should == []
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "ltrim" do
|
47
|
+
it "trims the list to specified ranges" do
|
48
|
+
r.lpush KEY, "a"
|
49
|
+
r.lpush KEY, "b"
|
50
|
+
r.lpush KEY, "f"
|
51
|
+
r.lpush KEY, "g"
|
52
|
+
r.ltrim(KEY, 0, 2)
|
53
|
+
r.lrange(KEY, 0, -1) == ["g", "f", "b"]
|
54
|
+
r.ltrim(KEY, 1, 2)
|
55
|
+
r.lrange(KEY, 0, -1) == ["f", "b"]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "lflush" do
|
60
|
+
it "empties the list" do
|
61
|
+
r.lpush KEY, "a"
|
62
|
+
r.lpush KEY, "b"
|
63
|
+
r.lpush KEY, "f"
|
64
|
+
r.lpush KEY, "g"
|
65
|
+
r.lflush KEY
|
66
|
+
r.lrange(KEY, 0, -1) == []
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'redi2casa'
|
2
|
+
|
3
|
+
require './spec/sets_spec.rb'
|
4
|
+
require './spec/hashs_spec.rb'
|
5
|
+
require './spec/lists_spec.rb'
|
6
|
+
require './spec/sorted-sets_spec.rb'
|
7
|
+
require './spec/keyvalue_spec.rb'
|
8
|
+
require './spec/bitwise_spec.rb'
|
9
|
+
require './spec/counters_spec.rb'
|
data/spec/sets_spec.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "sets" do
|
5
|
+
KEY = "test_set"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
$r.del(KEY, "set")
|
9
|
+
end
|
10
|
+
|
11
|
+
def r
|
12
|
+
$r
|
13
|
+
end
|
14
|
+
|
15
|
+
context "sadd" do
|
16
|
+
it "should add first element" do
|
17
|
+
r.sadd KEY, "a"
|
18
|
+
r.smembers(KEY).include?("a").should == true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should add second element" do
|
22
|
+
r.sadd KEY, "a"
|
23
|
+
r.sadd KEY, "b"
|
24
|
+
r.smembers(KEY).include?("a").should == true
|
25
|
+
r.smembers(KEY).include?("b").should == true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "already added element should not be added again" do
|
29
|
+
r.sadd KEY, "a"
|
30
|
+
r.sadd KEY, "a"
|
31
|
+
r.smembers(KEY).size.should == 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "sadd_with_expire" do
|
36
|
+
it "add a new element it should disapper after ttl" do
|
37
|
+
r.sadd_with_expire KEY, 5, "a"
|
38
|
+
r.smembers(KEY).size.should == 1
|
39
|
+
sleep 7
|
40
|
+
r.smembers(KEY).size.should == 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "scard" do
|
45
|
+
it "default size should be 0" do
|
46
|
+
r.scard(KEY).should == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
it "add 5 unique elements and size should be five" do
|
50
|
+
r.sadd KEY, "a", "b", "c", "d", "e"
|
51
|
+
r.scard(KEY).should == 5
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "sismember" do
|
56
|
+
it "add a element and it should be there in the set" do
|
57
|
+
r.sadd KEY, "a", "b", "c", "d", "e"
|
58
|
+
r.sismember(KEY, "a").should == true
|
59
|
+
r.sismember(KEY, "d").should == true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "random element should not be present in the set" do
|
63
|
+
r.sadd KEY, "a"
|
64
|
+
r.sismember(KEY, "b").should == false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "smembers" do
|
69
|
+
it "add 5 members and this should be listed in smembers" do
|
70
|
+
r.sadd KEY, "a", "b", "c", "d", "e"
|
71
|
+
r.smembers(KEY).should == ["a", "b", "c", "d", "e"]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "default should be empty set" do
|
75
|
+
r.smembers(KEY).should == []
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "spop" do
|
80
|
+
it "removes random element from set" do
|
81
|
+
r.sadd KEY, "a", "b", "c", "d", "e"
|
82
|
+
k = r.spop(KEY)
|
83
|
+
r.smembers(KEY).should == ["a", "b", "c", "d", "e"] - [ k ]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "return nil incase set is empty" do
|
87
|
+
r.spop(KEY).should == nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "srem" do
|
92
|
+
it "deletes the element if present" do
|
93
|
+
r.sadd KEY, "a", "b", "c", "d", "e"
|
94
|
+
r.srem KEY, "b"
|
95
|
+
r.smembers(KEY).should == ["a", "c", "d", "e"]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "ignores if element is not present" do
|
99
|
+
r.sadd KEY, "a", "b", "c", "d", "e"
|
100
|
+
r.srem KEY, "f"
|
101
|
+
r.smembers(KEY).should == ["a", "b", "c", "d", "e"]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Redi2casa do
|
4
|
+
context "sorted-sets" do
|
5
|
+
KEY = "test_sorted-set"
|
6
|
+
before(:each) do
|
7
|
+
$r ||= Redi2casa.new(["localhost"], "redi2casa")
|
8
|
+
$r.del(KEY, "sorted_set")
|
9
|
+
end
|
10
|
+
|
11
|
+
def r
|
12
|
+
$r
|
13
|
+
end
|
14
|
+
|
15
|
+
context "zadd" do
|
16
|
+
it "add one element with a score" do
|
17
|
+
r.zadd KEY, 5, "a"
|
18
|
+
r.zrangebyscore(KEY, 0).should == ["a"]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "add already existing element with the same score" do
|
22
|
+
r.zadd KEY, 5, "a"
|
23
|
+
r.zadd KEY, 5, "a"
|
24
|
+
r.zrangebyscore(KEY, 0).should == ["a"]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "add two elements with same score" do
|
28
|
+
r.zadd KEY, 5, "a"
|
29
|
+
r.zadd KEY, 5, "b"
|
30
|
+
r.zrangebyscore(KEY, 0).should == ["a", "b"]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "add two elements with different score" do
|
34
|
+
r.zadd KEY, 5, "a"
|
35
|
+
r.zadd KEY, 6, "b"
|
36
|
+
r.zrangebyscore(KEY, 0).should == ["a", "b"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "zrangebyscore" do
|
41
|
+
it "list elements from 0 to -1 should give all elements with positive score" do
|
42
|
+
r.zadd KEY, 5, "a"
|
43
|
+
r.zadd KEY, 6, "b"
|
44
|
+
r.zadd KEY, 7, "c"
|
45
|
+
r.zadd KEY, 8, "d"
|
46
|
+
r.zrangebyscore(KEY, 0).should == ["a", "b", "c", "d"]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "list elements with subset with specified range of scores" do
|
50
|
+
# Ranges are exclusive
|
51
|
+
r.zadd KEY, 5, "a"
|
52
|
+
r.zadd KEY, 6, "b"
|
53
|
+
r.zadd KEY, 7, "c"
|
54
|
+
r.zadd KEY, 8, "d"
|
55
|
+
r.zrangebyscore(KEY, 5, 8).should == ["b", "c"]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "zrem" do
|
60
|
+
it "removed certain element from the zset and removing non existant member should be ignored" do
|
61
|
+
r.zadd KEY, 5, "a"
|
62
|
+
r.zadd KEY, 6, "b"
|
63
|
+
r.zadd KEY, 7, "c"
|
64
|
+
r.zadd KEY, 8, "d"
|
65
|
+
r.zrem KEY, "c"
|
66
|
+
r.zrem KEY, "z"
|
67
|
+
r.zrangebyscore(KEY, 0).should == ["a", "b", "d"]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "zscore" do
|
72
|
+
it "returns score of certain element in the zset and for non existant member score should be nil" do
|
73
|
+
r.zadd KEY, 5, "a"
|
74
|
+
r.zadd KEY, 6, "b"
|
75
|
+
r.zadd KEY, 7, "c"
|
76
|
+
r.zadd KEY, 8, "d"
|
77
|
+
r.zscore(KEY, "c").should == 7
|
78
|
+
r.zscore(KEY, "z").should == nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require './lib/redi2casa.rb'
|
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.2
|
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-12-
|
12
|
+
date: 2013-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cql-rb
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - '>='
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - '>='
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- Rakefile
|
85
85
|
- cassandra_cli_cmds
|
86
86
|
- cqlsh_cmds
|
87
|
+
- lib/.DS_Store
|
87
88
|
- lib/redi2casa.rb
|
88
89
|
- lib/redi2casa/clear_bits.rb
|
89
90
|
- lib/redi2casa/del.rb
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- lib/redi2casa/hmget.rb
|
99
100
|
- lib/redi2casa/hset.rb
|
100
101
|
- lib/redi2casa/incrby.rb
|
102
|
+
- lib/redi2casa/keys.rb
|
101
103
|
- lib/redi2casa/lpop.rb
|
102
104
|
- lib/redi2casa/lpush.rb
|
103
105
|
- lib/redi2casa/lrange.rb
|
@@ -120,6 +122,15 @@ files:
|
|
120
122
|
- lib/redi2casa/zrem.rb
|
121
123
|
- lib/redi2casa/zscore.rb
|
122
124
|
- redi2casa.gemspec
|
125
|
+
- spec/bitwise_spec.rb
|
126
|
+
- spec/counters_spec.rb
|
127
|
+
- spec/hashs_spec.rb
|
128
|
+
- spec/keyvalue_spec.rb
|
129
|
+
- spec/lists_spec.rb
|
130
|
+
- spec/redis2casa_spec.rb
|
131
|
+
- spec/sets_spec.rb
|
132
|
+
- spec/sorted-sets_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
123
134
|
homepage: https://github.com/vireshas/redi2casa
|
124
135
|
licenses:
|
125
136
|
- MIT
|
@@ -145,4 +156,13 @@ signing_key:
|
|
145
156
|
specification_version: 4
|
146
157
|
summary: Moving redis calls to equivalent cassandra calls can be a pain unless you
|
147
158
|
use this gem
|
148
|
-
test_files:
|
159
|
+
test_files:
|
160
|
+
- spec/bitwise_spec.rb
|
161
|
+
- spec/counters_spec.rb
|
162
|
+
- spec/hashs_spec.rb
|
163
|
+
- spec/keyvalue_spec.rb
|
164
|
+
- spec/lists_spec.rb
|
165
|
+
- spec/redis2casa_spec.rb
|
166
|
+
- spec/sets_spec.rb
|
167
|
+
- spec/sorted-sets_spec.rb
|
168
|
+
- spec/spec_helper.rb
|