Skip to content
Discussion options

You must be logged in to vote

As @yatsukhnenko posted it's when you are in a transaction (either MULTI, PIPELINE, or both). This allows you to chain commands

$redis = new Redis;
$redis->connect('localhost', 6379);

$redis->multi()               // Returns Redis ($this)
    ->set('user:id', 1)       // Returns Redis ($this)
    ->set('user:name', 'Bob') // Returns Redis ($this)
    ->exec();                 // Returns array of results: [true, true]

And on the server:

1778176160.762464 [0 [::1]:45330] "MULTI"
1778176160.762775 [0 [::1]:45330] "SET" "user:id" "1"
1778176160.762789 [0 [::1]:45330] "SET" "user:name" "Bob"
1778176160.762790 [0 [::1]:45330] "EXEC"

We only ever semantically return $this never an unrelated Redis

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@michael-grunder
Comment options

Answer selected by hackel
@hackel
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants