Skip to content

Commit 59c8d61

Browse files
brennentsmithjsvd
authored andcommitted
Add support for Redis unix sockets (#64)
* Add support for Redis unix sockets * Make `path` and `host` mutually exclusive * Add documentation updates
1 parent 91be818 commit 59c8d61

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

docs/index.asciidoc

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
4545
| <<plugins-{type}s-{plugin}-data_type>> |<<string,string>>, one of `["list", "channel", "pattern_channel"]`|Yes
4646
| <<plugins-{type}s-{plugin}-db>> |<<number,number>>|No
4747
| <<plugins-{type}s-{plugin}-host>> |<<string,string>>|No
48+
| <<plugins-{type}s-{plugin}-path>> |<<string,string>>|No
4849
| <<plugins-{type}s-{plugin}-key>> |<<string,string>>|Yes
4950
| <<plugins-{type}s-{plugin}-password>> |<<password,password>>|No
5051
| <<plugins-{type}s-{plugin}-port>> |<<number,number>>|No
@@ -58,15 +59,15 @@ input plugins.
5859
&nbsp;
5960

6061
[id="plugins-{type}s-{plugin}-batch_count"]
61-
===== `batch_count`
62+
===== `batch_count`
6263

6364
* Value type is <<number,number>>
6465
* Default value is `125`
6566

6667
The number of events to return from Redis using EVAL.
6768

6869
[id="plugins-{type}s-{plugin}-data_type"]
69-
===== `data_type`
70+
===== `data_type`
7071

7172
* This is a required setting.
7273
* Value can be any of: `list`, `channel`, `pattern_channel`
@@ -77,23 +78,32 @@ key. If `redis\_type` is `channel`, then we will SUBSCRIBE to the key.
7778
If `redis\_type` is `pattern_channel`, then we will PSUBSCRIBE to the key.
7879

7980
[id="plugins-{type}s-{plugin}-db"]
80-
===== `db`
81+
===== `db`
8182

8283
* Value type is <<number,number>>
8384
* Default value is `0`
8485

8586
The Redis database number.
8687

8788
[id="plugins-{type}s-{plugin}-host"]
88-
===== `host`
89+
===== `host`
8990

9091
* Value type is <<string,string>>
9192
* Default value is `"127.0.0.1"`
9293

9394
The hostname of your Redis server.
9495

96+
id="plugins-{type}s-{plugin}-path"]
97+
===== `path`
98+
99+
* Value type is <<string,string>>
100+
* There is no default value for this setting.
101+
* Path will override Host configuration if both specified.
102+
103+
The unix socket path of your Redis server.
104+
95105
[id="plugins-{type}s-{plugin}-key"]
96-
===== `key`
106+
===== `key`
97107

98108
* This is a required setting.
99109
* Value type is <<string,string>>
@@ -102,31 +112,31 @@ The hostname of your Redis server.
102112
The name of a Redis list or channel.
103113

104114
[id="plugins-{type}s-{plugin}-password"]
105-
===== `password`
115+
===== `password`
106116

107117
* Value type is <<password,password>>
108118
* There is no default value for this setting.
109119

110120
Password to authenticate with. There is no authentication by default.
111121

112122
[id="plugins-{type}s-{plugin}-port"]
113-
===== `port`
123+
===== `port`
114124

115125
* Value type is <<number,number>>
116126
* Default value is `6379`
117127

118128
The port to connect on.
119129

120130
[id="plugins-{type}s-{plugin}-threads"]
121-
===== `threads`
131+
===== `threads`
122132

123133
* Value type is <<number,number>>
124134
* Default value is `1`
125135

126136

127137

128138
[id="plugins-{type}s-{plugin}-timeout"]
129-
===== `timeout`
139+
===== `timeout`
130140

131141
* Value type is <<number,number>>
132142
* Default value is `5`
@@ -136,4 +146,4 @@ Initial connection timeout in seconds.
136146

137147

138148
[id="plugins-{type}s-{plugin}-common-options"]
139-
include::{include_path}/{type}.asciidoc[]
149+
include::{include_path}/{type}.asciidoc[]

lib/logstash/inputs/redis.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable
2929
# The port to connect on.
3030
config :port, :validate => :number, :default => 6379
3131

32+
# The unix socket path to connect on. Will override host and port if defined.
33+
# There is no unix socket path by default.
34+
config :path, :validate => :string
35+
3236
# The Redis database number.
3337
config :db, :validate => :number, :default => 0
3438

@@ -68,7 +72,7 @@ def new_redis_instance
6872
end
6973

7074
def register
71-
@redis_url = "redis://#{@password}@#{@host}:#{@port}/#{@db}"
75+
@redis_url = @path.nil? ? "redis://#{@password}@#{@host}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}"
7276

7377
@redis_builder ||= method(:internal_redis_builder)
7478

@@ -114,13 +118,25 @@ def is_list_type?
114118

115119
# private
116120
def redis_params
117-
{
118-
:host => @host,
119-
:port => @port,
121+
if @path.nil?
122+
connectionParams = {
123+
:host => @host,
124+
:port => @port
125+
}
126+
else
127+
@logger.warn("Parameter 'path' is set, ignoring parameters: 'host' and 'port'")
128+
connectionParams = {
129+
:path => @path
130+
}
131+
end
132+
133+
baseParams = {
120134
:timeout => @timeout,
121135
:db => @db,
122136
:password => @password.nil? ? nil : @password.value
123137
}
138+
139+
return connectionParams.merge(baseParams)
124140
end
125141

126142
# private

0 commit comments

Comments
 (0)