src/foobara/redis_crud_driver.rb in foobara-redis-crud-driver-0.0.2 vs src/foobara/redis_crud_driver.rb in foobara-redis-crud-driver-0.0.3
- old
+ new
@@ -36,26 +36,10 @@
when nil
self.class.redis
end
end
- # We don't make use of Redis transaction feature here because they are do not really work
- # like database transactions which is what this feature is based on. We might want to use database transactions
- # in some sort of flush feature though.
- def open_transaction
- # Should we have some kind of fake transaction object that raises errors when used after rolledback/closed?
- Object.new
- end
-
- def close_transaction(_raw_tx)
- end
-
- def rollback_transaction(_raw_tx)
- # nothing to do... except maybe enter a state where we don't flush anything else
- # but can just rely on higher-up plumbing for that
- end
-
class Table < Persistence::EntityAttributesCrudDriver::Table
def initialize(...)
super
unless entity_class.primary_key_type.type_symbol == :integer
@@ -65,34 +49,14 @@
raise "Only integer primary keys are supported for now"
# :nocov:
end
end
- def prefix
- crud_driver.prefix
- end
-
def get_id
redis.incr(sequence_key)
end
- def sequence_key
- @sequence_key ||= "#{entity_key_prefix}$sequence"
- end
-
- def primary_keys_index_key
- @primary_keys_index_key ||= "#{entity_key_prefix}$all"
- end
-
- def entity_key_prefix
- @entity_key_prefix ||= [*prefix, table_name].join(":")
- end
-
- def record_key_prefix(record_id)
- "#{entity_key_prefix}:#{record_id}"
- end
-
def all
Enumerator.new do |yielder|
batches_of_primary_keys.each do |batch|
raw_records = redis.pipelined do |p|
batch.each do |record_id|
@@ -195,9 +159,29 @@
end
end
end
private
+
+ def prefix
+ crud_driver.prefix
+ end
+
+ def sequence_key
+ @sequence_key ||= "#{entity_key_prefix}$sequence"
+ end
+
+ def primary_keys_index_key
+ @primary_keys_index_key ||= "#{entity_key_prefix}$all"
+ end
+
+ def entity_key_prefix
+ @entity_key_prefix ||= [*prefix, table_name].join(":")
+ end
+
+ def record_key_prefix(record_id)
+ "#{entity_key_prefix}:#{record_id}"
+ end
def redis
raw_connection
end