fakeredis 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["guilleiguaran@gmail.com"]
11
11
  s.homepage = "https://github.com/guilleiguaran/fakeredis"
12
12
  s.summary = %q{Fake redis-rb for your tests}
13
- s.description = %q{Fake implementation of redis-rb for machines without Redis or test environments}
13
+ s.description = %q{Fake implementation of redis-rb for machines without Redis or for testing purposes}
14
14
 
15
15
  s.rubyforge_project = "fakeredis"
16
16
 
@@ -1,6 +1,34 @@
1
1
 
2
2
  module FakeRedis
3
3
  class Redis
4
+ class Client
5
+ attr_accessor :host, :port, :db, :path, :password, :logger, :reconnect
6
+ def initialize(options = {})
7
+ @path = options[:path]
8
+ @host = options[:host] || "127.0.0.1"
9
+ @port = (options[:port] || 6379).to_i
10
+ @password = options[:password]
11
+ @db = (options[:db] || 0).to_i
12
+ @logger = options[:logger]
13
+ @reconnect = true
14
+ end
15
+
16
+ def id
17
+ "redis://#{@host}:#{@port}/#{@db}"
18
+ end
19
+
20
+ def connect
21
+ self
22
+ end
23
+
24
+ def connected?
25
+ true
26
+ end
27
+
28
+ def method_missing(command, *args, &block)
29
+ true
30
+ end
31
+ end
4
32
 
5
33
  def self.connect(options = {})
6
34
  new(options)
@@ -9,6 +37,11 @@ module FakeRedis
9
37
  def initialize(options = {})
10
38
  @data = {}
11
39
  @expires = {}
40
+ @client = Client.new(options)
41
+ end
42
+
43
+ def client
44
+ @client
12
45
  end
13
46
  end
14
47
  end
@@ -26,7 +26,7 @@ module FakeRedis
26
26
  true
27
27
  end
28
28
 
29
- def keys(pattern)
29
+ def keys(pattern = "*")
30
30
  regexp = Regexp.new(pattern.split("*").map { |r| Regexp.escape(r) }.join(".*"))
31
31
  @data.keys.select { |key| key =~ regexp }
32
32
  end
@@ -58,7 +58,7 @@ module FakeRedis
58
58
  fail_unless_set(key)
59
59
  case set = @data[key]
60
60
  when nil then []
61
- when Set then set.to_a
61
+ when Set then set.to_a.reverse
62
62
  end
63
63
  end
64
64
 
@@ -54,6 +54,11 @@ module FakeRedis
54
54
  @data.values_at(*keys)
55
55
  end
56
56
 
57
+ def mapped_mget(*keys)
58
+ reply = mget(*keys)
59
+ Hash[*keys.zip(reply).flatten]
60
+ end
61
+
57
62
  def mset(*pairs)
58
63
  pairs.each_slice(2) do |pair|
59
64
  @data[pair[0].to_s] = pair[1].to_s
@@ -1,3 +1,3 @@
1
1
  module FakeRedis
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -79,6 +79,17 @@ module FakeRedis
79
79
  @client.mget("key1", "key2", "key3").should == ["value1", "value2", "value3"]
80
80
  end
81
81
 
82
+ it "should get the values of all the given keys mapped" do
83
+ @client.set("key1", "value1")
84
+ @client.set("key2", "value2")
85
+ @client.set("key3", "value3")
86
+ response = @client.mapped_mget("key1", "key2", "key3")
87
+
88
+ response["key1"].should == "value1"
89
+ response["key2"].should == "value2"
90
+ response["key3"].should == "value3"
91
+ end
92
+
82
93
  it "should set multiple keys to multiple values" do
83
94
  @client.mset(:key1, "value1", :key2, "value2")
84
95
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fakeredis
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Guillermo Iguaran
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-16 00:00:00 Z
13
+ date: 2011-04-17 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: 2.0.0
24
24
  type: :development
25
25
  version_requirements: *id001
26
- description: Fake implementation of redis-rb for machines without Redis or test environments
26
+ description: Fake implementation of redis-rb for machines without Redis or for testing purposes
27
27
  email:
28
28
  - guilleiguaran@gmail.com
29
29
  executables: []