-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: create StorageSync for the redis-rb based storage
Also, move the helpers to StorageHelpers to be able to use them to instantiate AsyncStorage too. The helpers will need to be cleaned-up because we have ThreeScale::Backend::StorageHelpers and ThreeScale::Backend::Storage::Helpers. They should probably be merged.
- Loading branch information
Showing
3 changed files
with
303 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# used to provide a Redis client based on a configuration object | ||
require 'uri' | ||
|
||
module ThreeScale | ||
module Backend | ||
class StorageSync | ||
include Configurable | ||
|
||
class << self | ||
# Returns a shared instance of the storage. If there is no instance yet, | ||
# creates one first. If you want to always create a fresh instance, set | ||
# the +reset+ parameter to true. | ||
def instance(reset = false) | ||
if reset || @instance.nil? | ||
@instance = new(Storage::Helpers.config_with(configuration.redis, | ||
options: get_options)) | ||
else | ||
@instance | ||
end | ||
end | ||
|
||
def new(options) | ||
Redis.new options | ||
end | ||
|
||
private | ||
|
||
if ThreeScale::Backend.production? | ||
def get_options | ||
{} | ||
end | ||
else | ||
DEFAULT_SERVER = '127.0.0.1:22121'.freeze | ||
private_constant :DEFAULT_SERVER | ||
|
||
def get_options | ||
{ default_url: DEFAULT_SERVER } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |