Module: Picky::Backends::Redis::DirectlyManipulable
- Defined in:
- lib/picky/backends/redis/directly_manipulable.rb
Constant Summary collapse
- @@append_index =
THINK Current implementation is very brittle.
0- @@unshift_index =
THINK Current implementation is very brittle.
0
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#key ⇒ Object
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(value) ⇒ Object
-
#delete(value) ⇒ Object
Deletes the value.
- #unshift(value) ⇒ Object
-
#zadd(value, index) ⇒ Object
Z-Adds a value with the given index.
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
9 10 11 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 9 def backend @backend end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 9 def key @key end |
Class Method Details
.make(backend, list, key) ⇒ Object
11 12 13 14 15 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 11 def self.make backend, list, key list.extend DirectlyManipulable list.backend = backend list.key = key end |
Instance Method Details
#<<(value) ⇒ Object
20 21 22 23 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 20 def << value super zadd value, @@append_index += 1 end |
#delete(value) ⇒ Object
Deletes the value.
35 36 37 38 39 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 35 def delete value result = super value backend.client.zrem "#{backend.namespace}:#{key}", value if result result end |
#unshift(value) ⇒ Object
28 29 30 31 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 28 def unshift value super zadd value, @@unshift_index -= 1 end |
#zadd(value, index) ⇒ Object
Z-Adds a value with the given index.
43 44 45 46 |
# File 'lib/picky/backends/redis/directly_manipulable.rb', line 43 def zadd value, index backend.client.zadd "#{backend.namespace}:#{key}", index, value backend[key] end |