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
42 43 44 |
# File 'lib/familia/data_type/database_commands.rb', line 42 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.
32 33 34 35 |
# File 'lib/familia/data_type/database_commands.rb', line 32 def delete! Familia.trace :DELETE!, nil, self.class.uri if Familia.debug? dbclient.del dbkey end |
#echo(*args) ⇒ Object
58 59 60 |
# File 'lib/familia/data_type/database_commands.rb', line 58 def echo(*args) dbclient.echo "[#{self.class}] #{args.join(' ')} (#{opts&.fetch(:class, '<no opts>')})" end |
#exists? ⇒ Boolean
38 39 40 |
# File 'lib/familia/data_type/database_commands.rb', line 38 def exists? dbclient.exists(dbkey) && !size.zero? end |
#expire(sec) ⇒ Object
46 47 48 |
# File 'lib/familia/data_type/database_commands.rb', line 46 def expire(sec) dbclient.expire dbkey, sec.to_i end |
#expireat(unixtime) ⇒ Object
50 51 52 |
# File 'lib/familia/data_type/database_commands.rb', line 50 def expireat(unixtime) dbclient.expireat dbkey, unixtime end |
#move(logical_database) ⇒ Object
10 11 12 |
# File 'lib/familia/data_type/database_commands.rb', line 10 def move(logical_database) dbclient.move dbkey, logical_database end |
#persist ⇒ Object
54 55 56 |
# File 'lib/familia/data_type/database_commands.rb', line 54 def persist dbclient.persist dbkey end |
#rename(newkey) ⇒ Object
14 15 16 |
# File 'lib/familia/data_type/database_commands.rb', line 14 def rename(newkey) dbclient.rename dbkey, newkey end |
#renamenx(newkey) ⇒ Object
18 19 20 |
# File 'lib/familia/data_type/database_commands.rb', line 18 def renamenx(newkey) dbclient.renamenx dbkey, newkey end |
#type ⇒ Object
22 23 24 |
# File 'lib/familia/data_type/database_commands.rb', line 22 def type dbclient.type dbkey end |