Class: MapRedus::FileSystem
- Inherits:
-
Object
- Object
- MapRedus::FileSystem
- Defined in:
- lib/mapredus/filesystem.rb
Overview
Manages the book keeping of redis keys and redis usage provides the data storage for process information through redis All interaction with redis should go through this class
Class Method Summary collapse
- .acquire_lock(key) ⇒ Object
-
.copy(first_key, second_key) ⇒ Object
Copy the values from one key to a second key.
-
.has_lock?(key) ⇒ Boolean
Setup locks on results using RedisSupport lock functionality.
- .method_missing(method, *args, &block) ⇒ Object
- .release_lock(key) ⇒ Object
-
.save(key, value, time = nil) ⇒ Object
Save/Read functions to save/read values for a redis key.
- .storage ⇒ Object
Class Method Details
.acquire_lock(key) ⇒ Object
60 61 62 |
# File 'lib/mapredus/filesystem.rb', line 60 def self.acquire_lock(key) MapRedus.acquire_redis_lock_nonblock( RedisKey.result_cache(key), 60 * 60 ) end |
.copy(first_key, second_key) ⇒ Object
Copy the values from one key to a second key
NOTE TODO: currently only works for the redis list data structure but will be extended for arbitrary data types.
NOTE: this does not account for the key being changed during the copy, so should not be used in situations where the first_key value can change during the running of copy.
Examples
FileSystem.copy("key_one", "key_two")
returns true on success false otherwise
41 42 43 44 45 46 47 |
# File 'lib/mapredus/filesystem.rb', line 41 def self.copy(first_key, second_key) list_length = storage.llen(first_key) list_length.times do |index| storage.rpush(second_key, storage.lindex(first_key, index)) end true end |
.has_lock?(key) ⇒ Boolean
Setup locks on results using RedisSupport lock functionality
Examples
FileSystem::has_lock?(key)
# => true or false
Returns true if there’s a lock
56 57 58 |
# File 'lib/mapredus/filesystem.rb', line 56 def self.has_lock?(key) MapRedus.has_redis_lock?( RedisKey.result_cache(key) ) end |
.method_missing(method, *args, &block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/mapredus/filesystem.rb', line 20 def self.method_missing(method, *args, &block) if storage.respond_to?(method) storage.send(method, *args) else super end end |
.release_lock(key) ⇒ Object
64 65 66 |
# File 'lib/mapredus/filesystem.rb', line 64 def self.release_lock(key) MapRedus.release_redis_lock( RedisKey.result_cache(key) ) end |
.save(key, value, time = nil) ⇒ Object
15 16 17 18 |
# File 'lib/mapredus/filesystem.rb', line 15 def self.save(key, value, time = nil) storage.set(key, value) storage.expire(key, time) if time end |
.storage ⇒ Object
7 8 9 |
# File 'lib/mapredus/filesystem.rb', line 7 def self.storage MapRedus.redis end |