kuby-redis 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +15 -0
- data/LICENSE +21 -0
- data/README.md +106 -0
- data/Rakefile +14 -0
- data/kuby-redis.gemspec +20 -0
- data/lib/kuby/redis.rb +10 -0
- data/lib/kuby/redis/instance.rb +81 -0
- data/lib/kuby/redis/plugin.rb +27 -0
- data/lib/kuby/redis/version.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a76527037e4b0dc6d60be52d6ae1b9c93bf3bd41d3188b562f8140a4d45dc007
|
4
|
+
data.tar.gz: a98a3e23693aa65f9e8964d37754c5c4e0612c6250b5b2d9a4047f99ab3f1fa7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e288064f9f39ff7c223e34c0e9f75dd5e3e0b94c4a6983b849fc78469ceeb2ed2577594695eba5dca8d4019e5cac4ea26b49ebc59ba3c782d1cada87f335f9d7
|
7
|
+
data.tar.gz: 7c68f5b0bea7c5aa285e3164562f5ea514577c0b608a346cb74f8c976a15360d22495c5013108a886f935bb2592a7f20910c6f82817ccc05d8221cb4285db431
|
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,106 @@
|
|
1
|
+
## kuby-redis
|
2
|
+
|
3
|
+
Redis plugin for [Kuby](https://github.com/getkuby/kuby-core).
|
4
|
+
|
5
|
+
## Intro
|
6
|
+
|
7
|
+
The redis plugin provides the ability to stand up arbitrary redis instances. Behind the scenes it uses the excellent [kubedb](https://kubedb.com/) Kubernetes operator.
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
Add the kuby-redis gem to your Gemfile, then add a redis instance like this:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'kuby/redis'
|
15
|
+
|
16
|
+
Kuby.define(:production) do
|
17
|
+
kubernetes do
|
18
|
+
|
19
|
+
add_plugin(:redis) do
|
20
|
+
instance(:my_rails_cache)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
The kuby-redis plugin allows a number of additional configuration options too:
|
28
|
+
|
29
|
+
|
30
|
+
value_field :storage_type, default: 'Durable'
|
31
|
+
value_field :storage, default: '1Gi'
|
32
|
+
value_field :access_modes, default: ['ReadWriteOnce']
|
33
|
+
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
Kuby.define(:production) do
|
37
|
+
kubernetes do
|
38
|
+
|
39
|
+
add_plugin(:redis) do
|
40
|
+
instance(:my_rails_cache) do
|
41
|
+
# set the version of redis you want to use
|
42
|
+
version '5.0.3-v1' # this is the default version
|
43
|
+
|
44
|
+
# set the port redis listens on and that you'll
|
45
|
+
# use to connect to the instance
|
46
|
+
port 6379 # this is the default port
|
47
|
+
|
48
|
+
# the amount of durable storage to allocate
|
49
|
+
storage '1Gi'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Get a list of the redis versions your cluster supports by running:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
bundle exec kuby -e production kubectl -- get redisversions
|
61
|
+
```
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
Redis 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 redis instance, including the host and port.
|
66
|
+
|
67
|
+
### Rails Cache
|
68
|
+
|
69
|
+
In your Rails config (eg. config/environments/production.rb), point your cache store at your redis instance like so:
|
70
|
+
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Kuby.load!
|
74
|
+
|
75
|
+
url = Kuby.environment.kubernetes
|
76
|
+
.plugin(:redis)
|
77
|
+
.instance(:my_rails_cache)
|
78
|
+
.url
|
79
|
+
|
80
|
+
config.cache_store = :redis_cache_store, { url: url }
|
81
|
+
```
|
82
|
+
|
83
|
+
### Redis Gem
|
84
|
+
|
85
|
+
You can also use a redis client like the [Redis gem](https://github.com/redis/redis-rb) directly:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
require 'redis'
|
89
|
+
|
90
|
+
url = Kuby.environment.kubernetes
|
91
|
+
.plugin(:redis)
|
92
|
+
.instance(:my_rails_cache)
|
93
|
+
.url
|
94
|
+
|
95
|
+
redis = Redis.new(url: url)
|
96
|
+
redis.set('abc', 123)
|
97
|
+
value = redis.get('abc')
|
98
|
+
```
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
Licensed under the MIT license. See LICENSE for details.
|
103
|
+
|
104
|
+
## Authors
|
105
|
+
|
106
|
+
* 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/redis'
|
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
|
data/kuby-redis.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
require 'kuby/redis/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'kuby-redis'
|
6
|
+
s.version = ::Kuby::Redis::VERSION
|
7
|
+
s.authors = ['Cameron Dutro']
|
8
|
+
s.email = ['camertron@gmail.com']
|
9
|
+
s.homepage = 'http://github.com/getkuby/kuby-redis'
|
10
|
+
|
11
|
+
s.description = s.summary = 'Redis 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-redis.gemspec']
|
20
|
+
end
|
data/lib/kuby/redis.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'kube-dsl'
|
2
|
+
|
3
|
+
module Kuby
|
4
|
+
module Redis
|
5
|
+
class Instance
|
6
|
+
extend ::KubeDSL::ValueFields
|
7
|
+
|
8
|
+
attr_reader :name, :environment
|
9
|
+
|
10
|
+
value_field :version, default: '5.0.3-v1'
|
11
|
+
value_field :storage_class_name, default: -> (inst) { inst.kubernetes.provider.storage_class_name }
|
12
|
+
value_field :storage_type, default: 'Durable'
|
13
|
+
value_field :storage, default: '1Gi'
|
14
|
+
value_field :access_modes, default: ['ReadWriteOnce']
|
15
|
+
value_field :port, default: 6379
|
16
|
+
|
17
|
+
def initialize(name, environment)
|
18
|
+
@name = name
|
19
|
+
@environment = environment
|
20
|
+
end
|
21
|
+
|
22
|
+
def resources
|
23
|
+
@resources ||= [redis]
|
24
|
+
end
|
25
|
+
|
26
|
+
def hostname
|
27
|
+
name
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
@url ||= "redis://#{hostname}:#{port}/0"
|
32
|
+
end
|
33
|
+
|
34
|
+
def redis(&block)
|
35
|
+
context = self
|
36
|
+
|
37
|
+
@redis ||= Kuby::KubeDB.redis do
|
38
|
+
api_version 'kubedb.com/v1alpha1'
|
39
|
+
|
40
|
+
metadata do
|
41
|
+
name "#{context.name}-redis"
|
42
|
+
namespace context.kubernetes.namespace.metadata.name
|
43
|
+
end
|
44
|
+
|
45
|
+
spec do
|
46
|
+
version context.version
|
47
|
+
storage_type context.storage_type
|
48
|
+
|
49
|
+
storage do
|
50
|
+
storage_class_name context.storage_class_name
|
51
|
+
access_modes context.access_modes
|
52
|
+
|
53
|
+
resources do
|
54
|
+
requests do
|
55
|
+
add :storage, context.storage
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
service_template do
|
61
|
+
spec do
|
62
|
+
type 'NodePort'
|
63
|
+
port do
|
64
|
+
name 'memcached'
|
65
|
+
port context.port
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@redis.instance_eval(&block) if block
|
73
|
+
@redis
|
74
|
+
end
|
75
|
+
|
76
|
+
def kubernetes
|
77
|
+
environment.kubernetes
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'kuby'
|
2
|
+
|
3
|
+
module Kuby
|
4
|
+
module Redis
|
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-redis
|
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-21 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: Redis 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-redis.gemspec
|
54
|
+
- lib/kuby/redis.rb
|
55
|
+
- lib/kuby/redis/instance.rb
|
56
|
+
- lib/kuby/redis/plugin.rb
|
57
|
+
- lib/kuby/redis/version.rb
|
58
|
+
homepage: http://github.com/getkuby/kuby-redis
|
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: Redis plugin for Kuby.
|
80
|
+
test_files: []
|