lib/ldclient-rb/impl/integrations/redis_impl.rb in launchdarkly-server-sdk-5.8.2 vs lib/ldclient-rb/impl/integrations/redis_impl.rb in launchdarkly-server-sdk-6.0.0
- old
+ new
@@ -53,11 +53,11 @@
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, item.to_json)
+ multi.hset(items_key(kind), key, Model.serialize(kind,item))
end
end
multi.set(inited_key, inited_key)
end
end
@@ -73,12 +73,11 @@
def get_all_internal(kind)
fs = {}
with_connection do |redis|
hashfs = redis.hgetall(items_key(kind))
hashfs.each do |k, json_item|
- f = JSON.parse(json_item, symbolize_names: true)
- fs[k.to_sym] = f
+ fs[k.to_sym] = Model.deserialize(kind, json_item)
end
end
fs
end
@@ -93,11 +92,11 @@
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, new_item.to_json)
+ 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
@@ -113,13 +112,11 @@
end
final_item
end
def initialized_internal?
- with_connection do |redis|
- redis.respond_to?(:exists?) ? redis.exists?(inited_key) : redis.exists(inited_key)
- end
+ with_connection { |redis| redis.exists?(inited_key) }
end
def stop
if @stopped.make_true
return unless @pool_shutdown_on_close
@@ -148,11 +145,10 @@
def with_connection
@pool.with { |redis| yield(redis) }
end
def get_redis(redis, kind, key)
- json_item = redis.hget(items_key(kind), key)
- json_item.nil? ? nil : JSON.parse(json_item, symbolize_names: true)
+ Model.deserialize(kind, redis.hget(items_key(kind), key))
end
end
end
end
end