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
Constant Summary collapse
- DEFAULT_EXPIRATION =
24 * 60 * 60
- DEFAULT_NAMESPACE =
"graphql-persisted-query"
Instance Attribute Summary
Attributes inherited from BaseStoreAdapter
Instance Method Summary collapse
- #fetch(hash) ⇒ Object
-
#initialize(redis_client: {}, expiration: nil, namespace: nil) ⇒ RedisStoreAdapter
constructor
A new instance of RedisStoreAdapter.
- #save(hash, query) ⇒ Object
Methods inherited from BaseStoreAdapter
#fetch_query, #save_query, #trace
Constructor Details
#initialize(redis_client: {}, expiration: nil, namespace: nil) ⇒ RedisStoreAdapter
Returns a new instance of RedisStoreAdapter.
13 14 15 16 17 18 |
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 13 def initialize(redis_client: {}, expiration: nil, namespace: nil) @redis_proc = build_redis_proc(redis_client) @expiration = expiration || DEFAULT_EXPIRATION @namespace = namespace || DEFAULT_NAMESPACE @name = :redis end |
Instance Method Details
#fetch(hash) ⇒ Object
20 21 22 |
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 20 def fetch(hash) @redis_proc.call { |redis| redis.get(key_for(hash)) } end |
#save(hash, query) ⇒ Object
24 25 26 |
# File 'lib/graphql/persisted_queries/store_adapters/redis_store_adapter.rb', line 24 def save(hash, query) @redis_proc.call { |redis| redis.set(key_for(hash), query, ex: @expiration) } end |