Message from discussion
No locking the data down during the transaction?
Received: by 10.68.132.162 with SMTP id ov2mr2387448pbb.0.1350198180068;
Sun, 14 Oct 2012 00:03:00 -0700 (PDT)
X-BeenThere: redis-db@googlegroups.com
Received: by 10.68.226.100 with SMTP id rr4ls14980309pbc.2.gmail; Sun, 14 Oct
2012 00:02:55 -0700 (PDT)
Received: by 10.66.80.98 with SMTP id q2mr2265288pax.33.1350198175413;
Sun, 14 Oct 2012 00:02:55 -0700 (PDT)
Received: by 10.66.80.98 with SMTP id q2mr2265287pax.33.1350198175403;
Sun, 14 Oct 2012 00:02:55 -0700 (PDT)
Return-Path: <josiah.carl...@gmail.com>
Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54])
by gmr-mx.google.com with ESMTPS id pw7si122041pbb.0.2012.10.14.00.02.55
(version=TLSv1/SSLv3 cipher=OTHER);
Sun, 14 Oct 2012 00:02:55 -0700 (PDT)
Received-SPF: pass (google.com: domain of josiah.carl...@gmail.com designates 209.85.220.54 as permitted sender) client-ip=209.85.220.54;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of josiah.carl...@gmail.com designates 209.85.220.54 as permitted sender) smtp.mail=josiah.carl...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-pa0-f54.google.com with SMTP id bi1so3788069pad.41
for <redis-db@googlegroups.com>; Sun, 14 Oct 2012 00:02:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type;
bh=adJcHZx0St5cUCvwuj1+duHEGGWJogX3GwcX3Q8daEs=;
b=x1g4+pi0vX+/n35KkAybnokIyTBXgOfFAU42KuTRQPwCo869BSumx18yJbGftI340l
F0vBx8JJDXZtj4wihGxXgWCUNbd/3B1LmUT8A/0+quC/25ln674Xo7zNT/NVcLq24ZRR
VHh++k8Ps0C3Piyw1IjM0KjqfPpz+/KahQCZ+UzkNfH/eMmCLnL8TmqopPCXgDYG2PBO
B4AAJhnkuwVzZbACmJxoJPapUY3SG7oaOUgmwAyrJXjslvCV7wcEmRzogdpWCG93RWm5
p6QYG/wzs8Ccu0g5asERAgvsPyBPzJQkGV6V6SZ1KDYv7QL0flUZ2FojK6BIt8GlzwLe
QCjg==
MIME-Version: 1.0
Received: by 10.68.116.228 with SMTP id jz4mr26268881pbb.166.1350198175194;
Sun, 14 Oct 2012 00:02:55 -0700 (PDT)
Received: by 10.68.83.167 with HTTP; Sun, 14 Oct 2012 00:02:55 -0700 (PDT)
In-Reply-To: <CA+m_8J1vTkqKzOrKX4H1yqd453XTw=JWG9i=JQ+8Zdc04t8...@mail.gmail.com>
References: <CA+m_8J3TWTqk5T=hTMFH3mTUzaWhXFawguBSXcfnHKk5WK_...@mail.gmail.com>
<ffdfc44f-b27a-45e9-8946-ff98b437da29@googlegroups.com>
<CA+m_8J27HrXZZB4ubCMn7_cVn6wmUKkmTZBhwJ5=9HWdGtD...@mail.gmail.com>
<CADcB0yjw41XaGUzL-cAZYVUJntDCi3sbFtRz4ZoHD8DHH-h...@mail.gmail.com>
<CA+m_8J1vTkqKzOrKX4H1yqd453XTw=JWG9i=JQ+8Zdc04t8...@mail.gmail.com>
Date: Sun, 14 Oct 2012 00:02:55 -0700
Message-ID: <CADcB0yhzc73sfXjqHUD+tdxTYSS_jpF4uCAGJ=co1O-pUsB...@mail.gmail.com>
Subject: Re: No locking the data down during the transaction?
From: Josiah Carlson <josiah.carl...@gmail.com>
To: redis-db@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Oct 13, 2012 at 1:32 AM, Felix E. Klee <felix.k...@inka.de> wrote:
> On Sat, Oct 13, 2012 at 5:14 AM, Josiah Carlson
> <josiah.carl...@gmail.com> wrote:
>> Note that Node doesn't support WATCH/MULTI/EXEC transactions.
>
> What? As far as I understand the node_redis module, it just forwards
> commands to Redis. From the [node_redis documentation][1]:
>
> "`MULTI` commands are queued up until an `EXEC` is issued, and then all
> commands are run atomically by Redis."
I had a discussion here with a fellow who swore up and down that the
Node Redis client only used a single connection to Redis, so if you
wanted to do a WATCH/.../MULTI/.../EXEC, while you were waiting for
the GET result in a callback, someone else could hop in and run some
other commands on that same connection - which would mess up what you
were doing.
If Node lets you create multiple connections, then I withdraw my claim.
Also note that there is a fundamental difference between MULTI/EXEC.
MULTI/EXEC lets you do an atomic sequence of operations as if they
were 1. But WATCH/MULTI/EXEC lets you do this:
WATCH foo
x = GET foo
if foo < 3:
UNWATCH
return
MULTI
INCR foo
EXEC
You can also do that with Lua, but AFAIK, that sequence of operations
is not possible with the Node Redis libraries (unless you can use
multiple connections).
>> Also note that while there are many things that Lua does support,
>> there are some operations that Lua doesn't support that are possible
>> with WATCH/MULTI/EXEC transactions [...]
>>
>> I can list them out if you'd like.
>
> Just one, please. That could be enlightening.
1. Fetch data from Redis
2. Use the fetched data to fetch other data from a *different* Redis,
local cache, a database, or some other resource
3. When the secondary data has been fetched, combine the two pieces of
data and write back to Redis - failing if some other process has
already done the same
You can think of this as the explicit cache-update scenario. It is
easy with WATCH/MULTI/EXEC or higher-level locks. Not possible with
Lua, as you can't make remote requests (by design). There are a couple
other things that I mention in my book about why something like
WATCH/MULTI/EXEC or locks built on W/M/E or Lua are still necessary
(but that's in chapter 11, which won't be out for another 3 weeks or
so).
> By the way, I am using scripting for very simple and well constrained
> tasks. Example:
I'm glad you figured out how to do this with a single command :)
- Josiah