Predis\Client::transaction PHP Method

transaction() public method

Creates a new transaction context and returns it, or returns the results of a transaction executed inside the optionally provided callable object.
public transaction ( ) : MultiExec | array
return Predis\Transaction\MultiExec | array
    public function transaction()
    {
        return $this->sharedContextFactory('createTransaction', func_get_args());
    }

Usage Example

Example #1
0
 /**
  * @param User $user
  */
 public function remove(User $user)
 {
     $this->redisClient->transaction(function (MultiExec $tx) use($user) {
         $id = $user->getId();
         $tx->hdel(self::USER_HASH_STORE, $id);
         if (!empty($user->getGithubId())) {
             $tx->hdel('github_' . self::USER_HASH_STORE, $user->getGithubId());
         }
         if (!empty($user->getGoogleId())) {
             $tx->hdel('google_' . self::USER_HASH_STORE, $user->getGoogleId());
         }
         if (!empty($user->getBitbucketId())) {
             $tx->hdel('bitbucket_' . self::USER_HASH_STORE, $user->getBitbucketId());
         }
     });
 }
All Usage Examples Of Predis\Client::transaction