-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from i2bskn/feature/0.2.0
v0.2.0
- Loading branch information
Showing
29 changed files
with
244 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: ruby | ||
rvm: | ||
- 2.1.7 | ||
- 2.2.3 | ||
before_install: gem install bundler -v 1.10.6 | ||
- 2.3.3 | ||
- 2.4.1 | ||
before_install: gem install bundler -v 1.14.6 | ||
services: | ||
- redis-server |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
source 'https://rubygems.org' | ||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in redis_eval.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
require "rake/testtask" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << "test" | ||
t.libs << "lib" | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
end | ||
|
||
task :default => :spec | ||
task :default => :test |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,46 @@ | ||
module RedisEval | ||
class Script | ||
attr_reader :name, :script, :sha | ||
attr_accessor :parent | ||
attr_reader :source, :sha | ||
|
||
class << self | ||
# @param path [Pathname] | ||
# @return [RedisEval::Script] | ||
def build_from_path(path) | ||
name = path.basename(".*").to_s | ||
script = File.read(path) | ||
new(name, script) | ||
end | ||
|
||
def load(script) | ||
redis.script(:load, script) | ||
end | ||
def self.build_from_parent(src, parent, with_load: true) | ||
script = new(src, with_load: with_load) | ||
script.parent = parent | ||
script | ||
end | ||
|
||
def flush | ||
redis.script(:flush) | ||
end | ||
def initialize(src, with_load: true) | ||
@source = src | ||
@sha = Digest::SHA1.hexdigest(@source) | ||
@redis = nil | ||
self.load if with_load | ||
end | ||
|
||
def redis | ||
RedisEval.config.redis | ||
end | ||
def load | ||
redis.script(:load, source) | ||
end | ||
|
||
def initialize(name, script) | ||
@name = name | ||
@script = script | ||
@sha = Digest::SHA1.hexdigest(script) | ||
def exist? | ||
redis.script(:exists, sha) | ||
end | ||
|
||
def execute(keys = [], argv = []) | ||
redis.evalsha(sha, Array(keys), Array(argv)) | ||
rescue Redis::CommandError => e | ||
if e.message =~ /NOSCRIPT/ | ||
redis.eval(script, Array(keys), Array(argv)) | ||
redis.eval(source, Array(keys), Array(argv)) | ||
else | ||
raise | ||
end | ||
end | ||
|
||
def exist? | ||
redis.script(:exists, sha) | ||
def redis | ||
return @redis if @redis | ||
parent ? parent.redis : Redis.current | ||
end | ||
|
||
def redis | ||
self.class.redis | ||
def redis=(conn) | ||
@redis = conn | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module RedisEval | ||
class ScriptSet | ||
attr_reader :path | ||
|
||
SCRIPT_SUFFIX = ".lua" | ||
|
||
def initialize(target_path, conn = nil) | ||
@path = pathname(target_path) | ||
@redis = conn | ||
end | ||
|
||
def load(name) | ||
source = script_path(name).read | ||
loaded_scripts[name.to_s] ||= RedisEval::Script.build_from_parent(source, self) | ||
end | ||
|
||
def load_all | ||
path.children(false).each do |child| | ||
name = child.basename(SCRIPT_SUFFIX).to_s | ||
source = script_path(name).read | ||
loaded_scripts[name] ||= RedisEval::Script.build_from_parent(source, self) | ||
end | ||
true | ||
end | ||
|
||
def redis | ||
@redis || Redis.current | ||
end | ||
|
||
def redis=(conn) | ||
@redis = conn | ||
end | ||
|
||
private | ||
|
||
def pathname(path) | ||
path.is_a?(Pathname) ? path : Pathname.new(path) | ||
end | ||
|
||
def loaded_scripts | ||
@loaded_scripts ||= {} | ||
end | ||
|
||
def script_path(name) | ||
path.join(name.to_s).sub_ext(SCRIPT_SUFFIX) | ||
end | ||
|
||
def method_missing(name, *args, &block) | ||
super unless respond_to?(name) | ||
|
||
self.load(name) | ||
define_singleton_method(name) { |*a, &b| loaded_scripts[name.to_s] } | ||
send(name, *args, &block) | ||
end | ||
|
||
def respond_to_missing?(name, include_private = false) | ||
loaded_scripts.has_key?(name.to_s) || script_path(name).exist? || super | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.