ozy 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +50 -27
- data/lib/ozy.rb +3 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -1,53 +1,76 @@
|
|
1
|
-
|
1
|
+
Ozymandias
|
2
2
|
=
|
3
3
|
|
4
|
-
**
|
4
|
+
**Ozy** is a simple Hash subclass that persists itself to Redis, if you'll let it. This provides a clean interface to storing data in Redis without calling all those crazy Redis commands. Of course, Ozy also supports those commands, so go nuts.
|
5
5
|
|
6
6
|
Install
|
7
7
|
==
|
8
8
|
|
9
9
|
Install using Rubygems:
|
10
10
|
|
11
|
-
gem install
|
11
|
+
gem install ozy
|
12
12
|
|
13
13
|
Then:
|
14
14
|
|
15
15
|
require 'rubygems'
|
16
|
-
require '
|
17
|
-
|
18
|
-
Addressabler will automatically require `addressable/uri`.
|
16
|
+
require 'ozy'
|
19
17
|
|
20
18
|
Usage
|
21
19
|
==
|
22
20
|
|
23
|
-
|
21
|
+
Ozy's are just Hashes, but accept a hash for its initialization:
|
22
|
+
|
23
|
+
@ozy = Ozy.new(:foo => :bar)
|
24
|
+
|
25
|
+
Persistence
|
26
|
+
===
|
27
|
+
|
28
|
+
An Ozy won't persist until you tell it to by calling "save" and passing it a key:
|
29
|
+
|
30
|
+
@ozy.save(:key)
|
31
|
+
|
32
|
+
You can get an Ozy using that key:
|
33
|
+
|
34
|
+
Ozy.get(:key) #=> key: {:foo => :bar}
|
35
|
+
|
36
|
+
Expiration
|
37
|
+
===
|
38
|
+
You can pass an options hash into an Ozy initializer as well. Currently, the only supported option is `expire`:
|
39
|
+
|
40
|
+
@ozy = Ozy.new({:foo => :bar}, :expire => 60)
|
41
|
+
@ozy.expires_in #=> 60
|
42
|
+
|
43
|
+
Ozy's expiration times won't start ticking down until you save them. Cause they're not in Redis yet. Are you getting it?
|
24
44
|
|
25
|
-
@
|
26
|
-
|
45
|
+
@ozy.save(:key)
|
46
|
+
sleep 1
|
47
|
+
@ozy.expires_in #=> 59
|
27
48
|
|
28
|
-
|
49
|
+
You can extend an Ozy's expiration like so:
|
29
50
|
|
30
|
-
@
|
31
|
-
@
|
32
|
-
@uri.subdomain #=> "www"
|
51
|
+
@ozy.expire_in! 120
|
52
|
+
@ozy.expires_in #=> 120
|
33
53
|
|
34
|
-
|
54
|
+
Automatic Persistence
|
55
|
+
===
|
56
|
+
Changes made to a saved Ozy will automatically persist to Redis without calling save again:
|
35
57
|
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
|
41
|
-
@uri.host #=> "developers.amazon.org"
|
58
|
+
@ozy = Ozy.new(:foo => :bar)
|
59
|
+
@ozy.save(:key)
|
60
|
+
@ozy.merge!(:foo => :baz)
|
61
|
+
@ozy[:your] = :mom
|
62
|
+
Ozy.get(:key) #=> foo: {:foo => :baz, :your => :mom}
|
42
63
|
|
43
|
-
|
64
|
+
If you want to skip the whole "save" thing, just call Ozy.create(key, attributes):
|
44
65
|
|
45
|
-
@
|
46
|
-
|
66
|
+
@ozy = Ozy.create(:key, :i_will => :hunt_ed)
|
67
|
+
Ozy.get(:key) #=> key: {:i_will => :hunt_ed}
|
47
68
|
|
48
|
-
|
69
|
+
Redis Commands
|
70
|
+
===
|
71
|
+
Ozy's accept any key-based Redis command, as well. Example:
|
49
72
|
|
50
|
-
@
|
51
|
-
|
73
|
+
@ozy.del
|
74
|
+
Ozy.get(:key) #=> nil
|
52
75
|
|
53
|
-
|
76
|
+
And... that's it!
|
data/lib/ozy.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ozy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Flip Sasser
|