Skip to content

Commit

Permalink
Document expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
heka1024 committed Mar 3, 2024
1 parent 4b69e05 commit b835839
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
false == limiter.exceeded? # => GET "limiter"
```

Lists, unique lists, sets, and ordered sets support expiration:

```ruby
set = Kredis.set "myset", expires_in: 1.second
set.add "hello", "world" # => SADD myset "hello" "world"
true == set.include?("hello") # => SISMEMBER myset "hello
sleep 2
[] == set.members # => SMEMBERS myset
```

To support lower versions of redis, which does not has `nx` option on `EXPIRE` command, multiple commands are used to achieve the same effect.

### Models

You can use all these structures in models:
Expand All @@ -189,6 +201,7 @@ class Person < ApplicationRecord
kredis_unique_list :skills, limit: 2
kredis_enum :morning, values: %w[ bright blue black ], default: "bright"
kredis_counter :steps, expires_in: 1.hour
kredis_set :favorite_colors, expires_in: 1.day

private
def generate_names_key
Expand Down

0 comments on commit b835839

Please sign in to comment.