Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
resolved backwards compatability issue and added support for jruby
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughanbrittonsage committed Jun 26, 2017
1 parent c5b645b commit f777735
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
9 changes: 9 additions & 0 deletions cache_store_redis/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in cache_store_redis.gemspec
gemspec

platforms :ruby do
gem 'oj', '2.15.0'
gem 'pry'
end

platforms :jruby do
gem 'pry-debugger-jruby'
end
13 changes: 9 additions & 4 deletions cache_store_redis/cache_store_redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "pry"
spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_dependency('redis')

if RUBY_PLATFORM =~ /java/
spec.platform = 'java'
else
spec.add_dependency('oj')
end

end
25 changes: 23 additions & 2 deletions cache_store_redis/lib/cache_store_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
class RedisCacheStore

def initialize(namespace = nil, config = nil)

if RUBY_PLATFORM != 'java'
require 'oj'
end

@namespace = namespace
if config == nil
@client = Redis.new
Expand Down Expand Up @@ -43,7 +48,7 @@ def set(key, value, expires_in = 0)
k = build_key(key)

if value != nil
v = Marshal::dump(value)
v = serialize(value)
end

@client.set(k, v)
Expand All @@ -65,7 +70,7 @@ def get(key, expires_in = 0, &block)
k = build_key(key)

value = @client.get(k)
value = Marshal::load(value) unless value == nil
value = deserialize(value) unless value == nil

if value.nil? && block_given?
value = yield
Expand Down Expand Up @@ -103,6 +108,22 @@ def ping

private

def serialize(object)
if RUBY_PLATFORM == 'java'
Marshal::dump(object)
else
Oj.dump(object)
end
end

def deserialize(object)
if RUBY_PLATFORM == 'java'
Marshal::load(object)
else
Oj.load(object)
end
end

def build_key(key)
k = ''
if @namespace != nil
Expand Down
2 changes: 1 addition & 1 deletion cache_store_redis/lib/cache_store_redis/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CacheStoreRedis
VERSION = '0.3.0'
VERSION = '0.3.2'
end
9 changes: 9 additions & 0 deletions cache_store_redis/script/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ testrunner:
links:
- redis

testrunner2:
image: 522104923602.dkr.ecr.eu-west-1.amazonaws.com/sageone/jruby:20170623
container_name: testrunner_jruby
command: sh -c "while true; do echo 'Container is running..'; sleep 5; done"
volumes:
- ../:/code
links:
- redis

3 changes: 2 additions & 1 deletion cache_store_redis/script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
echo start rspec tests
docker-compose up -d

docker exec -it testrunner bash -c "bundle install && bundle exec rspec $*"
docker exec -it testrunner bash -c "bundle install && bundle exec rspec $*" \
&& docker exec -it testrunner_jruby bash -c "cd code && rm -rf Gemfile.lock && jruby -S bundle install && jruby -S rspec $*"

0 comments on commit f777735

Please sign in to comment.