Class: Shrine::Storage::RedisStorage
- Inherits:
-
Object
- Object
- Shrine::Storage::RedisStorage
- Defined in:
- lib/shrine/storage/redis_storage.rb
Instance Attribute Summary collapse
-
#expire ⇒ Object
readonly
Returns the value of attribute expire.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #exists?(id) ⇒ Boolean
-
#initialize(redis, prefix:, expire:) ⇒ RedisStorage
constructor
A new instance of RedisStorage.
- #open(id) ⇒ Object
- #upload(io, id, shrine_metadata: {}, **upload_options) ⇒ Object
- #url(id, **options) ⇒ Object
Constructor Details
#initialize(redis, prefix:, expire:) ⇒ RedisStorage
Returns a new instance of RedisStorage.
11 12 13 14 15 16 |
# File 'lib/shrine/storage/redis_storage.rb', line 11 def initialize(redis, prefix:, expire:) @redis = redis @prefix = prefix @expire = expire raise ArgumentError, 'Missing redis client' unless redis && redis.is_a?(Redis) end |
Instance Attribute Details
#expire ⇒ Object (readonly)
Returns the value of attribute expire.
9 10 11 |
# File 'lib/shrine/storage/redis_storage.rb', line 9 def expire @expire end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/shrine/storage/redis_storage.rb', line 9 def prefix @prefix end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
9 10 11 |
# File 'lib/shrine/storage/redis_storage.rb', line 9 def redis @redis end |
Instance Method Details
#delete(id) ⇒ Object
38 39 40 |
# File 'lib/shrine/storage/redis_storage.rb', line 38 def delete(id) redis.del(key(id)) end |
#exists?(id) ⇒ Boolean
34 35 36 |
# File 'lib/shrine/storage/redis_storage.rb', line 34 def exists?(id) redis.exists(key(id)) end |
#open(id) ⇒ Object
29 30 31 32 |
# File 'lib/shrine/storage/redis_storage.rb', line 29 def open(id) redis.expire(key(id), expire) if expire StringIO.new(content(id)) end |
#upload(io, id, shrine_metadata: {}, **upload_options) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/shrine/storage/redis_storage.rb', line 18 def upload(io, id, shrine_metadata: {}, **) if expire redis.setex(key(id), expire, io.read) else redis.set(key(id), io.read) end end |
#url(id, **options) ⇒ Object
26 27 |
# File 'lib/shrine/storage/redis_storage.rb', line 26 def url(id, **) end |