Skip to content

Commit

Permalink
Merge pull request #212 from dfens/master
Browse files Browse the repository at this point in the history
Fix for long key_with_namespace
  • Loading branch information
mperham committed May 8, 2012
2 parents ee5193e + f41089d commit a578a6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/dalli/client.rb
Expand Up @@ -243,8 +243,7 @@ def env_servers
# Chokepoint method for instrumentation
def perform(op, key, *args)
key = key.to_s
validate_key(key)
key = key_with_namespace(key)
key = validate_key(key)
begin
server = ring.server_for_key(key)
server.request(op, key, *args)
Expand All @@ -257,7 +256,9 @@ def perform(op, key, *args)

def validate_key(key)
raise ArgumentError, "key cannot be blank" if !key || key.length == 0
key = key_with_namespace(key)
raise ArgumentError, "key too long #{key.inspect}" if key.length > 250
return key
end

def key_with_namespace(key)
Expand Down
5 changes: 5 additions & 0 deletions test/test_dalli.rb
Expand Up @@ -404,6 +404,11 @@
dc2.set('namespaced', 2)
assert_equal 1, dc.get('namespaced')
assert_equal 2, dc2.get('namespaced')

dc3 = Dalli::Client.new('localhost:19122', :namespace => 'c' * 100)
assert_raises ArgumentError do
dc3.get "a" * 151
end
end
end

Expand Down

1 comment on commit a578a6b

@dfens
Copy link
Collaborator

@dfens dfens commented on a578a6b May 8, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

Please sign in to comment.