cache_store_redis 0.3.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5dc8f3e6e5dc5e83e0d51540a15da7140298d9915de546f35759affb3b41ee6
4
+ data.tar.gz: d895e01a2007f6d0295b6d8861afc9ed034ecfa8d63dd339f258b79c428a73fb
5
+ SHA512:
6
+ metadata.gz: 53e674a747a0bb31ece3788a26b03d6ca72ca0a0f6128928c7c926feecc5c67a6f5b377fb15e23f2b15f6050d2c41d179625fc6fced29d18708b83281eb242a4
7
+ data.tar.gz: 8e3d48bc9ae19ca9f51f7f875d5f349584898890ddffdb5ce4d91783043aaa4b3f270ad1d2ec00bfd3928a8d205f00347d0105556bdd0b4a872660031ef14f97
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cache_store"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module CacheStoreRedis
2
+ VERSION = '0.3.2'
3
+ end
@@ -0,0 +1,137 @@
1
+ require 'cache_store_redis/version'
2
+ require 'redis'
3
+ require 'securerandom'
4
+
5
+ #This class is used to implement a redis cache store.
6
+ #This class is used for interacting with a redis based cache store.
7
+ class RedisCacheStore
8
+
9
+ def initialize(namespace = nil, config = nil)
10
+
11
+ if RUBY_PLATFORM != 'java'
12
+ require 'oj'
13
+ end
14
+
15
+ @namespace = namespace
16
+ if config == nil
17
+ @client = Redis.new
18
+ else
19
+ @client = Redis.new(config)
20
+ end
21
+ end
22
+
23
+ #This method is called to configure the connection to the cache store.
24
+ def configure(host = 'localhost', port = 6379, db = 'default', password = nil, driver: nil, url: nil)
25
+ if url != nil
26
+ config[:url] = url
27
+ config[:db] = db
28
+ else
29
+ config = { :host => host, :port => port, :db => db }
30
+ end
31
+ if password != nil
32
+ config[:password] = password
33
+ end
34
+ if driver != nil
35
+ config[:driver] = driver
36
+ end
37
+
38
+ @client = Redis.new(config)
39
+ end
40
+
41
+ #This method is called to set a value within this cache store by it's key.
42
+ #
43
+ # @param key [String] This is the unique key to reference the value being set within this cache store.
44
+ # @param value [Object] This is the value to set within this cache store.
45
+ # @param expires_in [Integer] This is the number of seconds from the current time that this value should expire.
46
+ def set(key, value, expires_in = 0)
47
+ v = nil
48
+ k = build_key(key)
49
+
50
+ if value != nil
51
+ v = serialize(value)
52
+ end
53
+
54
+ @client.set(k, v)
55
+
56
+ if expires_in > 0
57
+ @client.expire(k, expires_in)
58
+ end
59
+
60
+ end
61
+
62
+ #This method is called to get a value from this cache store by it's unique key.
63
+ #
64
+ # @param key [String] This is the unique key to reference the value to fetch from within this cache store.
65
+ # @param expires_in [Integer] This is the number of seconds from the current time that this value should expire. (This is used in conjunction with the block to hydrate the cache key if it is empty.)
66
+ # @param &block [Block] This block is provided to hydrate this cache store with the value for the request key when it is not found.
67
+ # @return [Object] The value for the specified unique key within the cache store.
68
+ def get(key, expires_in = 0, &block)
69
+
70
+ k = build_key(key)
71
+
72
+ value = @client.get(k)
73
+ value = deserialize(value) unless value == nil
74
+
75
+ if value.nil? && block_given?
76
+ value = yield
77
+ set(k, value, expires_in)
78
+ end
79
+
80
+ return value
81
+ end
82
+
83
+ # This method is called to remove a value from this cache store by it's unique key.
84
+ #
85
+ # @param key [String] This is the unique key to reference the value to remove from this cache store.
86
+ def remove(key)
87
+
88
+ @client.del(build_key(key))
89
+
90
+ end
91
+
92
+ # This method is called to check if a value exists within this cache store for a specific key.
93
+ #
94
+ # @param key [String] This is the unique key to reference the value to check for within this cache store.
95
+ # @return [Boolean] True or False to specify if the key exists in the cache store.
96
+ def exist?(key)
97
+
98
+ @client.exists(build_key(key))
99
+
100
+ end
101
+
102
+ # Ping the cache store.
103
+ #
104
+ # @return [String] `PONG`
105
+ def ping
106
+ @client.ping
107
+ end
108
+
109
+ private
110
+
111
+ def serialize(object)
112
+ if RUBY_PLATFORM == 'java'
113
+ Marshal::dump(object)
114
+ else
115
+ Oj.dump(object)
116
+ end
117
+ end
118
+
119
+ def deserialize(object)
120
+ if RUBY_PLATFORM == 'java'
121
+ Marshal::load(object)
122
+ else
123
+ Oj.load(object)
124
+ end
125
+ end
126
+
127
+ def build_key(key)
128
+ k = ''
129
+ if @namespace != nil
130
+ k = @namespace + ':' + key.to_s
131
+ elsif
132
+ k = key.to_s
133
+ end
134
+ k
135
+ end
136
+
137
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache_store_redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: java
6
+ authors:
7
+ - vaughanbrittonsage
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.11'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ name: rspec
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: redis
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This is the redis cache_store implementation.
70
+ email:
71
+ - vaughan.britton@sage.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - bin/console
77
+ - bin/setup
78
+ - lib/cache_store_redis.rb
79
+ - lib/cache_store_redis/version.rb
80
+ homepage: https://github.com/vaughanbrittonsage/cache_store
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.6.11
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: This is the redis cache_store implementation.
104
+ test_files: []