Easy Tutorial
❮ Android Tutorial Sqlite 2 Android Tutorial Canvas Api2 ❯

7.0 Basic Commands for Zookeeper Client

Category Zookeeper Tutorial

The zookeeper command is used to perform operations on the zookeeper service.

First, execute the command to open a new session and enter the terminal.

$ sh zkCli.sh

We will now begin explaining the basic commonly used commands, with detailed discussion of ACL permissions in later chapters.

ls Command

The ls command is used to view the list of directories at a certain path.

Format:

ls path

-path: Represents the path.

$ ls /tutorialpro

ls2 Command

The ls2 command is used to view the list of directories at a certain path, providing more detailed information than the ls command.

Format:

ls2 path

-path: Represents the path.

$ ls2 /tutorialpro

get Command

The get command is used to retrieve node data and status information.

Format:

get path [watch]

-path: Represents the path.

-[watch]: Event listening on the node.

The following example shows two terminals being opened simultaneously.

Terminal one:

$ get /tutorialpro watch

In Terminal two, modify this node:

$ set /tutorialpro 1

Terminal one automatically displays the NodeDataChanged event:

stat Command

The stat command is used to view the status information of a node.

Format:

stat path [watch]

-path: Represents the path.

-[watch]: Event listening on the node.

The following example checks the status of the /tutorialpro node:

$ stat /tutorialpro

create Command

The create command is used to create a node and assign a value.

Format:

create [-s] [-e] path data acl

-[-s] [-e]: -s and -e are both optional, -s represents a sequential node, -e represents an ephemeral node, note that -s and -e can be used simultaneously, and ephemeral nodes cannot create child nodes.

-path: Specifies the path where the node is to be created, such as /tutorialpro.

-data: The data to be stored in this node.

-acl: Access control, the default is world, which means everyone can access.

The following example adds an ephemeral sequential node:

$ create -s -e /tutorialpro 0

The created node is both sequential and ephemeral.

set Command

The set command is used to modify the data stored in a node.

Format:

set path data [version]

-path: Node path.

-data: The data to be stored.

-[version]: Optional, version number (can be used as an optimistic lock).

The following example opens two terminals, or the same terminal can be operated:

$ get /tutorialpro

The following diagram shows that only the correct version number can be set successfully:

$ set /tutorialpro 0 1
$ set /tutorialpro 0 2
$ set /tutorialpro 0 10
$ set /tutorialpro 0 6

delete Command

The delete command is used to delete a certain node.

Format:

delete path [version]

-path: Node path.

-[version]: Optional, version number (same as the set command).

The following example deletes the child node of /tutorialpro:

$ ls /tutorialpro
$ delete /tutorialpro/child
$ get /tutorialpro/child

-1.0 Zookeeper Tutorial

-2.0 Zookeeper Installation and Configuration

-3.0 Zookeeper Linux Server Cluster Setup Steps

-4.0 Zookeeper Java Client Setup

-5.0 Zookeeper Data Model znode Structure Detailed Explanation

-6.0 Zookeeper Session Basic Principles

-8.0 Zookeeper Four-Letter Words

-9.0 Zookeeper Node Features

-10.0 Zookeeper Access Control ACL

-11.0 Zookeeper Watcher Event Mechanism Principle Analysis

-[

❮ Android Tutorial Sqlite 2 Android Tutorial Canvas Api2 ❯