0
ID 큐를 유지해야하는 Ruby on Rails 응용 프로그램이 있습니다. 대기열로 전역 배열을 사용하려고했지만 내 애플 리케이션의 여러 인스턴스가 실행되는 경우 글로벌 애플 리케이션에서 글로벌 변수를 읽을 중지합니다. 그러면 응용 프로그램 전체 대기열을 어떻게 유지할 수 있습니까?내 Rails 응용 프로그램에서 전역 큐 데이터 구조 구현
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :update_queue, :get_next_free_agent
$agent_queue = []
def update_queue(agent)
if agent.status == "AVAILABLE"
if agent_queue.find_index(agent.reg_id) == nil
$agent_queue.push(agent.reg_id)
end
else
$agent_queue.delete(agent.reg_id)
end
end
def get_next_free_agent
return agent_queue.shift
end
end
을 나도이 일을하지 않으며, 내가 어떻게 전역 변수 영역 나쁜 생각에 대한 책을 읽은 후 그것을 더 이상 사용 하시겠습니까 :
은 여기 내와 ApplicationController 보이는 방법은 없습니다. 대체 솔루션을 제공하십시오.
감사합니다.
http://redis.io/ – deefour
지적한대로 모든 키 - 값 저장소. Redis, Memcached 등 – Kashyap