redi2casa 0.2.11 → 0.2.12

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: f2d50ed6f0114d98aa06e240299731e6d76c973b
4
- data.tar.gz: 862e0b402b47efe6c324fa295a70267fa6679604
3
+ metadata.gz: eaef837df719b7b01a8ee98de481c29b5734aa51
4
+ data.tar.gz: 78a33b7f7d74263ea15745954ed0441f17a1994b
5
5
  SHA512:
6
- metadata.gz: 3f7d85fe1ce687aa2b79564626bb2ccf551d2dd8450409c5d483069fc2c14dc1cfc1bbebb29a0ac36956960c840b4e8a2be870c36026d28387bb99c9c35b39d1
7
- data.tar.gz: 396ea6a4c72a97592e0a1ac6976697905f8577b0fe3aace2812a80eb45330a2c6e6097668b34a0f37dfe5d18ebf45e457218cb878c7e66c5082c611f3c232727
6
+ metadata.gz: 8b8155eb8ca9af7772ff6030e85460107b5b076672be105c20d7743db7ec02897f606d572475918081a4aa5988da6557ea56b154bcd98770ae84ed0c51a5c680
7
+ data.tar.gz: 385e15b22a81723228c421315cc3727fe1f762663812f5ae142489e80bf329652460534fca8d14eb6e3c383be39f073bd60e97fca1b59ea97860795d96b9314e
@@ -0,0 +1,36 @@
1
+ class Redi2casa
2
+ def lrem namespace, count, value
3
+ elements = lrange(namespace, 0, -1)
4
+ if count == 0
5
+ delete_positions = []
6
+ elements.delete(value)
7
+ elsif count < 0
8
+ count = count * -1
9
+ delete_positions = []
10
+ (elements.length - 1).downto(0) do |i|
11
+ if elements[i] == value && count > 0
12
+ delete_positions << i
13
+ count -= 1
14
+ end
15
+ end
16
+ elsif count > 0
17
+ delete_positions = []
18
+ elements.each_index do |i|
19
+ if elements[i] == value && count > 0
20
+ delete_positions << i
21
+ count -= 1
22
+ end
23
+ end
24
+ end
25
+
26
+ delete_positions.sort!
27
+ delete_positions.reverse!
28
+
29
+ puts delete_positions.inspect
30
+ delete_positions.each do |pos|
31
+ elements.delete_at(pos)
32
+ end
33
+
34
+ lrepush(namespace, elements)
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  class Redi2casa
2
- VERSION = "0.2.11"
2
+ VERSION = "0.2.12"
3
3
  end
data/spec/lists_spec.rb CHANGED
@@ -66,5 +66,44 @@ describe Redi2casa do
66
66
  r.lrange(KEY, 0, -1) == []
67
67
  end
68
68
  end
69
+
70
+ context "lrem" do
71
+ before(:each) do |end|
72
+ r.del KEY, "list"
73
+ r.lpush(KEY, "1")
74
+ r.lpush(KEY, "2")
75
+ r.lpush(KEY, "1")
76
+ r.lpush(KEY, "2")
77
+ r.lpush(KEY, "3")
78
+ r.lpush(KEY, "3")
79
+ r.lpush(KEY, "3")
80
+ r.lpush(KEY, "7")
81
+ r.lpush(KEY, "2")
82
+ end
83
+
84
+ it "when count is 0 delete all occurences of the element" do
85
+ r.lrem(KEY, 0, "1")
86
+ r.lrange(KEY, 0, -1).should == ["2", "7", "3", "3", "3", "2", "2"]
87
+ end
88
+
89
+ it "if element is not present do not delete anything what ever the count" do
90
+ r.lrem(KEY, 0, "100")
91
+ r.lrange(KEY, 0, -1).should == ["2", "7", "3", "3", "3", "2", "1", "2", "1"]
92
+ r.lrem(KEY, -2, "100")
93
+ r.lrange(KEY, 0, -1).should == ["2", "7", "3", "3", "3", "2", "1", "2", "1"]
94
+ r.lrem(KEY, 2, "100")
95
+ r.lrange(KEY, 0, -1).should == ["2", "7", "3", "3", "3", "2", "1", "2", "1"]
96
+ end
97
+
98
+ it "should delete count times from front to last if count is positive" do
99
+ r.lrem(KEY, 2, "2")
100
+ r.lrange(KEY, 0, -1).should == [ "7", "3", "3", "3", "1", "2", "1"]
101
+ end
102
+
103
+ it "should delete count times from front to last if count is positive" do
104
+ r.lrem(KEY, -2, "2")
105
+ r.lrange(KEY, 0, -1).should == [ "2", "7", "3", "3", "3", "1", "1"]
106
+ end
107
+ end
69
108
  end
70
109
  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.2.11
4
+ version: 0.2.12
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-02-16 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cql-rb
@@ -105,6 +105,7 @@ files:
105
105
  - lib/redi2casa/lpop.rb
106
106
  - lib/redi2casa/lpush.rb
107
107
  - lib/redi2casa/lrange.rb
108
+ - lib/redi2casa/lrem.rb
108
109
  - lib/redi2casa/ltrim.rb
109
110
  - lib/redi2casa/mget.rb
110
111
  - lib/redi2casa/rpop.rb