-
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.
Added Redis sharding and its test case
- Loading branch information
EC2 Default User
committed
Aug 2, 2017
1 parent
140b30d
commit 2b7eafe
Showing
40 changed files
with
7,892 additions
and
39 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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
development: &default | ||
redis: | ||
- :instance_id: redis_dev | ||
test: | ||
redis: | ||
- :instance_id: redis_test1 | ||
- :instance_id: redis_test2 | ||
production: | ||
redis: | ||
- :instance_id: redis_cluster1 | ||
- :instance_id: redis_cluster2 | ||
- :instance_id: redis_cluster3 | ||
default: | ||
<<: *default |
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,29 +1,15 @@ | ||
# SQLite version 3.x | ||
# gem install mysql | ||
# | ||
# Ensure the SQLite 3 gem is defined in your Gemfile | ||
# gem 'mysql' | ||
# | ||
default: &default | ||
development: &default | ||
adapter: mysql2 | ||
encoding: utf8 | ||
database: urllookup | ||
username: root | ||
password: | ||
port: 3306 | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
timeout: 5000 | ||
|
||
development: | ||
<<: *default | ||
database: urllookup | ||
|
||
# Warning: The database defined as "test" will be erased and | ||
# re-generated from your development database when you run "rake". | ||
# Do not set this db to the same as development or production. | ||
test: | ||
<<: *default | ||
database: urllookup_test | ||
|
||
production: | ||
<<: *default | ||
database: urllookup |
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,5 +1,14 @@ | ||
# Load the Rails application. | ||
require_relative 'application' | ||
|
||
app_config = YAML.load(File.read("#{Rails.root}/config/config.yml"))[Rails.env] | ||
redis_instances = app_config["redis"] | ||
|
||
REDIS_INSTANCE_LIST = {} | ||
redis_instances.each do |redis_instance| | ||
redis_instance_info = YAML.load(File.read("#{Rails.root}/config/redis.yml"))[redis_instance[:instance_id]] | ||
REDIS_INSTANCE_LIST[redis_instance_info['hashcode']] = { :object => nil, :url => redis_instance_info['url'] } | ||
end | ||
|
||
# Initialize the Rails application. | ||
Rails.application.initialize! |
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 +1,10 @@ | ||
$redis = Redis::Namespace.new(:ns, :redis => Redis.new) | ||
module UrlLookupCache | ||
class << self | ||
def redis | ||
REDIS_INSTANCE_LIST.each do |key, redis_instance| | ||
redis_instance[:object] ||= Redis.new(:url => (redis_instance[:url] || 'redis://127.0.0.1:6379')) | ||
end | ||
REDIS_INSTANCE_LIST | ||
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,18 @@ | ||
redis_dev: | ||
url: redis://localhost:6379 | ||
hashcode: 0 | ||
redis_test1: | ||
url: redis://localhost:6379 | ||
hashcode: 0 | ||
redis_test2: | ||
url: redis://localhost:6379 | ||
hashcode: 1 | ||
redis_cluster1: | ||
url: redis://localhost:6379 | ||
hashcode: 0 | ||
redis_cluster2: | ||
url: redis://localhost:6379 | ||
hashcode: 1 | ||
redis_cluster3: | ||
url: redis://localhost:6379 | ||
hashcode: 2 |
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,5 @@ | ||
{ | ||
"result": { | ||
"covered_percent": 89.66 | ||
} | ||
} |
Oops, something went wrong.