Skip to content

Commit

Permalink
implementing the substr method
Browse files Browse the repository at this point in the history
  • Loading branch information
David Pick committed Apr 19, 2012
1 parent 96b035d commit c6a27ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/redis/connection/memory.rb
Expand Up @@ -120,7 +120,6 @@ def read
# * subscribe
# * psubscribe
# * publish
# * substr
# * zremrangebyrank
# * zunionstore
def flushdb
Expand Down Expand Up @@ -173,6 +172,7 @@ def getrange(key, start, ending)
return unless @data[key]
@data[key][start..ending]
end
alias :substr :getrange

def getset(key, value)
old_value = @data[key]
Expand Down
7 changes: 4 additions & 3 deletions spec/strings_spec.rb
Expand Up @@ -48,6 +48,7 @@ module FakeRedis
@client.set("key1", "This a message")

@client.getrange("key1", 0, 3).should == "This"
@client.substr("key1", 0, 3).should == "This"
end

it "should set the string value of a key and return its old value" do
Expand All @@ -56,7 +57,7 @@ module FakeRedis
@client.getset("key1", "value2").should == "value1"
@client.get("key1").should == "value2"
end

it "should return nil for #getset if the key does not exist when setting" do
@client.getset("key1", "value1").should == nil
@client.get("key1").should == "value1"
Expand All @@ -68,11 +69,11 @@ module FakeRedis

@client.get("counter").should == "2"
end

it "should decrement the integer value of a key by one" do
@client.set("counter", "1")
@client.decr("counter").should == 0

@client.get("counter").should == "0"
end

Expand Down

0 comments on commit c6a27ea

Please sign in to comment.