Module: Familia::DataType::DatabaseCommands
- Included in:
- Familia::DataType
- Defined in:
- lib/familia/data_type/database_commands.rb
Overview
Must be included in all DataType classes to provide Valkey/Redis commands. The class must have a dbkey method.
Instance Method Summary collapse
- #current_expiration ⇒ Object
-
#delete! ⇒ Object
(also: #clear)
Deletes the entire dbkey.
- #echo(*args) ⇒ Object
- #exists? ⇒ Boolean
- #expire(sec) ⇒ Object
- #expireat(unixtime) ⇒ Object
- #move(logical_database) ⇒ Object
- #persist ⇒ Object
- #rename(newkey) ⇒ Object
- #renamenx(newkey) ⇒ Object
- #type ⇒ Object
Instance Method Details
#current_expiration ⇒ Object
40 41 42 |
# File 'lib/familia/data_type/database_commands.rb', line 40 def current_expiration dbclient.ttl dbkey end |
#delete! ⇒ Object Also known as: clear
Deletes the entire dbkey
We return the dbclient.del command's return value instead of a friendly boolean b/c that logic doesn't work inside of a transaction. The return value in that case is a Redis::Future which based on the name indicates that the commend hasn't even run yet.
30 31 32 33 |
# File 'lib/familia/data_type/database_commands.rb', line 30 def delete! Familia.trace :DELETE!, nil, self.class.uri if Familia.debug? dbclient.del dbkey end |
#echo(*args) ⇒ Object
56 57 58 |
# File 'lib/familia/data_type/database_commands.rb', line 56 def echo(*args) dbclient.echo "[#{self.class}] #{args.join(' ')} (#{opts&.fetch(:class, '<no opts>')})" end |
#exists? ⇒ Boolean
36 37 38 |
# File 'lib/familia/data_type/database_commands.rb', line 36 def exists? dbclient.exists(dbkey) && !size.zero? end |
#expire(sec) ⇒ Object
44 45 46 |
# File 'lib/familia/data_type/database_commands.rb', line 44 def expire(sec) dbclient.expire dbkey, sec.to_i end |
#expireat(unixtime) ⇒ Object
48 49 50 |
# File 'lib/familia/data_type/database_commands.rb', line 48 def expireat(unixtime) dbclient.expireat dbkey, unixtime end |
#move(logical_database) ⇒ Object
8 9 10 |
# File 'lib/familia/data_type/database_commands.rb', line 8 def move(logical_database) dbclient.move dbkey, logical_database end |
#persist ⇒ Object
52 53 54 |
# File 'lib/familia/data_type/database_commands.rb', line 52 def persist dbclient.persist dbkey end |
#rename(newkey) ⇒ Object
12 13 14 |
# File 'lib/familia/data_type/database_commands.rb', line 12 def rename(newkey) dbclient.rename dbkey, newkey end |
#renamenx(newkey) ⇒ Object
16 17 18 |
# File 'lib/familia/data_type/database_commands.rb', line 16 def renamenx(newkey) dbclient.renamenx dbkey, newkey end |
#type ⇒ Object
20 21 22 |
# File 'lib/familia/data_type/database_commands.rb', line 20 def type dbclient.type dbkey end |