ssdb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +31 -0
- data/README.md +117 -0
- data/Rakefile +10 -0
- data/lib/ssdb.rb +431 -0
- data/lib/ssdb/batch.rb +27 -0
- data/lib/ssdb/client.rb +173 -0
- data/lib/ssdb/future.rb +30 -0
- data/lib/ssdb/version.rb +3 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/ssdb/batch_spec.rb +38 -0
- data/spec/ssdb/client_spec.rb +48 -0
- data/spec/ssdb/future_spec.rb +30 -0
- data/spec/ssdb_spec.rb +37 -0
- data/spec/types/values_spec.rb +103 -0
- data/spec/types/zsets_spec.rb +116 -0
- data/ssdb.gemspec +25 -0
- metadata +151 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SSDB do
|
4
|
+
describe "zsets" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
subject.zset "#{FPX}:zset1", "a", 1
|
8
|
+
subject.zset "#{FPX}:zset1", "b", 2
|
9
|
+
subject.zset "#{FPX}:zset1", "c", 2.5
|
10
|
+
subject.zset "#{FPX}:zset1", "d", 3
|
11
|
+
subject.zset "#{FPX}:zset2", "xa", 100
|
12
|
+
subject.zset "#{FPX}:zset2", "xz", 200
|
13
|
+
subject.zset "#{FPX}:zset3", "za", 5
|
14
|
+
subject.zset "#{FPX}:zset3", "zz", 5
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should check existence" do
|
18
|
+
subject.zexists?("#{FPX}:zset1").should be(true)
|
19
|
+
subject.zexists("#{FPX}:zset2").should be(true)
|
20
|
+
subject.zexists?("#{FPX}:zset9").should be(false)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should count" do
|
24
|
+
subject.zsize("#{FPX}:zset1").should == 4
|
25
|
+
subject.zsize("#{FPX}:zset2").should == 2
|
26
|
+
subject.zsize("#{FPX}:zset9").should == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should delete" do
|
30
|
+
-> {
|
31
|
+
subject.zdel("#{FPX}:zset1", "a").should be(true)
|
32
|
+
}.should change { subject.zsize("#{FPX}:zset1") }.by(-1)
|
33
|
+
|
34
|
+
-> {
|
35
|
+
subject.zdel("#{FPX}:zset1", "e").should be(false)
|
36
|
+
}.should_not change { subject.zsize("#{FPX}:zset1") }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set/get scores" do
|
40
|
+
subject.zset("#{FPX}:zset9", "i", 50).should be(true)
|
41
|
+
subject.zset("#{FPX}:zset9", "i", 60).should be(false)
|
42
|
+
subject.zset("#{FPX}:zset9", "i", 60).should be(false)
|
43
|
+
|
44
|
+
subject.zget("#{FPX}:zset9", "i").should == 60
|
45
|
+
subject.zget("#{FPX}:zset1", "c").should == 2
|
46
|
+
subject.zget("#{FPX}:zset1", "x").should be_nil
|
47
|
+
subject.zget("#{FPX}:zsetX", "any").should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should 'add' scores" do
|
51
|
+
subject.zadd("#{FPX}:zset9", 50, "i").should be(true)
|
52
|
+
subject.zget("#{FPX}:zset9", "i").should == 50
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should increment/decrement scores" do
|
56
|
+
subject.zincr("#{FPX}:zset1", "a", 7).should == 8
|
57
|
+
subject.zdecr("#{FPX}:zset1", "a", 3).should == 5
|
58
|
+
subject.zincr("#{FPX}:zset1", "a", 3.9).should == 8
|
59
|
+
subject.zdecr("#{FPX}:zset1", "a", 1.8).should == 7
|
60
|
+
subject.zincr("#{FPX}:zset1", "b", 1).should == 3
|
61
|
+
|
62
|
+
subject.zincr("#{FPX}:zset1", "e", 5).should == 5
|
63
|
+
subject.zget("#{FPX}:zset1", "e").should == 5
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should list sets" do
|
67
|
+
subject.zlist("#{FPX}:zset1", "#{FPX}:zset3").should == ["#{FPX}:zset2", "#{FPX}:zset3"]
|
68
|
+
subject.zlist("#{FPX}:zset0", "#{FPX}:zsetz", limit: 2).should == ["#{FPX}:zset1", "#{FPX}:zset2"]
|
69
|
+
subject.zlist("#{FPX}:zsety", "#{FPX}:zsetz").should == []
|
70
|
+
subject.zlist("#{FPX}:zsetz", "#{FPX}:zset0").should == []
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should scan scores" do
|
74
|
+
subject.zscan("#{FPX}:zset1", 0, 10).should == [["a", 1], ["b", 2], ["c", 2], ["d", 3]]
|
75
|
+
subject.zscan("#{FPX}:zset1", 2, 3).should == [["b", 2], ["c", 2]]
|
76
|
+
subject.zscan("#{FPX}:zset1", 2, 3, limit: 2).should == [["b", 2], ["c", 2]]
|
77
|
+
subject.zscan("#{FPX}:zset1", 3, 2).should == []
|
78
|
+
subject.zscan("#{FPX}:zset3", 0, 10).should == [["za", 5], ["zz", 5]]
|
79
|
+
subject.zscan("#{FPX}:zsety", 0, 100).should == []
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should rscan scores" do
|
83
|
+
subject.zrscan("#{FPX}:zset2", 1000, 0).should == [["xz", 200], ["xa", 100]]
|
84
|
+
subject.zrscan("#{FPX}:zset2", 0, 1000).should == []
|
85
|
+
subject.zrscan("#{FPX}:zset2", 200, 100).should == [["xa", 100]]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should list score keys" do
|
89
|
+
subject.zkeys("#{FPX}:zset1", 0, 10).should == ["a", "b", "c", "d"]
|
90
|
+
subject.zkeys("#{FPX}:zset1", 10, 0).should == []
|
91
|
+
subject.zkeys("#{FPX}:zset3", 0, 10).should == ["za", "zz"]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should check existence of multiple sets" do
|
95
|
+
subject.multi_zexists(["#{FPX}:zset1", "#{FPX}:zset2", "#{FPX}:zset9"]).should == [true, true, false]
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should check sizes of multiple sets" do
|
99
|
+
subject.multi_zsize(["#{FPX}:zset1", "#{FPX}:zset2", "#{FPX}:zset9"]).should == [4, 2, 0]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should get/set multiple members" do
|
103
|
+
subject.multi_zset("#{FPX}:zset5", {"k" => 7, "l" => 8}).should == 2
|
104
|
+
subject.multi_zget("#{FPX}:zset1", ["a", "d", "x"]).should == [1, 3, 0]
|
105
|
+
subject.multi_zget("#{FPX}:zset5", ["i", "k", "l"]).should == [0, 7, 8]
|
106
|
+
subject.multi_zget("#{FPX}:zset9", ["x", "y"]).should == [0, 0]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should delete multiple members" do
|
110
|
+
-> {
|
111
|
+
subject.multi_zdel("#{FPX}:zset1", ["a", "d", "x"]).should == 2
|
112
|
+
}.should change { subject.zsize("#{FPX}:zset1") }.by(-2)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
data/ssdb.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ssdb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ssdb"
|
7
|
+
s.version = SSDB::VERSION.dup
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.licenses = ["MIT"]
|
10
|
+
s.summary = "A Ruby client library for SSDB"
|
11
|
+
s.email = "info@blacksquaremedia.com"
|
12
|
+
s.homepage = "http://github.com/bsm/ssdb-rb"
|
13
|
+
s.description = "Please see https://github.com/ideawu/ssdb/ for more information."
|
14
|
+
s.authors = ['Dimitrij Denissenko']
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency("rspec")
|
21
|
+
s.add_development_dependency("rake")
|
22
|
+
s.add_development_dependency("bundler")
|
23
|
+
s.add_development_dependency("yard")
|
24
|
+
s.add_development_dependency("redcarpet")
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimitrij Denissenko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
type: :development
|
17
|
+
name: rspec
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
32
|
+
type: :development
|
33
|
+
name: rake
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
name: bundler
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
64
|
+
type: :development
|
65
|
+
name: yard
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
prerelease: false
|
80
|
+
type: :development
|
81
|
+
name: redcarpet
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Please see https://github.com/ideawu/ssdb/ for more information.
|
95
|
+
email: info@blacksquaremedia.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- .gitignore
|
101
|
+
- Gemfile
|
102
|
+
- Gemfile.lock
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- lib/ssdb.rb
|
106
|
+
- lib/ssdb/batch.rb
|
107
|
+
- lib/ssdb/client.rb
|
108
|
+
- lib/ssdb/future.rb
|
109
|
+
- lib/ssdb/version.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/ssdb/batch_spec.rb
|
112
|
+
- spec/ssdb/client_spec.rb
|
113
|
+
- spec/ssdb/future_spec.rb
|
114
|
+
- spec/ssdb_spec.rb
|
115
|
+
- spec/types/values_spec.rb
|
116
|
+
- spec/types/zsets_spec.rb
|
117
|
+
- ssdb.gemspec
|
118
|
+
homepage: http://github.com/bsm/ssdb-rb
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.25
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: A Ruby client library for SSDB
|
143
|
+
test_files:
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- spec/ssdb/batch_spec.rb
|
146
|
+
- spec/ssdb/client_spec.rb
|
147
|
+
- spec/ssdb/future_spec.rb
|
148
|
+
- spec/ssdb_spec.rb
|
149
|
+
- spec/types/values_spec.rb
|
150
|
+
- spec/types/zsets_spec.rb
|
151
|
+
has_rdoc:
|