kredis 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kredis might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/kredis/attributes.rb +2 -2
- data/lib/kredis/connections.rb +2 -1
- data/lib/kredis/railtie.rb +4 -0
- data/lib/kredis/types/counter.rb +1 -1
- data/lib/kredis/types/enum.rb +1 -1
- data/lib/kredis/types/flag.rb +4 -2
- data/lib/kredis/types/hash.rb +1 -1
- data/lib/kredis/types/list.rb +1 -1
- data/lib/kredis/types/set.rb +1 -1
- data/lib/kredis/types/slots.rb +1 -1
- data/lib/kredis/types/unique_list.rb +1 -1
- data/lib/kredis/types.rb +2 -2
- data/lib/kredis/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6977b6ccbe9dba3574b4f0fe0c107fde3e1ff8a4e8a52f46076fe8df3acab2db
|
4
|
+
data.tar.gz: b3b9fb9c0e82a898168c6a9442cba36938bc4f7b9046dca16be052d28074c3ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa0715d6e188a7261f2f4c27f13a1b4dc919c5bf339c29435836693c3ae8df19f63ae54ff0d0ca28712f984a238df124bdc06ab268b85c88fd28179ae1534560
|
7
|
+
data.tar.gz: 9bb31956f1c666e64fc50c12a35b1a9ebefad8ec7f139b67c73033e745c48b8f271736b533c91eb6a4c84a892f541edb634688663219bd1285a1c3aafb996efd
|
data/README.md
CHANGED
@@ -144,7 +144,8 @@ true == flag.marked? # => EXISTS myflag
|
|
144
144
|
flag.remove # => DEL myflag
|
145
145
|
false == flag.marked? # => EXISTS myflag
|
146
146
|
|
147
|
-
flag.mark(expires_in: 1.second)
|
147
|
+
true == flag.mark(expires_in: 1.second, force: false) #=> SET myflag 1 EX 1 NX
|
148
|
+
false == flag.mark(expires_in: 10.seconds, force: false) #=> SET myflag 10 EX 1 NX
|
148
149
|
true == flag.marked? #=> EXISTS myflag
|
149
150
|
sleep 0.5.seconds
|
150
151
|
true == flag.marked? #=> EXISTS myflag
|
@@ -174,9 +175,9 @@ end
|
|
174
175
|
|
175
176
|
person = Person.find(5)
|
176
177
|
person.names.append "David", "Heinemeier", "Hansson" # => RPUSH people:5:names "David" "Heinemeier" "Hansson"
|
177
|
-
true == person.morning.bright? # => GET people:
|
178
|
-
person.morning.value = "blue" # => SET people:
|
179
|
-
true == person.morning.blue? # => GET people:
|
178
|
+
true == person.morning.bright? # => GET people:5:morning
|
179
|
+
person.morning.value = "blue" # => SET people:5:morning
|
180
|
+
true == person.morning.blue? # => GET people:5:morning
|
180
181
|
```
|
181
182
|
|
182
183
|
You can also define `after_change` callbacks that trigger on mutations:
|
@@ -243,6 +244,16 @@ Kredis::Connections.connections[:shared] = Redis.new(
|
|
243
244
|
|
244
245
|
The above code could be added to either `config/environments/production.rb` or an initializer. Please ensure that your client private key, if used, is stored your credentials file or another secure location.
|
245
246
|
|
247
|
+
### Configure how the redis client is created
|
248
|
+
|
249
|
+
You can configure how the redis client is created by setting `config.connector` in your `application.rb`:
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
config.kredis.connector = ->(config) { SomeRedisProxy.new(config) }
|
253
|
+
```
|
254
|
+
|
255
|
+
By default Kredis will use `Redis.new(config)`.
|
256
|
+
|
246
257
|
## License
|
247
258
|
|
248
259
|
Kredis is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/kredis/attributes.rb
CHANGED
@@ -22,8 +22,8 @@ module Kredis::Attributes
|
|
22
22
|
kredis_connection_with __method__, name, key, config: config, after_change: after_change, expires_in: expires_in
|
23
23
|
end
|
24
24
|
|
25
|
-
def kredis_flag(name, key: nil, config: :shared, after_change: nil)
|
26
|
-
kredis_connection_with __method__, name, key, config: config, after_change: after_change
|
25
|
+
def kredis_flag(name, key: nil, config: :shared, after_change: nil, expires_in: nil)
|
26
|
+
kredis_connection_with __method__, name, key, config: config, after_change: after_change, expires_in: expires_in
|
27
27
|
|
28
28
|
define_method("#{name}?") do
|
29
29
|
send(name).marked?
|
data/lib/kredis/connections.rb
CHANGED
@@ -3,11 +3,12 @@ require "redis"
|
|
3
3
|
module Kredis::Connections
|
4
4
|
mattr_accessor :connections, default: Hash.new
|
5
5
|
mattr_accessor :configurator
|
6
|
+
mattr_accessor :connector, default: ->(config) { Redis.new(config) }
|
6
7
|
|
7
8
|
def configured_for(name)
|
8
9
|
connections[name] ||= begin
|
9
10
|
Kredis.instrument :meta, message: "Connected to #{name}" do
|
10
|
-
|
11
|
+
connector.call configurator.config_for("redis/#{name}")
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
data/lib/kredis/railtie.rb
CHANGED
@@ -12,6 +12,10 @@ class Kredis::Railtie < ::Rails::Railtie
|
|
12
12
|
Kredis::LogSubscriber.logger = config.kredis.logger || Rails.logger
|
13
13
|
end
|
14
14
|
|
15
|
+
initializer "kredis.configuration" do
|
16
|
+
Kredis::Connections.connector = config.kredis.connector || ->(config) { Redis.new(config) }
|
17
|
+
end
|
18
|
+
|
15
19
|
initializer "kredis.configurator" do
|
16
20
|
Kredis.configurator = Rails.application
|
17
21
|
end
|
data/lib/kredis/types/counter.rb
CHANGED
data/lib/kredis/types/enum.rb
CHANGED
data/lib/kredis/types/flag.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class Kredis::Types::Flag < Kredis::Types::Proxying
|
2
2
|
proxying :set, :exists?, :del
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
attr_accessor :expires_in
|
5
|
+
|
6
|
+
def mark(expires_in: nil, force: true)
|
7
|
+
set 1, ex: expires_in || self.expires_in, nx: !force
|
6
8
|
end
|
7
9
|
|
8
10
|
def marked?
|
data/lib/kredis/types/hash.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "active_support/core_ext/hash"
|
2
2
|
|
3
3
|
class Kredis::Types::Hash < Kredis::Types::Proxying
|
4
|
-
proxying :hget, :hset, :hmget, :hdel, :hgetall, :hkeys, :hvals, :del
|
4
|
+
proxying :hget, :hset, :hmget, :hdel, :hgetall, :hkeys, :hvals, :del, :exists?
|
5
5
|
|
6
6
|
attr_accessor :typed
|
7
7
|
|
data/lib/kredis/types/list.rb
CHANGED
data/lib/kredis/types/set.rb
CHANGED
data/lib/kredis/types/slots.rb
CHANGED
data/lib/kredis/types.rb
CHANGED
@@ -47,8 +47,8 @@ module Kredis::Types
|
|
47
47
|
type_from(Cycle, config, key, after_change: after_change, values: values, expires_in: expires_in)
|
48
48
|
end
|
49
49
|
|
50
|
-
def flag(key, config: :shared, after_change: nil)
|
51
|
-
type_from(Flag, config, key, after_change: after_change)
|
50
|
+
def flag(key, config: :shared, after_change: nil, expires_in: nil)
|
51
|
+
type_from(Flag, config, key, after_change: after_change, expires_in: expires_in)
|
52
52
|
end
|
53
53
|
|
54
54
|
def enum(key, values:, default:, config: :shared, after_change: nil)
|
data/lib/kredis/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Timm Hansen
|
8
8
|
- David Heinemeier Hansson
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 6.0.0
|
56
|
-
description:
|
56
|
+
description:
|
57
57
|
email: david@hey.com
|
58
58
|
executables: []
|
59
59
|
extensions: []
|
@@ -91,7 +91,7 @@ homepage: https://github.com/rails/kredis
|
|
91
91
|
licenses:
|
92
92
|
- MIT
|
93
93
|
metadata: {}
|
94
|
-
post_install_message:
|
94
|
+
post_install_message:
|
95
95
|
rdoc_options: []
|
96
96
|
require_paths:
|
97
97
|
- lib
|
@@ -106,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
110
|
-
signing_key:
|
109
|
+
rubygems_version: 3.2.22
|
110
|
+
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Higher-level data structures built on Redis.
|
113
113
|
test_files: []
|