Class: AnyCache::Adapters::RedisStore Private

Inherits:
Redis
  • Object
show all
Defined in:
lib/any_cache/adapters/redis_store.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Constant Summary

Constants inherited from Redis

AnyCache::Adapters::Redis::DEAD_TTL, AnyCache::Adapters::Redis::DEFAULT_INCR_DECR_AMOUNT, AnyCache::Adapters::Redis::DELETE_MATCHED_BATCH_SIZE, AnyCache::Adapters::Redis::DELETE_MATCHED_CURSOR_START, AnyCache::Adapters::Redis::NO_EXPIRATION_TTL

Instance Attribute Summary

Attributes inherited from Basic

#driver

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Redis

#cleanup, #clear, #decrement, #delete, #delete_matched, #exist?, #expire, #fetch, #fetch_multi, #increment, #persist

Methods inherited from Basic

#cleanup, #clear, #decrement, #delete, #delete_matched, #exist?, #expire, #fetch, #fetch_multi, #increment, #initialize, #persist

Methods included from Dumper::InterfaceAccessMixin

#detransform_pairset, #detransform_value, #transform_pairset, #transform_value

Constructor Details

This class inherits a constructor from AnyCache::Adapters::Basic

Class Method Details

.supported_driver?(driver) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • driver (Object)

Returns:

  • (Boolean)

Since:

  • 0.1.0



13
14
15
# File 'lib/any_cache/adapters/redis_store.rb', line 13

def supported_driver?(driver)
  AnyCache::Drivers::RedisStore.supported_source?(driver)
end

Instance Method Details

#read(key, **options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)
  • raw (Hash)

    a customizable set of options

Returns:

  • (Object)

Since:

  • 0.1.0



26
27
28
29
30
31
# File 'lib/any_cache/adapters/redis_store.rb', line 26

def read(key, **options)
  raw = options.fetch(:raw, false)
  value = get(key, raw: true)

  raw ? value : detransform_value(value)
end

#read_multi(*keys, **options) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • keys (Array<String>)
  • options (Hash)

Returns:

  • (Hash)

Since:

  • 0.3.0



39
40
41
42
# File 'lib/any_cache/adapters/redis_store.rb', line 39

def read_multi(*keys, **options)
  # NOTE: cant use Redis::Store#mget cuz it has some marshalling errors :(
  Hash[keys.zip(keys.map { |key| read(key, **options) })]
end

#write(key, value, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • key (String)
  • value (Object)
  • expires_in (Hash)

    a customizable set of options

  • raw (Hash)

    a customizable set of options

Since:

  • 0.1.0



52
53
54
55
56
57
58
# File 'lib/any_cache/adapters/redis_store.rb', line 52

def write(key, value, **options)
  expires_in = options.fetch(:expires_in, NO_EXPIRATION_TTL)
  raw = options.fetch(:raw, false)
  value = transform_value(value) unless raw

  expires_in ? setex(key, expires_in, value, raw: true) : set(key, value, raw: true)
end

#write_multi(entries, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • entries (Hash)
  • raw (Hash)

    a customizable set of options

Since:

  • 0.3.0



66
67
68
69
70
71
# File 'lib/any_cache/adapters/redis_store.rb', line 66

def write_multi(entries, **options)
  raw = options.fetch(:raw, false)
  entries = transform_pairset(entries) unless raw

  mset(*entries.to_a.flatten!, raw: true)
end