Class: Bricolage::RedisRowWriter
- Inherits:
-
Object
- Object
- Bricolage::RedisRowWriter
show all
- Defined in:
- lib/bricolage/redisdatasource.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, prefix, key_columns) ⇒ RedisRowWriter
Returns a new instance of RedisRowWriter.
100
101
102
103
104
|
# File 'lib/bricolage/redisdatasource.rb', line 100
def initialize(client, prefix, key_columns)
@client = client
@prefix = prefix
@key_columns = key_columns
end
|
Instance Attribute Details
#prefix ⇒ Object
Returns the value of attribute prefix.
106
107
108
|
# File 'lib/bricolage/redisdatasource.rb', line 106
def prefix
@prefix
end
|
#write_count ⇒ Object
Returns the value of attribute write_count.
107
108
109
|
# File 'lib/bricolage/redisdatasource.rb', line 107
def write_count
@write_count
end
|
Class Method Details
.for_encode(encode) ⇒ Object
Instance Method Details
#expire ⇒ Object
132
133
134
|
# File 'lib/bricolage/redisdatasource.rb', line 132
def expire
@client.expire(key, @expire)
end
|
#key(row) ⇒ Object
109
110
111
|
# File 'lib/bricolage/redisdatasource.rb', line 109
def key(row)
@prefix + @key_columns.map {|k| row[k] }.join('_')
end
|
#pipelined(&block) ⇒ Object
121
122
123
|
# File 'lib/bricolage/redisdatasource.rb', line 121
def pipelined(&block)
@client.pipelined(&block)
end
|
#value_columns(row) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/bricolage/redisdatasource.rb', line 113
def value_columns(row)
r = row.dup
@key_columns.each do |key|
r.delete(key)
end
r.empty? ? {1 => 1} : r
end
|
#write(row) ⇒ Object
125
126
127
128
129
130
|
# File 'lib/bricolage/redisdatasource.rb', line 125
def write(row)
key = key(row)
futures = do_write(key, value_columns(row))
futures.push @client.expire(key, @expire) if @expire
futures
end
|