Skip to content

SESSION.CLOSE

Closes the current session and resets all session state while keeping the connection open.

SESSION.CLOSE

This command takes no parameters.

Simple string: OK on success.

The command performs a full session reset without closing the underlying network connection:

  1. Cursors: All active cursors (read, delete, update query contexts) are cleared
  2. FDB Transaction: Any active FoundationDB transaction is rolled back and closed
  3. MULTI State: MULTI transaction state (queued commands, the MULTI flag) is reset
  4. Watched Keys: All keys being watched via WATCH are unwatched
  5. Cursor ID Counter: Reset to 1
  6. Session Defaults: the configuration attributes (reply_type, input_type, batch, object_id_format) are reset to their defaults, snapshot read goes back to off, and the current namespace goes back to the default one

Everything that belongs to the connection rather than the session is kept: the negotiated RESP version, the authentication state, and the client name and library info set with CLIENT SETNAME and CLIENT SETINFO. A client that has already authenticated does not need to send AUTH again after this command.

Argument errors:

Error CodeError messageCause
ERRwrong number of arguments for 'SESSION.CLOSE' command-

Basic usage:

> SESSION.CLOSE
OK

After starting a transaction:

> BEGIN
OK
> SESSION.CLOSE
OK
> ROLLBACK
(error) TRANSACTION there is no transaction in progress.

The transaction is rolled back; no explicit ROLLBACK is needed.

Resetting modified session attributes:

> SESSION.ATTRIBUTE SET batch 50
OK
> SESSION.CLOSE
OK
> SESSION.ATTRIBUTE LIST
1# reply_type => bson
2# input_type => bson
3# batch => (integer) 100
4# object_id_format => bytes

The batch attribute is reset to its default value (100).

Resetting snapshot read:

> SNAPSHOTREAD ON
OK
> SESSION.CLOSE
OK

Reads are serializable again. The next transaction on this connection does not inherit snapshot isolation.

Resetting the current namespace:

> NAMESPACE USE global.staging
OK
> SESSION.CLOSE
OK
> NAMESPACE CURRENT
global