kuby-memcached 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +15 -0
- data/LICENSE +21 -0
- data/README.md +97 -0
- data/Rakefile +14 -0
- data/kuby-memcached.gemspec +20 -0
- data/lib/kuby/memcached.rb +10 -0
- data/lib/kuby/memcached/instance.rb +65 -0
- data/lib/kuby/memcached/plugin.rb +27 -0
- data/lib/kuby/memcached/version.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18c78462d9458158c3f3c28d7d4cc4533b95c8301d9a84a1c302476e0b93fe86
|
4
|
+
data.tar.gz: ff1b2da7749baef450a98b770db68ffd4be020b0065b0f97212dfe6a0a4d1975
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e634f9348db6ba094481ede3be2fe5139edfe3e2bbb760d4712ba039414750d4e570a457fb8a26e7004f92d16f8b745e2d31d674f3e7753a993a5176ec3e9f04
|
7
|
+
data.tar.gz: 88d33ff7b693573716c3c166ae0ba2492f5c800c5e5eadb03fbca8422d672ff6343df9157ecd25578797cdc403123a22d4fbb461d2bb368e702d3cd39d3fe8fa
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Cameron Dutro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
## kuby-memcached
|
2
|
+
|
3
|
+
Memcached plugin for [Kuby](https://github.com/getkuby/kuby-core).
|
4
|
+
|
5
|
+
## Intro
|
6
|
+
|
7
|
+
The memcached plugin provides the ability to stand up arbitrary memcached instances. Behind the scenes it uses the excellent [kubedb](https://kubedb.com/) Kubernetes operator.
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
Add the kuby-memcached gem to your Gemfile, then add a memcached instance like this:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'kuby/memcached'
|
15
|
+
|
16
|
+
Kuby.define(:production) do
|
17
|
+
kubernetes do
|
18
|
+
|
19
|
+
add_plugin(:memcached) do
|
20
|
+
instance(:my_rails_cache)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
The kuby-memcached plugin allows a number of additional configuration options too:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Kuby.define(:production) do
|
31
|
+
kubernetes do
|
32
|
+
|
33
|
+
add_plugin(:memcached) do
|
34
|
+
instance(:my_rails_cache) do
|
35
|
+
# set the version of memcached you want to use
|
36
|
+
version '1.5.4-v1' # this is the default version
|
37
|
+
|
38
|
+
# set the port memcached listen on and that you'll
|
39
|
+
# use to connect to the instance
|
40
|
+
port 11211 # this is the default port
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Get a list of the memcached versions your cluster supports by running:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
bundle exec kuby -e production kubectl -- get memcachedversions
|
52
|
+
```
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
Memcached instances defined in your Kuby config respond to `#hostname`, `#port`, and `#url` methods to help point at them in your Rails configuration. The `#url` method returns a complete URL to the memcached instance, including the host and port.
|
57
|
+
|
58
|
+
### Rails Cache
|
59
|
+
|
60
|
+
In your Rails config (eg. config/environments/production.rb), point your cache store at your memcached instance like so:
|
61
|
+
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Kuby.load!
|
65
|
+
|
66
|
+
url = Kuby.environment.kubernetes
|
67
|
+
.plugin(:memcached)
|
68
|
+
.instance(:my_rails_cache)
|
69
|
+
.url
|
70
|
+
|
71
|
+
config.cache_store = :mem_cache_store, url
|
72
|
+
```
|
73
|
+
|
74
|
+
### Dalli
|
75
|
+
|
76
|
+
You can also use a memcached client like the [Dalli gem](https://github.com/petergoldstein/dalli) directly:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'dalli'
|
80
|
+
|
81
|
+
url = Kuby.environment.kubernetes
|
82
|
+
.plugin(:memcached)
|
83
|
+
.instance(:my_rails_cache)
|
84
|
+
.url
|
85
|
+
|
86
|
+
dc = Dalli::Client.new(url)
|
87
|
+
dc.set('abc', 123)
|
88
|
+
value = dc.get('abc')
|
89
|
+
```
|
90
|
+
|
91
|
+
## License
|
92
|
+
|
93
|
+
Licensed under the MIT license. See LICENSE for details.
|
94
|
+
|
95
|
+
## Authors
|
96
|
+
|
97
|
+
* Cameron C. Dutro: http://github.com/camertron
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubygems/package_task'
|
4
|
+
|
5
|
+
require 'kuby/memcached'
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
|
9
|
+
task default: :spec
|
10
|
+
|
11
|
+
desc 'Run specs'
|
12
|
+
RSpec::Core::RakeTask.new do |t|
|
13
|
+
t.pattern = './spec/**/*_spec.rb'
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
require 'kuby/memcached/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'kuby-memcached'
|
6
|
+
s.version = ::Kuby::Memcached::VERSION
|
7
|
+
s.authors = ['Cameron Dutro']
|
8
|
+
s.email = ['camertron@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/getkuby/kuby-memcached'
|
10
|
+
|
11
|
+
s.description = s.summary = 'Memcached plugin for Kuby.'
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
|
15
|
+
s.add_dependency 'kuby-kube-db', '~> 0.4'
|
16
|
+
s.add_dependency 'kube-dsl', '~> 0.4'
|
17
|
+
|
18
|
+
s.require_path = 'lib'
|
19
|
+
s.files = Dir['{lib,spec}/**/*', 'Gemfile', 'LICENSE', 'CHANGELOG.md', 'README.md', 'Rakefile', 'kuby-memcached.gemspec']
|
20
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'kube-dsl'
|
2
|
+
|
3
|
+
module Kuby
|
4
|
+
module Memcached
|
5
|
+
class Instance
|
6
|
+
extend ::KubeDSL::ValueFields
|
7
|
+
|
8
|
+
attr_reader :name, :environment
|
9
|
+
|
10
|
+
value_field :version, default: '1.5.4-v1'
|
11
|
+
value_field :port, default: 11211
|
12
|
+
|
13
|
+
def initialize(name, environment)
|
14
|
+
@name = name
|
15
|
+
@environment = environment
|
16
|
+
end
|
17
|
+
|
18
|
+
def resources
|
19
|
+
@resources ||= [memcached]
|
20
|
+
end
|
21
|
+
|
22
|
+
def hostname
|
23
|
+
name
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
@url ||= "#{hostname}:#{port}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def memcached(&block)
|
31
|
+
context = self
|
32
|
+
|
33
|
+
@memcached ||= Kuby::KubeDB.memcached do
|
34
|
+
api_version 'kubedb.com/v1alpha1'
|
35
|
+
|
36
|
+
metadata do
|
37
|
+
name "#{context.name}-memcached"
|
38
|
+
namespace context.kubernetes.namespace.metadata.name
|
39
|
+
end
|
40
|
+
|
41
|
+
spec do
|
42
|
+
version context.version
|
43
|
+
|
44
|
+
service_template do
|
45
|
+
spec do
|
46
|
+
type 'NodePort'
|
47
|
+
port do
|
48
|
+
name 'redis'
|
49
|
+
port context.port
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@memcached.instance_eval(&block) if block
|
57
|
+
@memcached
|
58
|
+
end
|
59
|
+
|
60
|
+
def kubernetes
|
61
|
+
environment.kubernetes
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'kuby'
|
2
|
+
|
3
|
+
module Kuby
|
4
|
+
module Memcached
|
5
|
+
class Plugin < ::Kuby::Plugin
|
6
|
+
def configure(&block)
|
7
|
+
instance_eval(&block) if block
|
8
|
+
end
|
9
|
+
|
10
|
+
def instance(name, &block)
|
11
|
+
instances[name] ||= Instance.new(name, environment)
|
12
|
+
instances[name].instance_eval(&block) if block
|
13
|
+
instances[name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def resources
|
17
|
+
instances.flat_map { |_, instance| instance.resources }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def instances
|
23
|
+
@instances ||= {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kuby-memcached
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Dutro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kuby-kube-db
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: kube-dsl
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
41
|
+
description: Memcached plugin for Kuby.
|
42
|
+
email:
|
43
|
+
- camertron@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- kuby-memcached.gemspec
|
54
|
+
- lib/kuby/memcached.rb
|
55
|
+
- lib/kuby/memcached/instance.rb
|
56
|
+
- lib/kuby/memcached/plugin.rb
|
57
|
+
- lib/kuby/memcached/version.rb
|
58
|
+
homepage: http://github.com/getkuby/kuby-memcached
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.1.4
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Memcached plugin for Kuby.
|
80
|
+
test_files: []
|