Class: AfterMigrate::Stores::RedisStore
- Defined in:
- lib/after_migrate/store.rb
Instance Attribute Summary collapse
-
#key_prefix ⇒ Object
readonly
Returns the value of attribute key_prefix.
-
#run_id ⇒ Object
readonly
Returns the value of attribute run_id.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #affected_tables ⇒ Object
-
#initialize(redis:, key_prefix: 'after_migrate', run_id: nil, ttl: 24 * 60 * 60) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #merge_tables(schema, table_names) ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize(redis:, key_prefix: 'after_migrate', run_id: nil, ttl: 24 * 60 * 60) ⇒ RedisStore
Returns a new instance of RedisStore.
107 108 109 110 111 112 113 |
# File 'lib/after_migrate/store.rb', line 107 def initialize(redis:, key_prefix: 'after_migrate', run_id: nil, ttl: 24 * 60 * 60) super() @redis = redis @key_prefix = key_prefix.to_s @run_id = run_id.to_s.presence || 'default' @ttl = ttl.to_i end |
Instance Attribute Details
#key_prefix ⇒ Object (readonly)
Returns the value of attribute key_prefix.
105 106 107 |
# File 'lib/after_migrate/store.rb', line 105 def key_prefix @key_prefix end |
#run_id ⇒ Object (readonly)
Returns the value of attribute run_id.
105 106 107 |
# File 'lib/after_migrate/store.rb', line 105 def run_id @run_id end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
105 106 107 |
# File 'lib/after_migrate/store.rb', line 105 def ttl @ttl end |
Instance Method Details
#affected_tables ⇒ Object
115 116 117 118 |
# File 'lib/after_migrate/store.rb', line 115 def affected_tables load_into_memory super end |
#merge_tables(schema, table_names) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/after_migrate/store.rb', line 120 def merge_tables(schema, table_names) return if table_names.blank? with_redis do |redis| redis.sadd(index_key, schema) redis.sadd(schema_key(schema), table_names.to_a) expire_keys(redis, schema) end merge_into_memory(schema => table_names) end |
#reset! ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/after_migrate/store.rb', line 131 def reset! super with_redis do |redis| schemas = redis.smembers(index_key) keys = schemas.map { |schema| schema_key(schema) } redis.del(*(keys + [index_key])) if keys.any? redis.del(index_key) if keys.empty? end end |