Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove the lua script cache.

(I'm going to implement a better solution next).
  • Loading branch information...
commit b89dbbd1ab7899bf5f0a4a98a9bcecdb07814167 1 parent 6e5d89a
Myron Marston myronmarston authored
8 lib/qless.rb
View
@@ -14,11 +14,11 @@ module Qless
USING_LEGACY_REDIS_VERSION = ::Redis::VERSION.to_f < 3.0
end
-require "qless/lua_script_cache"
require "qless/version"
require "qless/config"
require "qless/queue"
require "qless/job"
+require "qless/lua_script"
module Qless
extend self
@@ -40,10 +40,6 @@ def worker_name
@worker_name ||= [Socket.gethostname, Process.pid.to_s].join('-')
end
- def lua_script_cache
- @lua_script_cache ||= LuaScriptCache.new
- end
-
class ClientJobs
def initialize(client)
@client = client
@@ -163,7 +159,7 @@ def initialize(options = {})
['cancel', 'config', 'complete', 'depends', 'fail', 'failed', 'get', 'heartbeat', 'jobs', 'peek', 'pop',
'priority', 'put', 'queues', 'recur', 'retry', 'stats', 'tag', 'track', 'workers', 'pause', 'unpause',
'deregister_workers'].each do |f|
- self.instance_variable_set("@_#{f}", Qless.lua_script_cache.script_for(f, @redis))
+ self.instance_variable_set("@_#{f}", Qless::LuaScript.new(f, @redis))
end
@jobs = ClientJobs.new(self)
22 lib/qless/lua_script_cache.rb
View
@@ -1,22 +0,0 @@
-require 'qless/lua_script'
-
-module Qless
- class LuaScriptCache
- def initialize
- @sha_cache = {}
- end
-
- def script_for(script_name, redis_connection)
- key = CacheKey.new(script_name, redis_connection.id)
-
- sha = @sha_cache.fetch(key) do
- @sha_cache[key] = LuaScript.new(script_name, redis_connection).sha
- end
-
- LuaScript.new(script_name, redis_connection, sha)
- end
-
- CacheKey = Struct.new(:script_name, :redis_server_url)
- end
-end
-
35 spec/integration/lua_script_cache_spec.rb
View
@@ -1,35 +0,0 @@
-require 'spec_helper'
-require "qless"
-require 'yaml'
-
-module Qless
- describe LuaScriptCache, :integration do
- def ensure_put_script_loaded(client)
- client.queues["q1"].put(Qless::Job, {})
- end
-
- let(:redis_1) { Redis.new(url: redis_url) }
- let(:redis_2) { Redis.new(url: redis_url) }
- let(:client_1) { Qless::Client.new(redis: redis_1) }
- let(:client_2) { Qless::Client.new(redis: redis_2) }
-
- before { stub_const("SomeJob", Class.new) }
-
- it 'does not prevent watch-multi-exec blocks from working properly' do
- ensure_put_script_loaded(client_1)
- ensure_put_script_loaded(client_2)
-
- redis_2.watch("some_key") do
- response = redis_2.multi do
- redis_1.set("some_key", "some_value") # force the multi block to no-op
- client_2.queues["some_job"].put(SomeJob, {})
- end
-
- expect(response).to be_nil
- end
-
- expect(client_2.queues["some_job"].length).to eq(0)
- end
- end
-end
-
56 spec/unit/lua_script_cache_spec.rb
View
@@ -1,56 +0,0 @@
-require 'spec_helper'
-require 'qless'
-require 'qless/lua_script_cache'
-
-module Qless
- describe LuaScriptCache do
- def redis_double(db_num)
- fire_double("Redis", id: "redis://foo:1234/#{db_num}").tap do |redis|
- redis.stub(:script) do |script_contents|
- script_contents
- end
- end
- end
-
- let(:redis_1a) { redis_double(1) }
- let(:redis_1b) { redis_double(1) }
- let(:redis_2) { redis_double(2) }
- let(:cache) { LuaScriptCache.new }
-
- before do
- File.stub(:read) do |file_name|
- file_name.split('/').last
- end
- end
-
- it 'loads each different script' do
- redis_1a.should_receive(:script).twice
-
- script_1 = cache.script_for("foo", redis_1a)
- script_2 = cache.script_for("bar", redis_1a)
-
- expect(script_1).to be_a(LuaScript)
- expect(script_2).to be_a(LuaScript)
-
- expect(script_1.name).to eq("foo")
- expect(script_2.name).to eq("bar")
- end
-
- it 'loads the same script each time it is needed in a different redis server' do
- redis_1a.should_receive(:script).once
- redis_2.should_receive(:script).once
-
- cache.script_for("foo", redis_1a)
- cache.script_for("foo", redis_2)
- end
-
- it 'loads a script only once when it is needed by multiple connections to the same redis server' do
- redis_1a.should_receive(:script).once
- redis_1b.should_not_receive(:script)
-
- cache.script_for("foo", redis_1a)
- cache.script_for("foo", redis_1b)
- end
- end
-end
-
18 spec/unit/qless_spec.rb
View
@@ -18,13 +18,6 @@
end
end
- describe ".lua_script_cache" do
- it 'returns a memoized script cache instance' do
- expect(Qless.lua_script_cache).to be_a(Qless::LuaScriptCache)
- expect(Qless.lua_script_cache).to be(Qless.lua_script_cache)
- end
- end
-
context 'when instantiated' do
let(:redis) { fire_double("Redis", id: "redis://foo:1/1", info: { "redis_version" => "2.6.0" }) }
let(:redis_class) { fire_replaced_class_double("Redis") }
@@ -55,17 +48,6 @@
client = Qless::Client.new(redis: redis)
client.redis.should be(redis)
end
-
- it 'loads the lua scripts from the cache so that the scripts are not unnecessarily loaded multiple times' do
- cache = fire_double("Qless::LuaScriptCache")
- Qless.stub(lua_script_cache: cache)
-
- loaded_scripts = []
- cache.stub(:script_for) { |name, redis| loaded_scripts << name }
-
- client = Qless::Client.new(redis: redis)
- expect(loaded_scripts).to include("put", "complete")
- end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.