Class: LaunchDarkly::Impl::Integrations::Redis::RedisFeatureStoreCore
- Inherits:
-
RedisStoreImplBase
- Object
- RedisStoreImplBase
- LaunchDarkly::Impl::Integrations::Redis::RedisFeatureStoreCore
- Defined in:
- lib/ldclient-rb/impl/integrations/redis_impl.rb
Overview
Internal implementation of the Redis feature store, intended to be used with CachingStoreWrapper.
Instance Method Summary collapse
- #description ⇒ Object
- #get_all_internal(kind) ⇒ Object
- #get_internal(kind, key) ⇒ Object
- #init_internal(all_data) ⇒ Object
-
#initialize(opts) ⇒ RedisFeatureStoreCore
constructor
A new instance of RedisFeatureStoreCore.
- #initialized_internal? ⇒ Boolean
- #upsert_internal(kind, new_item) ⇒ Object
Methods inherited from RedisStoreImplBase
Constructor Details
#initialize(opts) ⇒ RedisFeatureStoreCore
Returns a new instance of RedisFeatureStoreCore.
72 73 74 75 76 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 72 def initialize(opts) super(opts) @test_hook = opts[:test_hook] # used for unit tests, deliberately undocumented end |
Instance Method Details
#description ⇒ Object
78 79 80 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 78 def description "RedisFeatureStore" end |
#get_all_internal(kind) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 105 def get_all_internal(kind) fs = {} with_connection do |redis| hashfs = redis.hgetall(items_key(kind)) hashfs.each do |k, json_item| fs[k.to_sym] = Model.deserialize(kind, json_item) end end fs end |
#get_internal(kind, key) ⇒ Object
99 100 101 102 103 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 99 def get_internal(kind, key) with_connection do |redis| get_redis(redis, kind, key) end end |
#init_internal(all_data) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 82 def init_internal(all_data) count = 0 with_connection do |redis| redis.multi do |multi| all_data.each do |kind, items| multi.del(items_key(kind)) count = count + items.count items.each do |key, item| multi.hset(items_key(kind), key, Model.serialize(kind,item)) end end multi.set(inited_key, inited_key) end end @logger.info { "RedisFeatureStore: initialized with #{count} items" } end |
#initialized_internal? ⇒ Boolean
147 148 149 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 147 def initialized_internal? with_connection { |redis| redis.exists?(inited_key) } end |
#upsert_internal(kind, new_item) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ldclient-rb/impl/integrations/redis_impl.rb', line 116 def upsert_internal(kind, new_item) base_key = items_key(kind) key = new_item[:key] try_again = true final_item = new_item while try_again try_again = false with_connection do |redis| redis.watch(base_key) do old_item = get_redis(redis, kind, key) before_update_transaction(base_key, key) if old_item.nil? || old_item[:version] < new_item[:version] result = redis.multi do |multi| multi.hset(base_key, key, Model.serialize(kind, new_item)) end if result.nil? @logger.debug { "RedisFeatureStore: concurrent modification detected, retrying" } try_again = true end else final_item = old_item action = new_item[:deleted] ? "delete" : "update" @logger.warn { "RedisFeatureStore: attempted to #{action} #{key} version: #{old_item[:version]} in '#{kind[:namespace]}' with a version that is the same or older: #{new_item[:version]}" } end redis.unwatch end end end final_item end |