Skip to content

Commit fc2d019

Browse files
committed
Resolve conflicts
2 parents 5660bf1 + 4fbb2f5 commit fc2d019

File tree

22 files changed

+212
-52
lines changed

22 files changed

+212
-52
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
strategy:
77
matrix:
88
redis_server: ["4", "5", "6", "7"]
9-
ruby: ["2.7", "3.0", "3.1", "3.2"]
9+
ruby: ["3.1", "3.2", "3.3"]
1010

1111
name: Redis server ${{ matrix.redis_server }} - Ruby ${{ matrix.ruby }}
1212

.github/workflows/rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
bundler-cache: true
2020

2121
- name: Run RuboCop
22-
run: bundle exec rubocop --parallel
22+
run: bin/rubocop --parallel

.rubocop.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
inherit_from: https://raw.githubusercontent.com/rails/rails/main/.rubocop.yml
1+
# Omakase Ruby styling for Rails
2+
inherit_gem: { rubocop-rails-omakase: rubocop.yml }

Gemfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,4 @@ gemspec
66

77
gem "rake"
88
gem "debug", ">= 1.0.0"
9-
gem "rubocop"
10-
gem "rubocop-minitest"
11-
gem "rubocop-packaging"
12-
gem "rubocop-performance"
13-
gem "rubocop-rails"
14-
gem "rubocop-md"
9+
gem "rubocop-rails-omakase"

Gemfile.lock

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
kredis (1.6.0)
4+
kredis (1.7.0)
55
activemodel (>= 6.0.0)
66
activesupport (>= 6.0.0)
77
redis (>= 4.2, < 6)
@@ -84,7 +84,7 @@ GEM
8484
io-console (0.6.0)
8585
irb (1.7.1)
8686
reline (>= 0.3.0)
87-
json (2.6.3)
87+
json (2.7.1)
8888
language_server-protocol (3.17.0.3)
8989
loofah (2.9.0)
9090
crass (~> 1.0.2)
@@ -104,8 +104,8 @@ GEM
104104
racc (~> 1.4)
105105
nokogiri (1.15.2-x86_64-darwin)
106106
racc (~> 1.4)
107-
parallel (1.23.0)
108-
parser (3.2.2.3)
107+
parallel (1.24.0)
108+
parser (3.2.2.4)
109109
ast (~> 2.4.1)
110110
racc
111111
racc (1.7.1)
@@ -140,40 +140,43 @@ GEM
140140
thor (~> 1.0)
141141
rainbow (3.1.1)
142142
rake (13.0.3)
143-
redis (5.0.7)
144-
redis-client (>= 0.9.0)
145-
redis-client (0.17.0)
143+
redis (5.0.8)
144+
redis-client (>= 0.17.0)
145+
redis-client (0.19.1)
146146
connection_pool
147-
regexp_parser (2.8.1)
147+
regexp_parser (2.8.3)
148148
reline (0.3.6)
149149
io-console (~> 0.5)
150-
rexml (3.2.5)
151-
rubocop (1.54.1)
150+
rexml (3.2.6)
151+
rubocop (1.59.0)
152152
json (~> 2.3)
153153
language_server-protocol (>= 3.17.0)
154154
parallel (~> 1.10)
155-
parser (>= 3.2.2.3)
155+
parser (>= 3.2.2.4)
156156
rainbow (>= 2.2.2, < 4.0)
157157
regexp_parser (>= 1.8, < 3.0)
158158
rexml (>= 3.2.5, < 4.0)
159-
rubocop-ast (>= 1.28.0, < 2.0)
159+
rubocop-ast (>= 1.30.0, < 2.0)
160160
ruby-progressbar (~> 1.7)
161161
unicode-display_width (>= 2.4.0, < 3.0)
162-
rubocop-ast (1.29.0)
162+
rubocop-ast (1.30.0)
163163
parser (>= 3.2.1.0)
164-
rubocop-md (1.2.0)
165-
rubocop (>= 1.0)
166-
rubocop-minitest (0.31.0)
164+
rubocop-minitest (0.34.2)
167165
rubocop (>= 1.39, < 2.0)
168-
rubocop-packaging (0.5.2)
169-
rubocop (>= 1.33, < 2.0)
170-
rubocop-performance (1.18.0)
171-
rubocop (>= 1.7.0, < 2.0)
172-
rubocop-ast (>= 0.4.0)
173-
rubocop-rails (2.20.2)
166+
rubocop-ast (>= 1.30.0, < 2.0)
167+
rubocop-performance (1.20.1)
168+
rubocop (>= 1.48.1, < 2.0)
169+
rubocop-ast (>= 1.30.0, < 2.0)
170+
rubocop-rails (2.23.1)
174171
activesupport (>= 4.2.0)
175172
rack (>= 1.1)
176173
rubocop (>= 1.33.0, < 2.0)
174+
rubocop-ast (>= 1.30.0, < 2.0)
175+
rubocop-rails-omakase (1.0.0)
176+
rubocop
177+
rubocop-minitest
178+
rubocop-performance
179+
rubocop-rails
177180
ruby-progressbar (1.13.0)
178181
sprockets (4.0.2)
179182
concurrent-ruby (~> 1.0)
@@ -185,7 +188,7 @@ GEM
185188
thor (1.1.0)
186189
tzinfo (2.0.4)
187190
concurrent-ruby (~> 1.0)
188-
unicode-display_width (2.4.2)
191+
unicode-display_width (2.5.0)
189192
websocket-driver (0.7.3)
190193
websocket-extensions (>= 0.1.0)
191194
websocket-extensions (0.1.5)
@@ -201,12 +204,7 @@ DEPENDENCIES
201204
kredis!
202205
rails (>= 6.0.0)
203206
rake
204-
rubocop
205-
rubocop-md
206-
rubocop-minitest
207-
rubocop-packaging
208-
rubocop-performance
209-
rubocop-rails
207+
rubocop-rails-omakase
210208

211209
BUNDLED WITH
212210
2.3.12

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ sleep 0.5.seconds
161161
true == flag.marked? #=> EXISTS myflag
162162
sleep 0.6.seconds
163163
false == flag.marked? #=> EXISTS myflag
164+
165+
limiter = Kredis.limiter "mylimit", limit: 3, expires_in: 5.seconds
166+
0 == limiter.value # => GET "limiter"
167+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
168+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
169+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
170+
false == limiter.exceeded? # => GET "limiter"
171+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
172+
true == limiter.exceeded? # => GET "limiter"
173+
sleep 6
174+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
175+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
176+
limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
177+
false == limiter.exceeded? # => GET "limiter"
164178
```
165179

166180
### Models
@@ -245,9 +259,11 @@ Additional configurations can be added under `config/redis/*.yml` and referenced
245259

246260
Kredis passes the configuration to `Redis.new` to establish the connection. See the [Redis documentation](https://github.com/redis/redis-rb) for other configuration options.
247261

262+
If you don't have `config/redis/shared.yml` (or use another named configuration), Kredis will default to look in env for `REDIS_URL`, then fallback to a default URL of `redis://127.0.0.1:6379/0`.
263+
248264
### Redis support
249265

250-
Kredis works with Redis server 4.0+, with the [Redis Ruby](https://github.com/redis/redis-rb) client version 4.2+.
266+
Kredis works with Redis server 4.0+, with the [Redis Ruby](https://github.com/redis/redis-rb) client version 4.2+. Redis Cluster is not supported.
251267

252268
### Setting SSL options on Redis Connections
253269

bin/rubocop

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rubocop' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12+
13+
bundle_binstub = File.expand_path("bundle", __dir__)
14+
15+
if File.file?(bundle_binstub)
16+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
17+
load(bundle_binstub)
18+
else
19+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21+
end
22+
end
23+
24+
require "rubygems"
25+
require "bundler/setup"
26+
27+
load Gem.bin_path("rubocop", "rubocop")

lib/kredis/attributes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def kredis_counter(name, key: nil, default: nil, config: :shared, after_change:
7272
kredis_connection_with __method__, name, key, default: default, config: config, after_change: after_change, expires_in: expires_in
7373
end
7474

75+
def kredis_limiter(name, limit:, key: nil, config: :shared, after_change: nil, expires_in: nil)
76+
kredis_connection_with __method__, name, key, limit: limit, config: config, after_change: after_change, expires_in: expires_in
77+
end
78+
7579
def kredis_hash(name, key: nil, default: nil, typed: :string, config: :shared, after_change: nil)
7680
kredis_connection_with __method__, name, key, default: default, typed: typed, config: config, after_change: after_change
7781
end

lib/kredis/connections.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
require "redis"
44

55
module Kredis::Connections
6+
DEFAULT_REDIS_URL = "redis://127.0.0.1:6379/0"
7+
DEFAULT_REDIS_TIMEOUT = 1
8+
69
mattr_accessor :connections, default: Hash.new
710
mattr_accessor :configurator
811
mattr_accessor :connector, default: ->(config) { Redis.new(config) }
912

1013
def configured_for(name)
1114
connections[name] ||= Kredis.instrument :meta, message: "Connected to #{name}" do
12-
connector.call configurator.config_for("redis/#{name}")
15+
if configurator.root.join("config/redis/#{name}.yml").exist?
16+
connector.call configurator.config_for("redis/#{name}")
17+
elsif name == :shared
18+
Redis.new url: ENV.fetch("REDIS_URL", DEFAULT_REDIS_URL), timeout: DEFAULT_REDIS_TIMEOUT
19+
else
20+
raise "No configuration found for #{name}"
21+
end
1322
end
1423
end
1524

lib/kredis/types.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def slots(key, available:, config: :shared, after_change: nil)
8585
type_from(Slots, config, key, after_change: after_change, available: available)
8686
end
8787

88+
def limiter(key, limit:, expires_in: nil, config: :shared, after_change: nil)
89+
type_from(Limiter, config, key, after_change: after_change, expires_in: expires_in, limit: limit)
90+
end
91+
8892
private
8993
def type_from(type_klass, config, key, after_change: nil, **options)
9094
type_klass.new(configured_for(config), namespaced_key(key), **options).then do |type|
@@ -107,3 +111,4 @@ def type_from(type_klass, config, key, after_change: nil, **options)
107111
require "kredis/types/set"
108112
require "kredis/types/ordered_set"
109113
require "kredis/types/slots"
114+
require "kredis/types/limiter"

0 commit comments

Comments
 (0)