는 루비와 함께 단축 URL 알고리즘을 생성 + MongoMapper경쟁 조건, URL 축약 알고리즘/레일/MongoDB를/MongoMapper
그것은 최대 3 자리와 간단한 URL 축약 알고리즘의 http://pablocantero.com/###
각 #은 어디에서 할 수 있습니다 [AZ] 또는이 알고리즘의 [AZ] 또는 [0-9]
, 난
class ShortenerData
include MongoMapper::Document
VALUES = ('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a
key :col_a, Integer
key :col_b, Integer
key :col_c, Integer
key :index, Integer
end
,536 ( MongoMapper 통해) MongoDB의 4 개 개의 특성을 유지해야
나는 ShortenerData를 관리하고 나는 내 애플 배포 동기화 get_unique 될 것입니다 수있는 방법을 고유 식별자
class Shortener
include Singleton
def get_unique
unique = nil
@shortener_data.reload
# some operations that can increment the attributes col_a, col_b, col_c and index
# ...
@shortener_data.save
unique
end
end
에게
Shortener.instance.get_unique
내 의심의 여지가입니다 Shortener를 사용을 생성하는 다른 클래스를 생성 heroku에서 동시 요청을 할 수 있습니다 Shortener.instance.get_unique