Class: GraphQL::PersistedQueries::StoreAdapters::RedisStoreAdapter
- Inherits:
-
BaseStoreAdapter
- Object
- BaseStoreAdapter
- GraphQL::PersistedQueries::StoreAdapters::RedisStoreAdapter
- Defined in:
- lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb
Overview
Redis adapter for storing persisted queries
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #fetch_query(hash) ⇒ Object
-
#initialize(client: nil, **options) ⇒ RedisStoreAdapter
constructor
A new instance of RedisStoreAdapter.
- #save_query(hash, query) ⇒ Object
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, **) require "redis" if client && .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() 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
#storage ⇒ Object (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 |