Question: I want to do this as a transaction because this key will serve as a "lock" for later actions. What if this happens:

1. Check it exists
2. Establish it doesn't exist
3. Someone else checks it exists whilst I am establishing it doesn't exist
4. Set it because it doesn't exist and then do my actions
5. Second person sets it at the same time and does actions when they shouldn't be allowed to.

Answer: 
Well, if you wanted to know about the nature of redis transactions:
<http://redis.io/topics/transactions>

In particular, this part: 

> 
> "All the commands in a transaction are serialized and executed
>  sequentially. It can never happen that a request issued by another
>  client is served in the middle of the execution of a Redis
>  transaction. This guarantees that the commands are executed as a
>  single isolated operation."
> 
> 
> 

If you want a single command that only adds if not exists, <http://redis.io/commands/setnx> is the link to docs for SETNX which does exactly that.

With transactions, you start by calling MULTI, then send in whatever commands you wish, then call EXEC to commence with the series of commands. This is guaranteed to be atomic, no other command can be executed until the sequence is done.

HTH
Use the `NX` flag of the [SET](http://redis.io/commands/set) command.

As the docs suggests:

> 
> The command `SET resource-name anystring NX EX max-lock-time` is a simple way to implement a locking system with Redis.
> 
> 
>