Mass Insertion

35 views
Skip to first unread message

Virendra Negi

unread,
Apr 30, 2012, 2:23:33 AM4/30/12
to Ohm Ruby
Is there a command to mass-insert a record in ohm for redis just like
mongo-id for mongo-db



cyx

unread,
May 26, 2012, 12:22:24 AM5/26/12
to Ohm Ruby
Hi,

Unfortunately there is none. It's not impossible though.

One approach would be to use a different redis connection for the ID
incrementing
and a different redis connection for doing an HMSET.

arr = [ { title: "Foo 1" }, { title: "Foo 2" } ]

r1 = Redis.connect
r2 = Redis.connect

r2.pipelined do
arr.each do |dict|
id = r1.incr "Post:id"

r2.hmset("Post:#{id}", *dict.flatten)
end
end

Something like that.

On Apr 30, 2:23 pm, Virendra Negi <viren...@idyllic-software.com>
wrote:
Reply all
Reply to author
Forward
0 new messages