mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActionCable: add id option to redis adapter config
This commit is contained in:
parent
bd932f5d22
commit
bcd11e07b5
3 changed files with 30 additions and 3 deletions
|
@ -1,3 +1,21 @@
|
||||||
|
* Add `id` option to redis adapter so now you can distinguish
|
||||||
|
ActionCable's redis connections among others. Also, you can set
|
||||||
|
custom id in options.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
```
|
||||||
|
$ redis-cli client list
|
||||||
|
id=669 addr=127.0.0.1:46442 fd=8 name= age=18 ...
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
```
|
||||||
|
$ redis-cli client list
|
||||||
|
id=673 addr=127.0.0.1:46516 fd=8 name=ActionCable-PID-19413 age=2 ...
|
||||||
|
```
|
||||||
|
|
||||||
|
*Ilia Kasianenko*
|
||||||
|
|
||||||
* Rails 6 requires Ruby 2.4.1 or newer.
|
* Rails 6 requires Ruby 2.4.1 or newer.
|
||||||
|
|
||||||
*Jeremy Daer*
|
*Jeremy Daer*
|
||||||
|
|
|
@ -13,7 +13,8 @@ module ActionCable
|
||||||
# Overwrite this factory method for Redis connections if you want to use a different Redis library than the redis gem.
|
# Overwrite this factory method for Redis connections if you want to use a different Redis library than the redis gem.
|
||||||
# This is needed, for example, when using Makara proxies for distributed Redis.
|
# This is needed, for example, when using Makara proxies for distributed Redis.
|
||||||
cattr_accessor :redis_connector, default: ->(config) do
|
cattr_accessor :redis_connector, default: ->(config) do
|
||||||
::Redis.new(config.slice(:url, :host, :port, :db, :password))
|
config[:id] ||= "ActionCable-PID-#{$$}"
|
||||||
|
::Redis.new(config.slice(:url, :host, :port, :db, :password, :id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(*)
|
def initialize(*)
|
||||||
|
|
|
@ -30,14 +30,22 @@ class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
|
||||||
end
|
end
|
||||||
|
|
||||||
class RedisAdapterTest::Connector < ActionCable::TestCase
|
class RedisAdapterTest::Connector < ActionCable::TestCase
|
||||||
test "slices url, host, port, db, and password from config" do
|
test "slices url, host, port, db, password and id from config" do
|
||||||
config = { url: 1, host: 2, port: 3, db: 4, password: 5 }
|
config = { url: 1, host: 2, port: 3, db: 4, password: 5, id: "Some custom ID" }
|
||||||
|
|
||||||
assert_called_with ::Redis, :new, [ config ] do
|
assert_called_with ::Redis, :new, [ config ] do
|
||||||
connect config.merge(other: "unrelated", stuff: "here")
|
connect config.merge(other: "unrelated", stuff: "here")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "adds default id if it is not specified" do
|
||||||
|
config = { url: 1, host: 2, port: 3, db: 4, password: 5, id: "ActionCable1-PID-#{$$}" }
|
||||||
|
|
||||||
|
assert_called_with ::Redis, :new, [ config ] do
|
||||||
|
connect config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def connect(config)
|
def connect(config)
|
||||||
ActionCable::SubscriptionAdapter::Redis.redis_connector.call(config)
|
ActionCable::SubscriptionAdapter::Redis.redis_connector.call(config)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue