-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
Description
~ $ node -v
v10.1.0
~ $ redis-server --version
Redis server v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=687a2a319020fa42
~ $ lsb_release -a
LSB Version: core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:printing-9.20160110ubuntu0.2-amd64:printing-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
Trying to get my head around the redis transaction stuff in order to support atomic events on small (json) objects (ratoms) using watch/multi. The initial code is working but client.quit() doesn't clean up any more:
const newRAtom = (ratom) => {
const key = getRAtomKey(ratom);
return new Promise((resolve, reject) => {
const transaction = client.multi();
transaction.watch(key);
client.get(key, (err, value) => {
if (err) reject(err);
if (value) reject(key + ' already exists');
else {
transaction.set(key, stringify(ratom));
transaction.exec((err) => {
if (err) reject(err);
else resolve(ratom)})}})})};
My theory is that the transaction (multi) ensures that other processes can't create a matching ratom in redis. This works in testing but once the above function has been used client.quit() fails to clean up the client so the javascript tests fail to terminate until -c is used to force an exit. This happens when the newRAtom promise resolves so transaction.exec has been called (and redis monitor shows the expected updates).