Class: Rhoconnect::Store
- Inherits:
-
Object
- Object
- Rhoconnect::Store
- Defined in:
- lib/rhoconnect/store.rb
Constant Summary collapse
- @@dbs =
nil
Class Method Summary collapse
-
.clone(srckey, dstkey) ⇒ Object
Create a copy of srckey in dstkey.
- .create(server = nil) ⇒ Object
- .decr(dockey) ⇒ Object
-
.delete_data(dockey, data = {}) ⇒ Object
Deletes data from a given doctype,source,user.
-
.delete_objects(dockey, data = []) ⇒ Object
Removes objects from a given doctype,source,user.
- .delete_value(dockey) ⇒ Object
- .doc_type(dockey) ⇒ Object
- .exists?(key) ⇒ Boolean
- .flush_all ⇒ Object
-
.flush_data(keymask) ⇒ Object
(also: flash_data)
Deletes all keys matching a given mask.
-
.flush_zdata(dockey) ⇒ Object
Deletes all keys and their hashes from the Redis DB.
-
.get_data(dockey, type = Hash) ⇒ Object
Retrieves set for given dockey,source,user.
- .get_db_doc(dockey) ⇒ Object
-
.get_diff_data(src_dockey, dst_dockey, p_size = nil) ⇒ Object
Retrieves diff data hash between two sets each entry is in the form of DIFF_OBJ_ELEMENT => [OBJ_KEY, OBJ_DATA_PAIRS].
-
.get_diff_data_bruteforce(src_dockey, dst_dockey, p_size = nil) ⇒ Object
Retrieves diff data hash between two sets by using BruteForce approach => download both sets from Redis and compute diffs inside of Ruby worst-cast scenario - it is much slower than doing Redis sdiff but : it allows Redis clustering each entry is in the form of DIFF_OBJ_ELEMENT => [OBJ_KEY, OBJ_DATA_PAIRS].
- .get_inserts_deletes(inserts_elements_map, deletes_elements_map) ⇒ Object
- .get_list(dockey) ⇒ Object
- .get_lock(dockey, timeout = 0, raise_on_expire = false) ⇒ Object
- .get_object(dockey, key) ⇒ Object
- .get_objects(dockey, keys) ⇒ Object
- .get_store(index = 0) ⇒ Object
-
.get_value(dockey) ⇒ Object
Retrieves value for a given key.
-
.get_zdata(dockey) ⇒ Object
Retrieves set for given dockey,associated key (client_id), obj_hashes.
- .incr(dockey) ⇒ Object
- .keys(pattern) ⇒ Object
-
.lock(dockey, timeout = 0, raise_on_expire = false, &block) ⇒ Object
Lock a given key and release when provided block is finished.
- .nullify ⇒ Object
- .num_stores ⇒ Object
-
.put_data(dockey, data = {}, append = false) ⇒ Object
(also: set_data)
Adds set with given data, replaces existing set if it exists or appends data to the existing set if append flag set to true.
- .put_list(dockey, data = [], append = false) ⇒ Object
- .put_object(dockey, key, data = {}) ⇒ Object
-
.put_tmp_data(dockey, data = {}, append = false) ⇒ Object
Same as above, but sets TTL on every key.
-
.put_value(dockey, value) ⇒ Object
(also: set_value)
Adds a simple key/value pair.
- .put_zdata(dockey, assoc_key, data = [], append = false) ⇒ Object
- .reconnect ⇒ Object
- .release_lock(dockey, lock, raise_on_expire = false) ⇒ Object
-
.rename(srckey, dstkey) ⇒ Object
Rename srckey to dstkey.
-
.rename_tmp_data(srckey, dstkey) ⇒ Object
Rename srckey to dstkey.
- .set_db_doc(dockey, data, append = false) ⇒ Object
- .update_count(dockey, count) ⇒ Object
- .update_elements(dockey, inserts_elements_map, deletes_elements_map) ⇒ Object
-
.update_objects(dockey, data = {}) ⇒ Object
updates objects for a given doctype, source, user create new objects if necessary.
-
.zadd(dockey, score, value) ⇒ Object
low-level operations with sorted sets.
- .zrange(dockey, start, stop) ⇒ Object
- .zrem(dockey, value) ⇒ Object
- .zremrangebyscore(dockey, min_elem, max_elem) ⇒ Object
- .zrevrange(dockey, start, stop) ⇒ Object
- .zscore(dockey, value) ⇒ Object
Class Method Details
.clone(srckey, dstkey) ⇒ Object
Create a copy of srckey in dstkey
228 229 230 |
# File 'lib/rhoconnect/store.rb', line 228 def clone(srckey,dstkey) get_store(0).clone(srckey, dstkey) end |
.create(server = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rhoconnect/store.rb', line 17 def create(server=nil) return @@dbs if @@dbs if server.is_a?Array server.each do |server_string| db_inst = RedisImpl.new db_inst.create(server_string) @@dbs ||= [] @@dbs << db_inst end else db_inst = RedisImpl.new db_inst.create(server) @@dbs ||= [] @@dbs << db_inst end @@dbs end |
.decr(dockey) ⇒ Object
141 142 143 |
# File 'lib/rhoconnect/store.rb', line 141 def decr(dockey) get_store(0).decr(dockey) end |
.delete_data(dockey, data = {}) ⇒ Object
Deletes data from a given doctype,source,user
119 120 121 |
# File 'lib/rhoconnect/store.rb', line 119 def delete_data(dockey,data={}) get_store(0).delete_data(dockey, data) end |
.delete_objects(dockey, data = []) ⇒ Object
Removes objects from a given doctype,source,user
114 115 116 |
# File 'lib/rhoconnect/store.rb', line 114 def delete_objects(dockey,data=[]) get_store(0).delete_objects(dockey, data) end |
.delete_value(dockey) ⇒ Object
133 134 135 |
# File 'lib/rhoconnect/store.rb', line 133 def delete_value(dockey) get_store(0).delete_value(dockey) end |
.doc_type(dockey) ⇒ Object
64 65 66 |
# File 'lib/rhoconnect/store.rb', line 64 def doc_type(dockey) get_store(0).db.type(dockey) if dockey end |
.exists?(key) ⇒ Boolean
257 258 259 |
# File 'lib/rhoconnect/store.rb', line 257 def exists?(key) get_store(0).exists?(key) end |
.flush_all ⇒ Object
50 51 52 53 54 |
# File 'lib/rhoconnect/store.rb', line 50 def flush_all @@dbs.each do |store_instance| store_instance.flush_all end end |
.flush_data(keymask) ⇒ Object Also known as: flash_data
Deletes all keys matching a given mask
57 58 59 60 61 |
# File 'lib/rhoconnect/store.rb', line 57 def flush_data(keymask) @@dbs.each do |store| store.flush_data(keymask) end end |
.flush_zdata(dockey) ⇒ Object
Deletes all keys and their hashes from the Redis DB
253 254 255 |
# File 'lib/rhoconnect/store.rb', line 253 def flush_zdata(dockey) get_store(0).flush_zdata(dockey) end |
.get_data(dockey, type = Hash) ⇒ Object
Retrieves set for given dockey,source,user
158 159 160 |
# File 'lib/rhoconnect/store.rb', line 158 def get_data(dockey,type=Hash) get_store(0).get_data(dockey, type) end |
.get_db_doc(dockey) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rhoconnect/store.rb', line 72 def get_db_doc(dockey) doc = "" @@dbs.each do |store| if store.exists?(dockey) doc = store.get_db_doc(dockey) break end end doc end |
.get_diff_data(src_dockey, dst_dockey, p_size = nil) ⇒ Object
Retrieves diff data hash between two sets each entry is in the form of DIFF_OBJ_ELEMENT => [OBJ_KEY, OBJ_DATA_PAIRS]
193 194 195 |
# File 'lib/rhoconnect/store.rb', line 193 def get_diff_data(src_dockey,dst_dockey,p_size=nil) get_store(0).get_diff_data(src_dockey, dst_dockey, p_size) end |
.get_diff_data_bruteforce(src_dockey, dst_dockey, p_size = nil) ⇒ Object
Retrieves diff data hash between two sets by using BruteForce approach
> download both sets from Redis and compute diffs inside of Ruby
worst-cast scenario - it is much slower than doing Redis sdiff but : it allows Redis clustering each entry is in the form of DIFF_OBJ_ELEMENT => [OBJ_KEY, OBJ_DATA_PAIRS]
202 203 204 |
# File 'lib/rhoconnect/store.rb', line 202 def get_diff_data_bruteforce(src_dockey,dst_dockey,p_size=nil) get_store(0).get_diff_data_bruteforce(src_dockey, dst_dockey, p_size) end |
.get_inserts_deletes(inserts_elements_map, deletes_elements_map) ⇒ Object
206 207 208 |
# File 'lib/rhoconnect/store.rb', line 206 def get_inserts_deletes(inserts_elements_map, deletes_elements_map) get_store(0).get_inserts_deletes(inserts_elements_map, deletes_elements_map) end |
.get_list(dockey) ⇒ Object
162 163 164 |
# File 'lib/rhoconnect/store.rb', line 162 def get_list(dockey) get_store(0).get_list(dockey) end |
.get_lock(dockey, timeout = 0, raise_on_expire = false) ⇒ Object
219 220 221 |
# File 'lib/rhoconnect/store.rb', line 219 def get_lock(dockey,timeout=0,raise_on_expire=false) get_store(0).get_lock(dockey, timeout, raise_on_expire) end |
.get_object(dockey, key) ⇒ Object
149 150 151 |
# File 'lib/rhoconnect/store.rb', line 149 def get_object(dockey, key) get_store(0).get_object(dockey, key) end |
.get_objects(dockey, keys) ⇒ Object
153 154 155 |
# File 'lib/rhoconnect/store.rb', line 153 def get_objects(dockey, keys) get_store(0).get_objects(dockey, keys) end |
.get_store(index = 0) ⇒ Object
46 47 48 |
# File 'lib/rhoconnect/store.rb', line 46 def get_store(index = 0) @@dbs[index] end |
.get_value(dockey) ⇒ Object
Retrieves value for a given key
129 130 131 |
# File 'lib/rhoconnect/store.rb', line 129 def get_value(dockey) get_store(0).get_value(dockey) end |
.get_zdata(dockey) ⇒ Object
Retrieves set for given dockey,associated key (client_id), obj_hashes
248 249 250 |
# File 'lib/rhoconnect/store.rb', line 248 def get_zdata(dockey) get_store(0).get_zdata(dockey) end |
.incr(dockey) ⇒ Object
137 138 139 |
# File 'lib/rhoconnect/store.rb', line 137 def incr(dockey) get_store(0).incr(dockey) end |
.keys(pattern) ⇒ Object
83 84 85 |
# File 'lib/rhoconnect/store.rb', line 83 def keys(pattern) get_store(0).keys(pattern) end |
.lock(dockey, timeout = 0, raise_on_expire = false, &block) ⇒ Object
Lock a given key and release when provided block is finished
215 216 217 |
# File 'lib/rhoconnect/store.rb', line 215 def lock(dockey,timeout=0,raise_on_expire=false, &block) get_store(0).lock(dockey, timeout, raise_on_expire, &block) end |
.nullify ⇒ Object
13 14 15 |
# File 'lib/rhoconnect/store.rb', line 13 def nullify @@dbs = nil end |
.num_stores ⇒ Object
42 43 44 |
# File 'lib/rhoconnect/store.rb', line 42 def num_stores @@dbs.nil? ? 0 : @@dbs.size end |
.put_data(dockey, data = {}, append = false) ⇒ Object Also known as: set_data
Adds set with given data, replaces existing set if it exists or appends data to the existing set if append flag set to true
94 95 96 |
# File 'lib/rhoconnect/store.rb', line 94 def put_data(dockey,data={},append=false) get_store(0).put_data(dockey, data, append) end |
.put_list(dockey, data = [], append = false) ⇒ Object
103 104 105 |
# File 'lib/rhoconnect/store.rb', line 103 def put_list(dockey, data=[], append=false) get_store(0).put_list(dockey, data, append) end |
.put_object(dockey, key, data = {}) ⇒ Object
87 88 89 |
# File 'lib/rhoconnect/store.rb', line 87 def put_object(dockey, key, data={}) get_store(0).put_object(dockey, key, data) end |
.put_tmp_data(dockey, data = {}, append = false) ⇒ Object
Same as above, but sets TTL on every key
99 100 101 |
# File 'lib/rhoconnect/store.rb', line 99 def put_tmp_data(dockey,data={},append=false) get_store(0).put_tmp_data(dockey, data, append) end |
.put_value(dockey, value) ⇒ Object Also known as: set_value
Adds a simple key/value pair
124 125 126 |
# File 'lib/rhoconnect/store.rb', line 124 def put_value(dockey,value) get_store(0).put_value(dockey, value) end |
.put_zdata(dockey, assoc_key, data = [], append = false) ⇒ Object
243 244 245 |
# File 'lib/rhoconnect/store.rb', line 243 def put_zdata(dockey,assoc_key,data=[],append=false) get_store(0).put_zdata(dockey, assoc_key, data, append) end |
.reconnect ⇒ Object
36 37 38 39 40 |
# File 'lib/rhoconnect/store.rb', line 36 def reconnect @@dbs.each do |db_inst| db_inst.reconnect end end |
.release_lock(dockey, lock, raise_on_expire = false) ⇒ Object
223 224 225 |
# File 'lib/rhoconnect/store.rb', line 223 def release_lock(dockey,lock,raise_on_expire=false) get_store(0).release_lock(dockey, lock, raise_on_expire) end |
.rename(srckey, dstkey) ⇒ Object
Rename srckey to dstkey
233 234 235 |
# File 'lib/rhoconnect/store.rb', line 233 def rename(srckey,dstkey) get_store(0).rename(srckey, dstkey) end |
.rename_tmp_data(srckey, dstkey) ⇒ Object
Rename srckey to dstkey
238 239 240 |
# File 'lib/rhoconnect/store.rb', line 238 def rename_tmp_data(srckey,dstkey) get_store(0).rename_tmp_data(srckey, dstkey) end |
.set_db_doc(dockey, data, append = false) ⇒ Object
68 69 70 |
# File 'lib/rhoconnect/store.rb', line 68 def set_db_doc(dockey, data, append=false) get_store(0).set_db_doc(dockey, data, append) end |
.update_count(dockey, count) ⇒ Object
145 146 147 |
# File 'lib/rhoconnect/store.rb', line 145 def update_count(dockey, count) get_store(0).update_count(dockey, count) end |
.update_elements(dockey, inserts_elements_map, deletes_elements_map) ⇒ Object
210 211 212 |
# File 'lib/rhoconnect/store.rb', line 210 def update_elements(dockey, inserts_elements_map, deletes_elements_map) get_store(0).update_elements(dockey, inserts_elements_map, deletes_elements_map) end |
.update_objects(dockey, data = {}) ⇒ Object
updates objects for a given doctype, source, user create new objects if necessary
109 110 111 |
# File 'lib/rhoconnect/store.rb', line 109 def update_objects(dockey, data={}) get_store(0).update_objects(dockey, data) end |
.zadd(dockey, score, value) ⇒ Object
low-level operations with sorted sets
167 168 169 |
# File 'lib/rhoconnect/store.rb', line 167 def zadd(dockey, score, value) get_store(0).zadd(dockey, score, value) end |
.zrange(dockey, start, stop) ⇒ Object
187 188 189 |
# File 'lib/rhoconnect/store.rb', line 187 def zrange(dockey, start, stop) get_store(0).zrange(dockey, start, stop) end |
.zrem(dockey, value) ⇒ Object
171 172 173 |
# File 'lib/rhoconnect/store.rb', line 171 def zrem(dockey, value) get_store(0).zrem(dockey, value) end |
.zremrangebyscore(dockey, min_elem, max_elem) ⇒ Object
175 176 177 |
# File 'lib/rhoconnect/store.rb', line 175 def zremrangebyscore(dockey, min_elem, max_elem) get_store(0).zremrangebyscore(dockey, min_elem, max_elem) end |
.zrevrange(dockey, start, stop) ⇒ Object
183 184 185 |
# File 'lib/rhoconnect/store.rb', line 183 def zrevrange(dockey, start, stop) get_store(0).zrevrange(dockey, start, stop) end |
.zscore(dockey, value) ⇒ Object
179 180 181 |
# File 'lib/rhoconnect/store.rb', line 179 def zscore(dockey, value) get_store(0).zscore(dockey, value) end |