dalli-elasticache 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +33 -0
- data/Rakefile +0 -0
- data/lib/dalli-elasticache.rb +2 -0
- data/lib/dalli/elasticache.rb +59 -0
- data/lib/dalli/elasticache/version.rb +5 -0
- metadata +82 -0
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# dalli-elasticache
|
2
|
+
|
3
|
+
A wrapper for the [Dalli memcached client](https://github.com/mperham/dalli) with support for [AWS ElastiCache Auto Discovery](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the [rubygem](https://rubygems.org/gems/dalli-elasticache):
|
8
|
+
|
9
|
+
# in your Gemfile
|
10
|
+
gem 'dalli-elasticache'
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
# Create an ElastiCache instance with your config endpoint and options for Dalli
|
15
|
+
elasticache = Dalli::ElastiCache.new(config_endpoint, dalli_options={})
|
16
|
+
# For example:
|
17
|
+
elasticache = Dalli::ElastiCache.new("aaron-scratch.vfdnac.cfg.use1.cache.amazonaws.com:11211", :ttl => 3600, :namespace => "my_app")
|
18
|
+
|
19
|
+
elasticache.version # => the config version returned by the ElastiCache config endpoint.
|
20
|
+
|
21
|
+
client = elasticache.client # a regular Dalli::Client using the instance IP addresses returns by the config endpoint
|
22
|
+
|
23
|
+
# Check the endpoint to see if the version has changed:
|
24
|
+
elasticache.refresh.version
|
25
|
+
# If so, update your dalli client:
|
26
|
+
client = elasticache.client
|
27
|
+
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
Copyright 2013 Aaron Suggs
|
32
|
+
|
33
|
+
Released under an [MIT License](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'dalli'
|
2
|
+
require 'socket'
|
3
|
+
require 'dalli/elasticache/version'
|
4
|
+
|
5
|
+
module Dalli
|
6
|
+
class ElastiCache
|
7
|
+
attr_accessor :config_host, :config_port, :options
|
8
|
+
|
9
|
+
def initialize(config_endpoint, options={})
|
10
|
+
@config_host, @config_port = config_endpoint.split(':')
|
11
|
+
@config_port ||= 11211
|
12
|
+
@options = options
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
Dalli::Client.new(servers, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def refresh
|
21
|
+
# Reset data
|
22
|
+
@data = nil
|
23
|
+
data
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def config_get_cluster
|
29
|
+
# TODO: handle timeouts
|
30
|
+
s = TCPSocket.new(config_host, config_port)
|
31
|
+
s.puts "config get cluster\r\n"
|
32
|
+
data = []
|
33
|
+
while (line = s.gets) != "END\r\n"
|
34
|
+
data << line
|
35
|
+
end
|
36
|
+
|
37
|
+
s.close
|
38
|
+
data
|
39
|
+
end
|
40
|
+
|
41
|
+
def data
|
42
|
+
return @data if @data
|
43
|
+
raw_data = config_get_cluster
|
44
|
+
version = raw_data[1].to_i
|
45
|
+
instance_data = raw_data[2].split(/\s+/)
|
46
|
+
instances = instance_data.map{ |raw| host, ip, port = raw.split('|'); {:host => host, :ip => ip, :port => port} }
|
47
|
+
@data = { :version => version, :instances => instances }
|
48
|
+
end
|
49
|
+
|
50
|
+
def version
|
51
|
+
data[:version]
|
52
|
+
end
|
53
|
+
|
54
|
+
def servers
|
55
|
+
data[:instances].map{ |i| "#{i[:ip]}:#{i[:port]}" }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dalli-elasticache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aaron Suggs
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: dalli
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
description: A wrapper for Dalli with support for AWS ElastiCache Auto Discovery
|
47
|
+
email: aaron@ktheory.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/dalli/elasticache/version.rb
|
53
|
+
- lib/dalli/elasticache.rb
|
54
|
+
- lib/dalli-elasticache.rb
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
homepage: http://github.com/ktheory/dalli-elasticache
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.5
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.24
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Adds AWS ElastiCache Auto Discovery support to Dalli memcache client
|
82
|
+
test_files: []
|