Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ cycle.next # => GET mycycle + SET mycycle 0
:one == cycle.value # => GET mycycle

enum = Kredis.enum "myenum", values: %w[ one two three ], default: "one"
"one" == enum.value # => GET myenum
"one" == enum.value # => GET myenum
true == enum.one? # => GET myenum
enum.value = "two" # => SET myenum "two"
"two" == enum.value # => GET myenum
enum.value = "four"
"two" == enum.value # => GET myenum
enum.reset # => DEL myenum
"one" == enum.value # => GET myenum
"one" == enum.value # => GET myenum

slots = Kredis.slots "myslots", available: 3
true == slots.available? # => GET myslots
slots.reserve # => INCR myslots
true == slots.available? # => GET myslots
slots.reserve # => INCR myslots
slots.reserve # => INCR myslots
true == slots.available? # => GET myslots
slots.reserve # => INCR myslots
false == slots.available? # => GET myslots
slots.reserve # => INCR myslots + DECR myslots
slots.reserve # => INCR myslots + DECR myslots
false == slots.available? # => GET myslots
slots.release # => DECR myslots
true == slots.available? # => GET myslots
Expand All @@ -141,7 +141,7 @@ flag = Kredis.flag "myflag"
false == flag.marked? # => EXISTS myflag
flag.mark # => SET myflag 1
true == flag.marked? # => EXISTS myflag
flag.remove # => DEL myflag
flag.remove # => DEL myflag
false == flag.marked? # => EXISTS myflag

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

1. Add the `kredis` gem to your Gemfile: `gem 'kredis'`
2. Run `./bin/bundle install`
3. Run `./bin/rails kredis:install` to add a default configuration under `config/redis/shared.yml`

A default configuration can look like this for `config/redis/shared.yml`:

```yaml
production: &production
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
timeout: 1
3. Run `./bin/rails kredis:install` to add a default configuration at [`config/redis/shared.yml`](lib/install/shared.yml)

development: &development
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
timeout: 1

test:
<<: *development
```
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`.

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`.
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.

### Setting SSL options on Redis Connections

Expand Down
11 changes: 7 additions & 4 deletions lib/install/shared.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
production: &production
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
url: <%= ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379/0") %>
timeout: 1

development: &development
host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
url: <%= ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379/0") %>
timeout: 1

# You can also specify host, port, and db instead of url
# host: <%= ENV.fetch("REDIS_SHARED_HOST", "127.0.0.1") %>
# port: <%= ENV.fetch("REDIS_SHARED_PORT", "6379") %>
# db: <%= ENV.fetch("REDIS_SHARED_DB", "11") %>

test:
<<: *development