Skip to content

Commit 21384ac

Browse files
committed
Document expiration
1 parent 2a0db3e commit 21384ac

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
181181
false == limiter.exceeded? # => GET "limiter"
182182
```
183183

184+
Lists, unique lists, sets, and ordered sets support expiration:
185+
186+
```ruby
187+
set = Kredis.set "myset", expires_in: 1.second
188+
set.add "hello", "world" # => SADD myset "hello" "world"
189+
true == set.include?("hello") # => SISMEMBER myset "hello
190+
sleep 2
191+
[] == set.members # => SMEMBERS myset
192+
```
193+
194+
To support lower versions of redis, which does not has `nx` option on `EXPIRE` command, multiple commands are used to achieve the same effect.
195+
184196
### Models
185197

186198
You can use all these structures in models:
@@ -193,6 +205,7 @@ class Person < ApplicationRecord
193205
kredis_unique_list :skills, limit: 2
194206
kredis_enum :morning, values: %w[ bright blue black ], default: "bright"
195207
kredis_counter :steps, expires_in: 1.hour
208+
kredis_set :favorite_colors, expires_in: 1.day
196209

197210
private
198211
def generate_names_key

0 commit comments

Comments
 (0)