Class: GraphQL::PersistedQueries::StoreAdapters::RedisStoreAdapter

Inherits:
BaseStoreAdapter
  • Object
show all
Defined in:
lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb

Overview

Redis adapter for storing persisted queries

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, **options) ⇒ RedisStoreAdapter

Returns a new instance of RedisStoreAdapter.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 10

def initialize(client: nil, **options)
  require "redis"

  if client && options.any?
    raise ArgumentError, "client cannot be passed along with redis_url, redis_host" \
                         ", redis_port or redis_db_name options"
  end

  @storage = client || configure_redis_client(options)
rescue LoadError => e
  msg = "Could not load the 'redis' gem, please add it to your gemfile or " \
        "configure a different adapter, e.g. use GraphQL::PersistedQueries, store: :memory"
  raise e.class, msg, e.backtrace
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



8
9
10
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 8

def storage
  @storage
end

Instance Method Details

#fetch_query(hash) ⇒ Object



25
26
27
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 25

def fetch_query(hash)
  storage.get(key_for(hash))
end

#save_query(hash, query) ⇒ Object



29
30
31
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 29

def save_query(hash, query)
  storage.set(key_for(hash), query)
end