fakeredis 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/README.md +9 -2
- data/fakeredis.gemspec +3 -2
- data/lib/fakeredis.rb +3 -56
- data/lib/fakeredis/version.rb +1 -1
- data/lib/redis/connection/memory.rb +655 -0
- data/spec/compatibility_spec.rb +9 -0
- data/spec/connection_spec.rb +2 -2
- data/spec/hashes_spec.rb +1 -1
- data/spec/keys_spec.rb +2 -1
- data/spec/lists_spec.rb +1 -1
- data/spec/server_spec.rb +1 -7
- data/spec/sets_spec.rb +1 -1
- data/spec/sorted_sets_spec.rb +1 -1
- data/spec/strings_spec.rb +1 -1
- data/spec/transactions_spec.rb +2 -2
- metadata +74 -40
- data/lib/fakeredis/connection.rb +0 -25
- data/lib/fakeredis/hashes.rb +0 -98
- data/lib/fakeredis/keys.rb +0 -82
- data/lib/fakeredis/lists.rb +0 -108
- data/lib/fakeredis/server.rb +0 -65
- data/lib/fakeredis/sets.rb +0 -122
- data/lib/fakeredis/sorted_sets.rb +0 -108
- data/lib/fakeredis/strings.rb +0 -116
- data/lib/fakeredis/transactions.rb +0 -13
data/spec/connection_spec.rb
CHANGED
@@ -4,11 +4,11 @@ module FakeRedis
|
|
4
4
|
describe "ConnectionMethods" do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@client =
|
7
|
+
@client = Redis.new
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should authenticate to the server" do
|
11
|
-
@client.auth("pass").should ==
|
11
|
+
@client.auth("pass").should == "OK"
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should echo the given string" do
|
data/spec/hashes_spec.rb
CHANGED
data/spec/keys_spec.rb
CHANGED
@@ -4,7 +4,7 @@ module FakeRedis
|
|
4
4
|
describe "KeysMethods" do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@client =
|
7
|
+
@client = Redis.new
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should delete a key" do
|
@@ -18,6 +18,7 @@ module FakeRedis
|
|
18
18
|
it "should determine if a key exists" do
|
19
19
|
@client.set("key1", "1")
|
20
20
|
|
21
|
+
puts "checking existence"
|
21
22
|
@client.exists("key1").should == true
|
22
23
|
@client.exists("key2").should == false
|
23
24
|
end
|
data/spec/lists_spec.rb
CHANGED
data/spec/server_spec.rb
CHANGED
@@ -4,7 +4,7 @@ module FakeRedis
|
|
4
4
|
describe "ServerMethods" do
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@client =
|
7
|
+
@client = Redis.new
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should return the number of keys in the selected database" do
|
@@ -15,12 +15,6 @@ module FakeRedis
|
|
15
15
|
@client.dbsize.should == 2
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should get debugging information about a key" do
|
19
|
-
@client.set("key1", "1")
|
20
|
-
|
21
|
-
@client.debug_object("key1").should == "1".inspect
|
22
|
-
end
|
23
|
-
|
24
18
|
it "should get information and statistics about the server" do
|
25
19
|
@client.info.key?("redis_version").should == true
|
26
20
|
end
|
data/spec/sets_spec.rb
CHANGED
data/spec/sorted_sets_spec.rb
CHANGED
data/spec/strings_spec.rb
CHANGED
data/spec/transactions_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module FakeRedis
|
4
4
|
describe "TransactionsMethods" do
|
5
5
|
before(:each) do
|
6
|
-
@client =
|
6
|
+
@client = Redis.new
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should mark the start of a transaction block" do
|
@@ -13,7 +13,7 @@ module FakeRedis
|
|
13
13
|
@client.mget("key1", "key2")
|
14
14
|
end
|
15
15
|
|
16
|
-
transaction.should == ["1", "2"]
|
16
|
+
transaction.should == ["OK", "OK", ["1", "2"]]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
metadata
CHANGED
@@ -1,35 +1,65 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakeredis
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Guillermo Iguaran
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2011-07-31 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: redis
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
version: 2.2.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
15
38
|
name: rspec
|
16
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
17
41
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 0
|
49
|
+
- 0
|
21
50
|
version: 2.0.0
|
22
51
|
type: :development
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
purposes
|
27
|
-
email:
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Fake (In-memory) driver for redis-rb. Useful for testing environment and machines without Redis.
|
54
|
+
email:
|
28
55
|
- guilleiguaran@gmail.com
|
29
56
|
executables: []
|
57
|
+
|
30
58
|
extensions: []
|
59
|
+
|
31
60
|
extra_rdoc_files: []
|
32
|
-
|
61
|
+
|
62
|
+
files:
|
33
63
|
- .gitignore
|
34
64
|
- .rspec
|
35
65
|
- .travis.yml
|
@@ -39,16 +69,9 @@ files:
|
|
39
69
|
- Rakefile
|
40
70
|
- fakeredis.gemspec
|
41
71
|
- lib/fakeredis.rb
|
42
|
-
- lib/fakeredis/connection.rb
|
43
|
-
- lib/fakeredis/hashes.rb
|
44
|
-
- lib/fakeredis/keys.rb
|
45
|
-
- lib/fakeredis/lists.rb
|
46
|
-
- lib/fakeredis/server.rb
|
47
|
-
- lib/fakeredis/sets.rb
|
48
|
-
- lib/fakeredis/sorted_sets.rb
|
49
|
-
- lib/fakeredis/strings.rb
|
50
|
-
- lib/fakeredis/transactions.rb
|
51
72
|
- lib/fakeredis/version.rb
|
73
|
+
- lib/redis/connection/memory.rb
|
74
|
+
- spec/compatibility_spec.rb
|
52
75
|
- spec/connection_spec.rb
|
53
76
|
- spec/hashes_spec.rb
|
54
77
|
- spec/keys_spec.rb
|
@@ -59,31 +82,42 @@ files:
|
|
59
82
|
- spec/spec_helper.rb
|
60
83
|
- spec/strings_spec.rb
|
61
84
|
- spec/transactions_spec.rb
|
85
|
+
has_rdoc: true
|
62
86
|
homepage: https://github.com/guilleiguaran/fakeredis
|
63
87
|
licenses: []
|
88
|
+
|
64
89
|
post_install_message:
|
65
90
|
rdoc_options: []
|
66
|
-
|
91
|
+
|
92
|
+
require_paths:
|
67
93
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
95
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
104
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
80
112
|
requirements: []
|
113
|
+
|
81
114
|
rubyforge_project: fakeredis
|
82
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.5.2
|
83
116
|
signing_key:
|
84
117
|
specification_version: 3
|
85
|
-
summary: Fake
|
86
|
-
test_files:
|
118
|
+
summary: Fake (In-memory) driver for redis-rb.
|
119
|
+
test_files:
|
120
|
+
- spec/compatibility_spec.rb
|
87
121
|
- spec/connection_spec.rb
|
88
122
|
- spec/hashes_spec.rb
|
89
123
|
- spec/keys_spec.rb
|
data/lib/fakeredis/connection.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module FakeRedis
|
2
|
-
class Redis
|
3
|
-
module ConnectionMethods
|
4
|
-
|
5
|
-
def auth(password)
|
6
|
-
true
|
7
|
-
end
|
8
|
-
|
9
|
-
def echo(string)
|
10
|
-
string
|
11
|
-
end
|
12
|
-
|
13
|
-
def ping
|
14
|
-
"PONG"
|
15
|
-
end
|
16
|
-
|
17
|
-
def quit ; end
|
18
|
-
|
19
|
-
def select(index) ; end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
include ConnectionMethods
|
24
|
-
end
|
25
|
-
end
|
data/lib/fakeredis/hashes.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
module FakeRedis
|
2
|
-
class Redis
|
3
|
-
module HashesMethods
|
4
|
-
def hdel(key, field)
|
5
|
-
return unless @data[key]
|
6
|
-
fail "Not a hash" unless @data[key].is_a?(Hash)
|
7
|
-
@data[key].delete(field)
|
8
|
-
end
|
9
|
-
|
10
|
-
def hexists(key, field)
|
11
|
-
return unless @data[key]
|
12
|
-
fail "Not a hash" unless @data[key].is_a?(Hash)
|
13
|
-
@data[key].key?(field)
|
14
|
-
end
|
15
|
-
|
16
|
-
def hget(key, field)
|
17
|
-
return unless @data[key]
|
18
|
-
fail "Not a hash" unless @data[key].is_a?(Hash)
|
19
|
-
@data[key][field]
|
20
|
-
end
|
21
|
-
|
22
|
-
def hgetall(key)
|
23
|
-
case hash = @data[key]
|
24
|
-
when nil then {}
|
25
|
-
when Hash then hash
|
26
|
-
else fail "Not a hash"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def hincrby(key, field, increment)
|
31
|
-
case hash = @data[key]
|
32
|
-
when nil then @data[key] = { field => value.to_s }
|
33
|
-
when Hash then hash[field] = (hash[field].to_i + increment.to_i).to_s
|
34
|
-
else fail "Not a hash"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def hkeys(key)
|
39
|
-
case hash = @data[key]
|
40
|
-
when nil then []
|
41
|
-
when Hash then hash.keys
|
42
|
-
else fail "Not a hash"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def hlen(key)
|
47
|
-
case hash = @data[key]
|
48
|
-
when nil then 0
|
49
|
-
when Hash then hash.size
|
50
|
-
else fail "Not a hash"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def hmget(key, *fields)
|
55
|
-
values = []
|
56
|
-
fields.each do |field|
|
57
|
-
case hash = @data[key]
|
58
|
-
when nil then values << nil
|
59
|
-
when Hash then values << hash[field]
|
60
|
-
else fail "Not a hash"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
values
|
64
|
-
end
|
65
|
-
|
66
|
-
def hmset(key, *fields)
|
67
|
-
@data[key] ||= {}
|
68
|
-
fail "Not a hash" unless @data[key].is_a?(Hash)
|
69
|
-
fields.each_slice(2) do |field|
|
70
|
-
@data[key][field[0].to_s] = field[1].to_s
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def hset(key, field, value)
|
75
|
-
case hash = @data[key]
|
76
|
-
when nil then @data[key] = { field => value.to_s }
|
77
|
-
when Hash then hash[field] = value.to_s
|
78
|
-
else fail "Not a hash"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def hsetnx(key, field, value)
|
83
|
-
return if (@data[key][field] rescue false)
|
84
|
-
hset(key, field, value)
|
85
|
-
end
|
86
|
-
|
87
|
-
def hvals(key)
|
88
|
-
case hash = @data[key]
|
89
|
-
when nil then []
|
90
|
-
when Hash then hash.values
|
91
|
-
else fail "Not a hash"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
include HashesMethods
|
97
|
-
end
|
98
|
-
end
|
data/lib/fakeredis/keys.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
module FakeRedis
|
2
|
-
class Redis
|
3
|
-
module KeysMethods
|
4
|
-
|
5
|
-
def del(*keys)
|
6
|
-
old_count = @data.keys.size
|
7
|
-
keys.flatten.each do |key|
|
8
|
-
@data.delete(key)
|
9
|
-
@expires.delete(key)
|
10
|
-
end
|
11
|
-
deleted_count = old_count - @data.keys.size
|
12
|
-
end
|
13
|
-
|
14
|
-
def exists(key)
|
15
|
-
@data.key?(key)
|
16
|
-
end
|
17
|
-
|
18
|
-
def expire(key, ttl)
|
19
|
-
return unless @data[key]
|
20
|
-
@expires[key] = ttl
|
21
|
-
true
|
22
|
-
end
|
23
|
-
|
24
|
-
def expireat(key, timestamp)
|
25
|
-
@expires[key] = (Time.at(timestamp) - Time.now).to_i
|
26
|
-
true
|
27
|
-
end
|
28
|
-
|
29
|
-
def keys(pattern = "*")
|
30
|
-
regexp = Regexp.new(pattern.split("*").map { |r| Regexp.escape(r) }.join(".*"))
|
31
|
-
@data.keys.select { |key| key =~ regexp }
|
32
|
-
end
|
33
|
-
|
34
|
-
def persist(key)
|
35
|
-
@expires[key] = -1
|
36
|
-
end
|
37
|
-
|
38
|
-
def randomkey
|
39
|
-
@data.keys[rand(dbsize)]
|
40
|
-
end
|
41
|
-
|
42
|
-
def rename(key, new_key)
|
43
|
-
return unless @data[key]
|
44
|
-
@data[new_key] = @data[key]
|
45
|
-
@expires[new_key] = @expires[key]
|
46
|
-
@data.delete(key)
|
47
|
-
@expires.delete(key)
|
48
|
-
end
|
49
|
-
|
50
|
-
def renamenx(key, new_key)
|
51
|
-
rename(key, new_key) unless exists(new_key)
|
52
|
-
end
|
53
|
-
|
54
|
-
def sort(key)
|
55
|
-
# TODO: Impleent
|
56
|
-
end
|
57
|
-
|
58
|
-
def ttl(key)
|
59
|
-
@expires[key]
|
60
|
-
end
|
61
|
-
|
62
|
-
def type(key)
|
63
|
-
case value = @data[key]
|
64
|
-
when nil then "none"
|
65
|
-
when String then "string"
|
66
|
-
when Hash then "hash"
|
67
|
-
when Array then "list"
|
68
|
-
when Set then "set"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
protected
|
73
|
-
def expired?(key)
|
74
|
-
return false if @expires[key] == -1
|
75
|
-
return true if @expires[key] && @expires[key] < Time.now
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
include KeysMethods
|
81
|
-
end
|
82
|
-
end
|