redis-plus 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - jruby-18mode
9
+ - jruby-19mode
10
+ services:
11
+ - redis-server
data/README.md CHANGED
@@ -31,6 +31,10 @@ r.rpush "numbers", "three"
31
31
 
32
32
  # retrieve all elements of a list:
33
33
  r.lgetall "numbers" #=> ["one", "two", "three"]
34
+
35
+ # retrieve the length of a string value stored in a list
36
+ r.lstrlen "numbers", 0 #=> 3
37
+ r.lstrlen "numbers", 2 #=> 5
34
38
  ```
35
39
 
36
40
 
@@ -6,6 +6,18 @@ class Redis
6
6
  def lgetall(key)
7
7
  lrange(key, 0, -1)
8
8
  end
9
+
10
+ def lstrlen(key, index)
11
+ command = <<-LUA
12
+ local v = redis.pcall('lrange',KEYS[1],ARGV[1],ARGV[1])
13
+ if v.err then
14
+ return v
15
+ else
16
+ return v[1] and string.len(v[1])
17
+ end
18
+ LUA
19
+ self.eval(command, [key], [index]) || 0
20
+ end
9
21
  end
10
22
 
11
23
  include Plus
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  module Plus
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -16,5 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.add_dependency "redis", ">=3.0.0"
19
+ gem.add_development_dependency 'rake'
20
+ gem.add_development_dependency "rspec"
19
21
  gem.require_paths = ["lib"]
20
22
  end
@@ -13,4 +13,32 @@ describe "redis-plus" do
13
13
  redis.lgetall("numbers").should == ["one", "two", "three"]
14
14
  end
15
15
  end
16
+
17
+ describe "#lstrlen" do
18
+ it "retrieves the length of a string value stored in a list" do
19
+ redis.rpush "numbers", "one"
20
+ redis.rpush "numbers", "two"
21
+ redis.rpush "numbers", "three"
22
+
23
+ redis.lstrlen("numbers", 0).should == 3
24
+ redis.lstrlen("numbers", 1).should == 3
25
+ redis.lstrlen("numbers", 2).should == 5
26
+ redis.lstrlen("numbers", -1).should == 5
27
+ end
28
+
29
+ it "returns 0 when the index is out of range" do
30
+ redis.lstrlen("numbers", 10).should == 0
31
+ redis.lstrlen("numbers", -10).should == 0
32
+ end
33
+
34
+ it "raises a 'wrong kind of value' error when not used on a list" do
35
+ redis.set "stringval", "hello"
36
+
37
+ expect { redis.lstrlen("stringval", 0) }.to raise_error {|error|
38
+ error.should be_a Redis::CommandError
39
+ error.message.should match /wrong kind of value/
40
+ error.message.should_not match /running script/
41
+ }
42
+ end
43
+ end
16
44
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
4
  prerelease:
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joshua Flanagan
@@ -12,8 +12,14 @@ cert_chain: []
12
12
  date: 2013-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: redis
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ none: false
16
21
  prerelease: false
22
+ name: redis
17
23
  requirement: !ruby/object:Gem::Requirement
18
24
  requirements:
19
25
  - - ! '>='
@@ -21,12 +27,38 @@ dependencies:
21
27
  version: 3.0.0
22
28
  none: false
23
29
  type: :runtime
30
+ - !ruby/object:Gem::Dependency
24
31
  version_requirements: !ruby/object:Gem::Requirement
25
32
  requirements:
26
33
  - - ! '>='
27
34
  - !ruby/object:Gem::Version
28
- version: 3.0.0
35
+ version: '0'
36
+ none: false
37
+ prerelease: false
38
+ name: rake
39
+ requirement: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ none: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ none: false
53
+ prerelease: false
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
29
60
  none: false
61
+ type: :development
30
62
  description: Extends the ruby client driver with additional commands
31
63
  email:
32
64
  - joshuaflanagan@gmail.com
@@ -35,6 +67,7 @@ extensions: []
35
67
  extra_rdoc_files: []
36
68
  files:
37
69
  - .gitignore
70
+ - .travis.yml
38
71
  - Gemfile
39
72
  - LICENSE.txt
40
73
  - README.md
@@ -54,12 +87,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
87
  - - ! '>='
55
88
  - !ruby/object:Gem::Version
56
89
  version: '0'
90
+ segments:
91
+ - 0
92
+ hash: -2779340959492746939
57
93
  none: false
58
94
  required_rubygems_version: !ruby/object:Gem::Requirement
59
95
  requirements:
60
96
  - - ! '>='
61
97
  - !ruby/object:Gem::Version
62
98
  version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -2779340959492746939
63
102
  none: false
64
103
  requirements: []
65
104
  rubyforge_project: