lib/split.rb in split-3.4.1 vs lib/split.rb in split-4.0.0.pre
- old
+ new
@@ -1,12 +1,14 @@
# frozen_string_literal: true
+
require 'redis'
require 'split/algorithms/block_randomization'
require 'split/algorithms/weighted_sample'
require 'split/algorithms/whiplash'
require 'split/alternative'
+require 'split/cache'
require 'split/configuration'
require 'split/encapsulated_helper'
require 'split/exceptions'
require 'split/experiment'
require 'split/experiment_catalog'
@@ -33,13 +35,13 @@
# 3. or a valid Redis instance (one that responds to `#smembers`). Likely,
# this will be an instance of either `Redis`, `Redis::Client`,
# `Redis::DistRedis`, or `Redis::Namespace`.
def redis=(server)
@redis = if server.is_a?(String)
- Redis.new(:url => server, :thread_safe => true)
+ Redis.new(url: server)
elsif server.is_a?(Hash)
- Redis.new(server.merge(:thread_safe => true))
+ Redis.new(server)
elsif server.respond_to?(:smembers)
server
else
raise ArgumentError,
"You must supply a url, options hash or valid Redis connection instance"
@@ -61,9 +63,13 @@
# config.ignore_ip_addresses = '192.168.2.1'
# end
def configure
self.configuration ||= Configuration.new
yield(configuration)
+ end
+
+ def cache(namespace, key, &block)
+ Split::Cache.fetch(namespace, key, &block)
end
end
# Check to see if being run in a Rails application. If so, wait until before_initialize to run configuration so Gems that create ENV variables have the chance to initialize first.
if defined?(::Rails)