Skip to content

Commit 55fa582

Browse files
committed
Add more documentation for 'set' method and updated error message, add client.set case using force option in order to clarify how to use this option since they are 2 positional hash arguments
1 parent 5828241 commit 55fa582

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.bundle
33
Gemfile.lock
44
coverage/
5+
.byebug_history

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ Stasche.set(user_emails: User.where(id: ids).pluck(:email))
7777
user_emails = Stasche.get(:user_emails)
7878
```
7979

80+
### Setting options
81+
The set method allows you to add an `options` hash as a second parameter, for example to set a given key even if already exists
82+
```rb
83+
# Session A
84+
Stasche.set({foo: 'bar'}, force: true)
85+
86+
# Session B
87+
foo_value = Stasche.get(:foo)
88+
```
89+
8090
### Pushing/Peeking/Popping values
8191

8292
```rb

lib/stasche/store.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class KeyAlreadyExistsError < StandardError
44

55
def initialize(key)
66
super(
7-
"Key #{key} already set in stasche. Use `force: true` to override."
7+
"Key #{key} already set in stasche. Use `force: true` to override, example: Stasche.set({foo: 'bar'}, force: true)"
88
)
99
end
1010

spec/stasche/client_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
error_class = Stasche::Store::KeyAlreadyExistsError
7575
expect { client.set(foo: 'bar') }.to raise_error(error_class)
7676
end
77+
78+
it 'does not throws an exception if forced' do
79+
expect { client.set({ foo: 'bar' }, force: true) }.to_not raise_error
80+
end
7781
end
7882
end
7983

0 commit comments

Comments
 (0)