Skip to content

Commit 2ea0d48

Browse files
authored
Merge pull request #57 from excid3/redis-url
Use REDIS_URL by default
2 parents cb2a3a1 + d4e88f0 commit 2ea0d48

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

README.md

+8-23
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,24 @@ cycle.next # => GET mycycle + SET mycycle 0
105105
:one == cycle.value # => GET mycycle
106106

107107
enum = Kredis.enum "myenum", values: %w[ one two three ], default: "one"
108-
"one" == enum.value # => GET myenum
108+
"one" == enum.value # => GET myenum
109109
true == enum.one? # => GET myenum
110110
enum.value = "two" # => SET myenum "two"
111111
"two" == enum.value # => GET myenum
112112
enum.value = "four"
113113
"two" == enum.value # => GET myenum
114114
enum.reset # => DEL myenum
115-
"one" == enum.value # => GET myenum
115+
"one" == enum.value # => GET myenum
116116

117117
slots = Kredis.slots "myslots", available: 3
118118
true == slots.available? # => GET myslots
119119
slots.reserve # => INCR myslots
120120
true == slots.available? # => GET myslots
121-
slots.reserve # => INCR myslots
121+
slots.reserve # => INCR myslots
122122
true == slots.available? # => GET myslots
123123
slots.reserve # => INCR myslots
124124
false == slots.available? # => GET myslots
125-
slots.reserve # => INCR myslots + DECR myslots
125+
slots.reserve # => INCR myslots + DECR myslots
126126
false == slots.available? # => GET myslots
127127
slots.release # => DECR myslots
128128
true == slots.available? # => GET myslots
@@ -141,7 +141,7 @@ flag = Kredis.flag "myflag"
141141
false == flag.marked? # => EXISTS myflag
142142
flag.mark # => SET myflag 1
143143
true == flag.marked? # => EXISTS myflag
144-
flag.remove # => DEL myflag
144+
flag.remove # => DEL myflag
145145
false == flag.marked? # => EXISTS myflag
146146

147147
true == flag.mark(expires_in: 1.second, force: false) #=> SET myflag 1 EX 1 NX
@@ -196,26 +196,11 @@ end
196196

197197
1. Add the `kredis` gem to your Gemfile: `gem 'kredis'`
198198
2. Run `./bin/bundle install`
199-
3. Run `./bin/rails kredis:install` to add a default configuration under `config/redis/shared.yml`
200-
201-
A default configuration can look like this for `config/redis/shared.yml`:
202-
203-
```yaml
204-
production: &production
205-
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
206-
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
207-
timeout: 1
199+
3. Run `./bin/rails kredis:install` to add a default configuration at [`config/redis/shared.yml`](lib/install/shared.yml)
208200

209-
development: &development
210-
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
211-
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
212-
timeout: 1
213-
214-
test:
215-
<<: *development
216-
```
201+
Additional configurations can be added under `config/redis/*.yml` and referenced when a type is created. For example, `Kredis.string("mystring", config: :strings)` would lookup `config/redis/strings.yml`.
217202

218-
Additional configurations can be added under `config/redis/*.yml` and referenced when a type is created, e.g. `Kredis.string("mystring", config: :strings)` would lookup `config/redis/strings.yml`. Under the hood `Kredis.configured_for` is called which'll pass the configuration on to `Redis.new`.
203+
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.
219204

220205
### Setting SSL options on Redis Connections
221206

lib/install/shared.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
production: &production
2-
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
3-
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
2+
url: <%= ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379/0") %>
43
timeout: 1
54

65
development: &development
7-
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
8-
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
6+
url: <%= ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379/0") %>
97
timeout: 1
108

9+
# You can also specify host, port, and db instead of url
10+
# host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
11+
# port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
12+
# db: <%= ENV.fetch("REDIS_SHARED_DB", "11") %>
13+
1114
test:
1215
<<: *development

0 commit comments

Comments
 (0)