Skip to content

Commit 1ad81da

Browse files
committed
Document expiration
1 parent 93aef02 commit 1ad81da

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
@@ -177,6 +177,18 @@ limiter.poke # => SET limiter 0 NX + INCRBY limiter 1
177177
false == limiter.exceeded? # => GET "limiter"
178178
```
179179

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

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

193206
private
194207
def generate_names_key

0 commit comments

Comments
 (0)