redis-activesupport-4.1.0/0000755000004100000410000000000012553424516015567 5ustar www-datawww-dataredis-activesupport-4.1.0/Rakefile0000644000004100000410000000014712553424516017236 0ustar www-datawww-datarequire 'bundler/setup' require 'rake' require 'bundler/gem_tasks' require 'redis-store/testing/tasks' redis-activesupport-4.1.0/Gemfile0000644000004100000410000000023112553424516017056 0ustar www-datawww-datasource 'https://rubygems.org' gemspec if ::File.directory?(gem_path = '../redis-store') gem 'redis-store', '~> 1.1.0', path: gem_path end gem 'i18n' redis-activesupport-4.1.0/MIT-LICENSE0000644000004100000410000000204512553424516017224 0ustar www-datawww-dataCopyright (c) 2009 - 2011 Luca Guidi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. redis-activesupport-4.1.0/redis-activesupport.gemspec0000644000004100000410000000227412553424516023155 0ustar www-datawww-data# -*- encoding: utf-8 -*- $:.push File.expand_path('../lib', __FILE__) require 'redis/activesupport/version' Gem::Specification.new do |s| s.name = 'redis-activesupport' s.version = Redis::ActiveSupport::VERSION s.authors = ['Luca Guidi'] s.email = ['me@lucaguidi.com'] s.homepage = 'http://redis-store.org/redis-activesupport' s.summary = %q{Redis store for ActiveSupport} s.description = %q{Redis store for ActiveSupport} s.license = 'MIT' s.rubyforge_project = 'redis-activesupport' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ['lib'] s.add_runtime_dependency 'redis-store', '~> 1.1.0' s.add_runtime_dependency 'activesupport', '~> 4' s.add_development_dependency 'rake', '~> 10' s.add_development_dependency 'bundler', '~> 1.3' s.add_development_dependency 'mocha', '~> 0.14.0' s.add_development_dependency 'minitest', '~> 4.2' s.add_development_dependency 'connection_pool', '~> 1.2.0' s.add_development_dependency 'redis-store-testing' end redis-activesupport-4.1.0/.travis.yml0000644000004100000410000000034012553424516017675 0ustar www-datawww-datalanguage: ruby script: 'bundle exec rake' rvm: - 1.9.3 - 2.0.0 - ruby-head - rbx-19mode - jruby-19mode - jruby-head services: - redis-server matrix: allow_failures: - rvm: jruby-head - rvm: ruby-head redis-activesupport-4.1.0/lib/0000755000004100000410000000000012553424516016335 5ustar www-datawww-dataredis-activesupport-4.1.0/lib/redis-activesupport.rb0000644000004100000410000000017712553424516022703 0ustar www-datawww-datarequire 'redis-store' require 'active_support' require 'redis/activesupport/version' require 'active_support/cache/redis_store'redis-activesupport-4.1.0/lib/active_support/0000755000004100000410000000000012553424516021404 5ustar www-datawww-dataredis-activesupport-4.1.0/lib/active_support/cache/0000755000004100000410000000000012553424516022447 5ustar www-datawww-dataredis-activesupport-4.1.0/lib/active_support/cache/redis_store.rb0000644000004100000410000002076212553424516025325 0ustar www-datawww-data# encoding: UTF-8 require 'redis-store' module ActiveSupport module Cache class RedisStore < Store attr_reader :data # Instantiate the store. # # Example: # RedisStore.new # # => host: localhost, port: 6379, db: 0 # # RedisStore.new "example.com" # # => host: example.com, port: 6379, db: 0 # # RedisStore.new "example.com:23682" # # => host: example.com, port: 23682, db: 0 # # RedisStore.new "example.com:23682/1" # # => host: example.com, port: 23682, db: 1 # # RedisStore.new "example.com:23682/1/theplaylist" # # => host: example.com, port: 23682, db: 1, namespace: theplaylist # # RedisStore.new "localhost:6379/0", "localhost:6380/0" # # => instantiate a cluster # # RedisStore.new "localhost:6379/0", "localhost:6380/0", pool_size: 5, pool_timeout: 10 # # => use a ConnectionPool # # RedisStore.new "localhost:6379/0", "localhost:6380/0", # pool: ::ConnectionPool.new(size: 1, timeout: 1) { ::Redis::Store::Factory.create("localhost:6379/0") }) # # => supply an existing connection pool (e.g. for use with redis-sentinel or redis-failover) def initialize(*addresses) @options = addresses.extract_options! @data = if @options[:pool] raise "pool must be an instance of ConnectionPool" unless @options[:pool].is_a?(ConnectionPool) @pooled = true @options[:pool] elsif [:pool_size, :pool_timeout].any? { |key| @options.has_key?(key) } pool_options = {} pool_options[:size] = options[:pool_size] if options[:pool_size] pool_options[:timeout] = options[:pool_timeout] if options[:pool_timeout] @pooled = true ::ConnectionPool.new(pool_options) { ::Redis::Store::Factory.create(addresses) } else ::Redis::Store::Factory.create(addresses) end super(@options) end def write(name, value, options = nil) options = merged_options(options) instrument(:write, name, options) do |payload| entry = options[:raw].present? ? value : Entry.new(value, options) write_entry(namespaced_key(name, options), entry, options) end end # Delete objects for matched keys. # # Performance note: this operation can be dangerous for large production # databases, as it uses the Redis "KEYS" command, which is O(N) over the # total number of keys in the database. Users of large Redis caches should # avoid this method. # # Example: # cache.delete_matched "rab*" def delete_matched(matcher, options = nil) options = merged_options(options) instrument(:delete_matched, matcher.inspect) do matcher = key_matcher(matcher, options) begin with do |store| !(keys = store.keys(matcher)).empty? && store.del(*keys) end rescue Errno::ECONNREFUSED, Redis::CannotConnectError false end end end # Reads multiple keys from the cache using a single call to the # servers for all keys. Options can be passed in the last argument. # # Example: # cache.read_multi "rabbit", "white-rabbit" # cache.read_multi "rabbit", "white-rabbit", :raw => true def read_multi(*names) options = names.extract_options! keys = names.map{|name| namespaced_key(name, options)} values = with { |c| c.mget(*keys) } values.map! { |v| v.is_a?(ActiveSupport::Cache::Entry) ? v.value : v } # Remove the options hash before mapping keys to values names.extract_options! result = Hash[keys.zip(values)] result.reject!{ |k,v| v.nil? } result end def fetch_multi(*names) results = read_multi(*names) options = names.extract_options! fetched = {} with do |c| c.multi do fetched = names.inject({}) do |memo, (name, _)| key = namespaced_key(name, options) memo[key] = results.fetch(key) do value = yield name write(name, value, options) value end memo end end end fetched end # Increment a key in the store. # # If the key doesn't exist it will be initialized on 0. # If the key exist but it isn't a Fixnum it will be initialized on 0. # # Example: # We have two objects in cache: # counter # => 23 # rabbit # => # # # cache.increment "counter" # cache.read "counter", :raw => true # => "24" # # cache.increment "counter", 6 # cache.read "counter", :raw => true # => "30" # # cache.increment "a counter" # cache.read "a counter", :raw => true # => "1" # # cache.increment "rabbit" # cache.read "rabbit", :raw => true # => "1" def increment(key, amount = 1) instrument(:increment, key, :amount => amount) do with{|c| c.incrby key, amount} end end # Decrement a key in the store # # If the key doesn't exist it will be initialized on 0. # If the key exist but it isn't a Fixnum it will be initialized on 0. # # Example: # We have two objects in cache: # counter # => 23 # rabbit # => # # # cache.decrement "counter" # cache.read "counter", :raw => true # => "22" # # cache.decrement "counter", 2 # cache.read "counter", :raw => true # => "20" # # cache.decrement "a counter" # cache.read "a counter", :raw => true # => "-1" # # cache.decrement "rabbit" # cache.read "rabbit", :raw => true # => "-1" def decrement(key, amount = 1) instrument(:decrement, key, :amount => amount) do with{|c| c.decrby key, amount} end end def expire(key, ttl) with { |c| c.expire key, ttl } end # Clear all the data from the store. def clear instrument(:clear, nil, nil) do with(&:flushdb) end end # fixed problem with invalid exists? method # https://github.com/rails/rails/commit/cad2c8f5791d5bd4af0f240d96e00bae76eabd2f def exist?(name, options = nil) res = super(name, options) res || false end def stats with(&:info) end def with(&block) if @pooled @data.with(&block) else block.call(@data) end end def reconnect @data.reconnect if @data.respond_to?(:reconnect) end protected def write_entry(key, entry, options) method = options && options[:unless_exist] ? :setnx : :set with { |client| client.send method, key, entry, options } rescue Errno::ECONNREFUSED, Redis::CannotConnectError false end def read_entry(key, options) entry = with { |c| c.get key, options } if entry entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry) end rescue Errno::ECONNREFUSED, Redis::CannotConnectError nil end ## # Implement the ActiveSupport::Cache#delete_entry # # It's really needed and use # def delete_entry(key, options) entry = with { |c| c.del key } rescue Errno::ECONNREFUSED, Redis::CannotConnectError false end # Add the namespace defined in the options to a pattern designed to match keys. # # This implementation is __different__ than ActiveSupport: # __it doesn't accept Regular expressions__, because the Redis matcher is designed # only for strings with wildcards. def key_matcher(pattern, options) prefix = options[:namespace].is_a?(Proc) ? options[:namespace].call : options[:namespace] if prefix raise "Regexps aren't supported, please use string with wildcards." if pattern.is_a?(Regexp) "#{prefix}:#{pattern}" else pattern end end end end end redis-activesupport-4.1.0/lib/redis/0000755000004100000410000000000012553424516017443 5ustar www-datawww-dataredis-activesupport-4.1.0/lib/redis/activesupport/0000755000004100000410000000000012553424516022353 5ustar www-datawww-dataredis-activesupport-4.1.0/lib/redis/activesupport/version.rb0000644000004100000410000000010312553424516024357 0ustar www-datawww-dataclass Redis module ActiveSupport VERSION = '4.1.0' end end redis-activesupport-4.1.0/metadata.yml0000644000004100000410000001032312553424516020071 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: redis-activesupport version: !ruby/object:Gem::Version version: 4.1.0 platform: ruby authors: - Luca Guidi autorequire: bindir: bin cert_chain: [] date: 2015-07-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: redis-store requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 1.1.0 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 1.1.0 - !ruby/object:Gem::Dependency name: activesupport requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '10' - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' - !ruby/object:Gem::Dependency name: mocha requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.14.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.14.0 - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4.2' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '4.2' - !ruby/object:Gem::Dependency name: connection_pool requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 1.2.0 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 1.2.0 - !ruby/object:Gem::Dependency name: redis-store-testing requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: Redis store for ActiveSupport email: - me@lucaguidi.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".travis.yml" - Gemfile - MIT-LICENSE - README.md - Rakefile - lib/active_support/cache/redis_store.rb - lib/redis-activesupport.rb - lib/redis/activesupport/version.rb - redis-activesupport.gemspec - test/active_support/cache/redis_store_test.rb - test/redis/activesupport/version_test.rb - test/test_helper.rb homepage: http://redis-store.org/redis-activesupport licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: redis-activesupport rubygems_version: 2.4.8 signing_key: specification_version: 4 summary: Redis store for ActiveSupport test_files: - test/active_support/cache/redis_store_test.rb - test/redis/activesupport/version_test.rb - test/test_helper.rb redis-activesupport-4.1.0/test/0000755000004100000410000000000012553424516016546 5ustar www-datawww-dataredis-activesupport-4.1.0/test/test_helper.rb0000644000004100000410000000021612553424516021410 0ustar www-datawww-datarequire 'bundler/setup' require 'minitest/autorun' require 'mocha/setup' require 'active_support' require 'active_support/cache/redis_store' redis-activesupport-4.1.0/test/active_support/0000755000004100000410000000000012553424516021615 5ustar www-datawww-dataredis-activesupport-4.1.0/test/active_support/cache/0000755000004100000410000000000012553424516022660 5ustar www-datawww-dataredis-activesupport-4.1.0/test/active_support/cache/redis_store_test.rb0000644000004100000410000003251712553424516026576 0ustar www-datawww-datarequire 'test_helper' require 'ostruct' require 'connection_pool' describe ActiveSupport::Cache::RedisStore do def setup @store = ActiveSupport::Cache::RedisStore.new @dstore = ActiveSupport::Cache::RedisStore.new "redis://127.0.0.1:6379/5", "redis://127.0.0.1:6379/6" @pool_store = ActiveSupport::Cache::RedisStore.new("redis://127.0.0.1:6379/2", pool_size: 5, pool_timeout: 10) @external_pool_store = ActiveSupport::Cache::RedisStore.new(pool: ::ConnectionPool.new(size: 1, timeout: 1) { ::Redis::Store::Factory.create("redis://127.0.0.1:6379/3") }) @pool_store.data.class.must_equal ::ConnectionPool @pool_store.data.instance_variable_get(:@size).must_equal 5 @external_pool_store.data.class.must_equal ::ConnectionPool @external_pool_store.data.instance_variable_get(:@size).must_equal 1 @rabbit = OpenStruct.new :name => "bunny" @white_rabbit = OpenStruct.new :color => "white" with_store_management do |store| store.write "rabbit", @rabbit store.delete "counter" store.delete "rub-a-dub" end end it "raises an error if :pool isn't a pool" do assert_raises(RuntimeError, 'pool must be an instance of ConnectionPool') do ActiveSupport::Cache::RedisStore.new(pool: 'poolio') end end it "namespaces all operations" do address = "redis://127.0.0.1:6380/1/cache-namespace" store = ActiveSupport::Cache::RedisStore.new(address) redis = Redis.new(url: address) store.write("white-rabbit", 0) redis.exists('cache-namespace:white-rabbit').must_equal(true) end it "creates a normal store when given no addresses" do underlying_store = instantiate_store underlying_store.must_be_instance_of(::Redis::Store) end it "creates a normal store when given options only" do underlying_store = instantiate_store(:expires_in => 1.second) underlying_store.must_be_instance_of(::Redis::Store) end it "creates a normal store when given a single address" do underlying_store = instantiate_store("redis://127.0.0.1:6380/1") underlying_store.must_be_instance_of(::Redis::Store) end it "creates a normal store when given a single address and options" do underlying_store = instantiate_store("redis://127.0.0.1:6380/1", { :expires_in => 1.second}) underlying_store.must_be_instance_of(::Redis::Store) end it "creates a distributed store when given multiple addresses" do underlying_store = instantiate_store("redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1") underlying_store.must_be_instance_of(::Redis::DistributedStore) end it "creates a distributed store when given multiple address and options" do underlying_store = instantiate_store("redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1", :expires_in => 1.second) underlying_store.must_be_instance_of(::Redis::DistributedStore) end it "reads the data" do with_store_management do |store| store.read("rabbit").must_equal(@rabbit) end end it "writes the data" do with_store_management do |store| store.write "rabbit", @white_rabbit store.read("rabbit").must_equal(@white_rabbit) end end it "writes the data with specified namespace" do with_store_management do |store| store.write "rabbit", @white_rabbit, namespace:'namespaced' store.read("namespaced:rabbit").must_equal(@white_rabbit) end end it "writes the data with expiration time" do with_store_management do |store| store.write "rabbit", @white_rabbit, :expires_in => 1.second store.read("rabbit").must_equal(@white_rabbit) sleep 2 store.read("rabbit").must_be_nil end end it "respects expiration time in seconds" do with_store_management do |store| store.write "rabbit", @white_rabbit store.read("rabbit").must_equal(@white_rabbit) store.expire "rabbit", 1.second sleep 2 store.read("rabbit").must_be_nil end end it "does't write data if :unless_exist option is true" do with_store_management do |store| store.write "rabbit", @white_rabbit, :unless_exist => true store.read("rabbit").must_equal(@rabbit) end end if RUBY_VERSION.match /1\.9/ it "reads raw data" do with_store_management do |store| result = store.read("rabbit", :raw => true) result.must_include("ActiveSupport::Cache::Entry") result.must_include("\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\x06EF") end end else it "reads raw data" do with_store_management do |store| result = store.read("rabbit", :raw => true) result.must_include("ActiveSupport::Cache::Entry") result.must_include("\017OpenStruct{\006:\tname") end end end it "writes raw data" do with_store_management do |store| store.write "rabbit", @white_rabbit, :raw => true store.read("rabbit", :raw => true).must_equal(%(#)) end end it "deletes data" do with_store_management do |store| store.delete "rabbit" store.read("rabbit").must_be_nil end end it "deletes namespaced data" do with_store_management do |store| store.write "rabbit", @white_rabbit, namespace:'namespaced' store.delete "rabbit", namespace:'namespaced' store.read("namespaced:rabbit").must_be_nil end end it "deletes matched data" do with_store_management do |store| store.delete_matched "rabb*" store.read("rabbit").must_be_nil end end it "verifies existence of an object in the store" do with_store_management do |store| store.exist?("rabbit").must_equal(true) store.exist?("rab-a-dub").must_equal(false) end end it "increments a key" do with_store_management do |store| 3.times { store.increment "counter" } store.read("counter", :raw => true).to_i.must_equal(3) end end it "decrements a key" do with_store_management do |store| 3.times { store.increment "counter" } 2.times { store.decrement "counter" } store.read("counter", :raw => true).to_i.must_equal(1) end end it "increments a raw key" do with_store_management do |store| assert store.write("raw-counter", 1, :raw => true) store.increment("raw-counter", 2) store.read("raw-counter", :raw => true).to_i.must_equal(3) end end it "decrements a raw key" do with_store_management do |store| assert store.write("raw-counter", 3, :raw => true) store.decrement("raw-counter", 2) store.read("raw-counter", :raw => true).to_i.must_equal(1) end end it "increments a key by given value" do with_store_management do |store| store.increment "counter", 3 store.read("counter", :raw => true).to_i.must_equal(3) end end it "decrements a key by given value" do with_store_management do |store| 3.times { store.increment "counter" } store.decrement "counter", 2 store.read("counter", :raw => true).to_i.must_equal(1) end end it "clears the store" do with_store_management do |store| store.clear store.with { |client| client.keys("*") }.flatten.must_be_empty end end it "provides store stats" do with_store_management do |store| store.stats.wont_be_empty end end it "fetches data" do with_store_management do |store| store.fetch("rabbit").must_equal(@rabbit) store.fetch("rub-a-dub").must_be_nil store.fetch("rub-a-dub") { "Flora de Cana" } store.fetch("rub-a-dub").must_equal("Flora de Cana") end end it "fetches data with expiration time" do with_store_management do |store| store.fetch("rabbit", :force => true) # force cache miss store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit } store.fetch("rabbit").must_equal(@white_rabbit) sleep 2 store.fetch("rabbit").must_be_nil end end it "fetches namespaced data" do with_store_management do |store| store.delete("rabbit", namespace:'namespaced') store.fetch("rabbit", namespace:'namespaced'){@rabbit}.must_equal(@rabbit) store.read("rabbit", namespace:'namespaced').must_equal(@rabbit) end end it "reads multiple keys" do @store.write "irish whisky", "Jameson" result = @store.read_multi "rabbit", "irish whisky" result['rabbit'].must_equal(@rabbit) result['irish whisky'].must_equal("Jameson") end it "reads multiple keys and returns only the matched ones" do @store.delete 'irish whisky' result = @store.read_multi "rabbit", "irish whisky" result.wont_include('irish whisky') result.must_include('rabbit') end it "reads multiple namespaced keys" do @store.write "rub-a-dub", "Flora de Cana", namespace:'namespaced' @store.write "irish whisky", "Jameson", namespace:'namespaced' result = @store.read_multi "rub-a-dub", "irish whisky", namespace:'namespaced' result['namespaced:rub-a-dub'].must_equal("Flora de Cana") result['namespaced:irish whisky'].must_equal("Jameson") end describe "fetch_multi" do it "reads existing keys and fills in anything missing" do @store.write "bourbon", "makers" result = @store.fetch_multi("bourbon", "rye") do |key| "#{key}-was-missing" end result.must_equal({ "bourbon" => "makers", "rye" => "rye-was-missing" }) @store.read("rye").must_equal("rye-was-missing") end end describe "fetch_multi namespaced keys" do it "reads existing keys and fills in anything missing" do @store.write "bourbon", "makers", namespace:'namespaced' result = @store.fetch_multi("bourbon", "rye", namespace:'namespaced') do |key| "#{key}-was-missing" end result.must_equal({ "namespaced:bourbon" => "makers", "namespaced:rye" => "rye-was-missing" }) @store.read("namespaced:rye").must_equal("rye-was-missing") end end describe "notifications" do it "notifies on #fetch" do with_notifications do @store.fetch("radiohead") { "House Of Cards" } end read, generate, write = @events read.name.must_equal('cache_read.active_support') read.payload.must_equal({ :key => 'radiohead', :super_operation => :fetch }) generate.name.must_equal('cache_generate.active_support') generate.payload.must_equal({ :key => 'radiohead' }) write.name.must_equal('cache_write.active_support') write.payload.must_equal({ :key => 'radiohead' }) end it "notifies on #read" do with_notifications do @store.read "metallica" end read = @events.first read.name.must_equal('cache_read.active_support') read.payload.must_equal({ :key => 'metallica', :hit => false }) end it "notifies on #write" do with_notifications do @store.write "depeche mode", "Enjoy The Silence" end write = @events.first write.name.must_equal('cache_write.active_support') write.payload.must_equal({ :key => 'depeche mode' }) end it "notifies on #delete" do with_notifications do @store.delete "the new cardigans" end delete = @events.first delete.name.must_equal('cache_delete.active_support') delete.payload.must_equal({ :key => 'the new cardigans' }) end it "notifies on #exist?" do with_notifications do @store.exist? "the smiths" end exist = @events.first exist.name.must_equal('cache_exist?.active_support') exist.payload.must_equal({ :key => 'the smiths' }) end it "notifies on #delete_matched" do with_notifications do @store.delete_matched "afterhours*" end delete_matched = @events.first delete_matched.name.must_equal('cache_delete_matched.active_support') delete_matched.payload.must_equal({ :key => %("afterhours*") }) end it "notifies on #increment" do with_notifications do @store.increment "pearl jam" end increment = @events.first increment.name.must_equal('cache_increment.active_support') increment.payload.must_equal({ :key => 'pearl jam', :amount => 1 }) end it "notifies on #decrement" do with_notifications do @store.decrement "placebo" end decrement = @events.first decrement.name.must_equal('cache_decrement.active_support') decrement.payload.must_equal({ :key => 'placebo', :amount => 1 }) end # it "notifies on cleanup" # TODO implement in ActiveSupport::Cache::RedisStore it "should notify on clear" do with_notifications do @store.clear end clear = @events.first clear.name.must_equal('cache_clear.active_support') clear.payload.must_equal({ :key => nil }) end end private def instantiate_store(*addresses) ActiveSupport::Cache::RedisStore.new(*addresses).instance_variable_get(:@data) end def with_store_management yield @store yield @dstore yield @pool_store yield @external_pool_store end def with_notifications @events = [ ] ActiveSupport::Cache::RedisStore.instrument = true ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args| @events << ActiveSupport::Notifications::Event.new(*args) end yield ActiveSupport::Cache::RedisStore.instrument = false end end redis-activesupport-4.1.0/test/redis/0000755000004100000410000000000012553424516017654 5ustar www-datawww-dataredis-activesupport-4.1.0/test/redis/activesupport/0000755000004100000410000000000012553424516022564 5ustar www-datawww-dataredis-activesupport-4.1.0/test/redis/activesupport/version_test.rb0000644000004100000410000000024212553424516025633 0ustar www-datawww-datarequire 'test_helper' describe Redis::ActiveSupport::VERSION do it 'returns current version' do Redis::ActiveSupport::VERSION.must_equal '4.0.0' end end redis-activesupport-4.1.0/.gitignore0000644000004100000410000000003012553424516017550 0ustar www-datawww-dataGemfile.lock *.gem tmp/ redis-activesupport-4.1.0/README.md0000644000004100000410000000247012553424516017051 0ustar www-datawww-data# Redis stores for ActiveSupport __`redis-activesupport`__ provides a cache for __ActiveSupport__. See the main [redis-store readme](https://github.com/redis-store/redis-store) for general guidelines. ## Installation ```ruby # Gemfile gem 'redis-activesupport' ``` ## Usage If you are using redis-store with Rails, consider using the [redis-rails gem](https://github.com/redis-store/redis-rails) instead. For standalone usage: ```ruby ActiveSupport::Cache.lookup_store :redis_store # { ... optional configuration ... } ``` ## Running tests ```shell gem install bundler git clone git://github.com/redis-store/redis-activesupport.git cd redis-activesupport bundle install bundle exec rake ``` If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake` ## Status [![Gem Version](https://badge.fury.io/rb/redis-activesupport.png)](http://badge.fury.io/rb/redis-activesupport) [![Build Status](https://secure.travis-ci.org/redis-store/redis-activesupport.png?branch=master)](http://travis-ci.org/jodosha/redis-activesupport?branch=master) [![Code Climate](https://codeclimate.com/github/jodosha/redis-store.png)](https://codeclimate.com/github/redis-store/redis-activesupport) ## Copyright 2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license