Repository navigation
Expand file tree
/
Copy pathsplit.rb
More file actions
executable file
·66 lines (59 loc) · 1.76 KB
/
Copy pathsplit.rb
File metadata and controls
executable file
·66 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'split/experiment'
require 'split/alternative'
require 'split/helper'
require 'split/version'
require 'split/configuration'
require 'redis/namespace'
module Split
extend self
attr_accessor :configuration
# Accepts:
# 1. A 'hostname:port' string
# 2. A 'hostname:port:db' string (to select the Redis db)
# 3. A 'hostname:port/namespace' string (to set the Redis namespace)
# 4. A redis URL string 'redis://host:port'
# 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
# or `Redis::Namespace`.
def redis=(server)
if server.respond_to? :split
if server =~ /redis\:\/\//
redis = Redis.connect(:url => server, :thread_safe => true)
else
server, namespace = server.split('/', 2)
host, port, db = server.split(':')
redis = Redis.new(:host => host, :port => port,
:thread_safe => true, :db => db)
end
namespace ||= :split
@redis = Redis::Namespace.new(namespace, :redis => redis)
elsif server.respond_to? :namespace=
@redis = server
else
@redis = Redis::Namespace.new(:split, :redis => server)
end
end
# Returns the current Redis connection. If none has been created, will
# create a new one.
def redis
return @redis if @redis
self.redis = 'localhost:6379'
self.redis
end
# Call this method to modify defaults in your initializers.
#
# @example
# Split.configure do |config|
# config.ignore_ips = '192.168.2.1'
# end
def configure
self.configuration ||= Configuration.new
yield(configuration)
end
end
Split.configure {}
if defined?(Rails)
class ActionController::Base
ActionController::Base.send :include, Split::Helper
ActionController::Base.helper Split::Helper
end
end