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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c7614f548dde6852fd7e654215ba56f103fec5ac7ad6ae477fe2621f3b9964a
4
- data.tar.gz: a023026462ec8a09f1e26550ce56abaeb95b1f0582665787cda48ef91e9048d1
3
+ metadata.gz: 6977b6ccbe9dba3574b4f0fe0c107fde3e1ff8a4e8a52f46076fe8df3acab2db
4
+ data.tar.gz: b3b9fb9c0e82a898168c6a9442cba36938bc4f7b9046dca16be052d28074c3ef
5
5
  SHA512:
6
- metadata.gz: e3755bc5be9370676ac5b2a4a6100a26d0ed09b1248d87114911020ec1b9eb6ab094d25ec6686478069add02197d5188f59edcab04ccc69fed9bb80d1db9966f
7
- data.tar.gz: 6f97f9ad814700b69b5663697add1f4b2d3468d05752c053c883ca0e8d93703b91af06f6a2593ee6ba79835435663c51c78cd17df32dafb1d7efc666150e77f6
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) #=> SET myflag 1 EX 1
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:1:morning
178
- person.morning.value = "blue" # => SET people:1:morning
179
- true == person.morning.blue? # => GET people:1:morning
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).
@@ -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?
@@ -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
- Redis.new configurator.config_for("redis/#{name}")
11
+ connector.call configurator.config_for("redis/#{name}")
11
12
  end
12
13
  end
13
14
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  class Kredis::Types::Counter < Kredis::Types::Proxying
2
- proxying :multi, :set, :incrby, :decrby, :get, :del
2
+ proxying :multi, :set, :incrby, :decrby, :get, :del, :exists?
3
3
 
4
4
  attr_accessor :expires_in
5
5
 
@@ -1,7 +1,7 @@
1
1
  require "active_support/core_ext/object/inclusion"
2
2
 
3
3
  class Kredis::Types::Enum < Kredis::Types::Proxying
4
- proxying :set, :get, :del
4
+ proxying :set, :get, :del, :exists?
5
5
 
6
6
  attr_accessor :values, :default
7
7
 
@@ -1,8 +1,10 @@
1
1
  class Kredis::Types::Flag < Kredis::Types::Proxying
2
2
  proxying :set, :exists?, :del
3
3
 
4
- def mark(expires_in: nil)
5
- set 1, ex: expires_in
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?
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  class Kredis::Types::List < Kredis::Types::Proxying
2
- proxying :lrange, :lrem, :lpush, :rpush
2
+ proxying :lrange, :lrem, :lpush, :rpush, :exists?
3
3
 
4
4
  attr_accessor :typed
5
5
 
@@ -1,5 +1,5 @@
1
1
  class Kredis::Types::Set < Kredis::Types::Proxying
2
- proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop
2
+ proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop, :exists?
3
3
 
4
4
  attr_accessor :typed
5
5
 
@@ -1,7 +1,7 @@
1
1
  class Kredis::Types::Slots < Kredis::Types::Proxying
2
2
  class NotAvailable < StandardError; end
3
3
 
4
- proxying :incr, :decr, :get, :del
4
+ proxying :incr, :decr, :get, :del, :exists?
5
5
 
6
6
  attr_accessor :available
7
7
 
@@ -1,6 +1,6 @@
1
1
  # You'd normally call this a set, but Redis already has another data type for that
2
2
  class Kredis::Types::UniqueList < Kredis::Types::List
3
- proxying :multi, :ltrim
3
+ proxying :multi, :ltrim, :exists?
4
4
 
5
5
  attr_accessor :typed, :limit
6
6
 
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)
@@ -1,3 +1,3 @@
1
1
  module Kredis
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0"
3
3
  end
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.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-09-15 00:00:00.000000000 Z
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.1.4
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: []