# Single-record commands

Aerospike provides simple interfaces for reading data from and writing data to an Aerospike cluster. They cover the standard CRUD (create, read, update, delete) use cases.

Every Aerospike client can perform the following per-bin operations, no matter which language it’s written in:

| Command | Description |
| --- | --- |
| `put` | Write a record. Performs the equivalent of `create`, `update` or `replace`, depending on the write policy given to the `write` command. |
| `delete` | Remove a record from the database. Generates a tombstone when using the [_durable-delete_](https://aerospike.com/docs/database/learn/architecture/durable-deletes) policy. |
| `get` | Read the record. Specific bins can be selected. |
| `add` | Add (or subtract) a value in an integer bin. Used to implement counters. Also called `increment`. |
| `append`  
`prepend` | Modify a string or byte array bin. |
| `touch` | Increment the [generation counter](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model/#metadata). |
| `operate` | Executes multiple [bin operations](https://aerospike.com/docs/develop/learn/bin-operations) atomically and in isolation as a single record command. |
|  |  |

### Filtering operations

A command can be conditionally applied, based on the result of a [record filter expression](https://aerospike.com/docs/develop/expressions/#record-filtering-with-expressions). If the filter expression evaluates to true, the operation executes.

::: note
Support for predicate filters was removed in Aerospike 6.0.0. We recommend using filter expressions instead.
:::

## Code examples of record operations

The following examples use Python to perform create, read, update, and delete (CRUD) operations on a record. The syntax differs per Aerospike client, based on the needs of the operating system. These examples model common usage:

-   [Java](#tab-panel-703)
-   [Python](#tab-panel-704)

### Create a record

```java
String sighting = "{\"sighting\":{\"occurred\":20200912,\"reported\":20200916,\"posted\":20201105,\"report\":{\"city\":\"Kirkland\",\"duration\":\"~30 minutes\",\"shape\":[\"circle\"],\"state\":\"WA\",\"summary\":\"4 rotating orange lights in the Kingsgate area above the Safeway. Around 9pm the power went out in the Kingsgate area.  Four lights were spotted rotating above the local Safeway and surrounding streets.  They were rotating fast but staying relatively in the same spots.  Also described as orange lights. About thirty minutes later they disappeared.  The second they disappeared the power was restored.  Later a station of police from Woodinville and Kirkland came to guard the street where it happened.  They wouldn't let anyone go past the street, putting out search lights and flare signals so people couldn't drive past Safeway.  The police also would not let people walk past to go home.\"},\"location\":\"\\\"{\\\"type\\\":\\\"Point\\\",\\\"coordinates\\\":[-122.1966441,47.69328259]}\\\"\"}}";

// Convert string to Java Map

Map<String, Map<String, Object>> sightingMap = new Gson().fromJson(sighting, new TypeToken<HashMap<String, HashMap<String, Object>>>(){}.getType());

// Create bins from map

Bin[] bins = {

    new Bin("occured", Value.get(sightingMap.get("sighting").get("occurred"))),

    new Bin("reported", Value.get(sightingMap.get("sighting").get("reported"))),

    new Bin("posted", Value.get(sightingMap.get("sighting").get("posted"))),

    new Bin("report", Value.get(sightingMap.get("sighting").get("report"))),

};

// Write recored

WritePolicy policy = client.copyWritePolicyDefault();

client.put(policy, key, bins);
```

### Read a record

```java
// Reading reacord using with key and null policy. If no policy is provided

// default policy will be used

Record rec = client.get(null, key);

System.out.println(new Gson().toJson(rec.getValue("report")));
```

### Update record

```java
// Update record

Map<String, Object> updateReportMap = Map.of("city","Seattle", "duration", "~1Hour");

Bin[] updateBins = {

    new Bin("posted", Value.get(20221105)),

    new Bin("report", updateReportMap),

};

// Update policy to record update

policy.recordExistsAction = RecordExistsAction.UPDATE;

// Update record with key

client.put(policy, key, updateBins);
```

### Delete record

```java
// Delete record

client.delete(null, key);
```

### Create a record

```plaintext
key = (namespace_name, set_name, user_key)

bins = {

        'l': [ "qwertyuiop", 1, bytearray("asd;as[d'as;d", "utf-8") ],

        'm': { "key": "asd';q;'1';" },

        'i': 1234,

        'f': 3.14159265359,

        's': '!@#@#$QSDAsd;as'

    }

client.put(key, bins)
```

Arguments:

-   `key`: The primary key of the record to create.
-   `bins`: Bin name and value pairs to insert into the bins upon creation.

### Read a record

```plaintext
client.get(key)
```

Arguments:

-   `key`: The primary key of the record to read.

### Update a record

```plaintext
update_bins = {

            'b'=: u"\ud83d\ude04"

            'i': aerospike.null()

         }

client.put(key, update_bins)
```

Arguments:

-   `key`: The primary key of the record to update.
-   `update_bins`: Bin name and value pairs to upsert into the bins.

Adds a blob bin. Removes the integer bin by overwriting with null.

### Delete a record

```plaintext
client.remove(key)
```

Arguments:

-   `key`: The primary key of the record to delete.

### Usage note for all examples

All full record read and write commands accept [policy](https://aerospike.com/docs/database/learn/policies) parameters: Max Retries and Total Timeout.

Write operations take an optional time-to-live (TTL) parameter that specifies how long to protect a record from automatic eviction by the system. Set the TTL to -1 to tell Aerospike to never evict that data.

## References

See these topics for language-specific examples:

-   [Java](https://aerospike.com/docs/develop/client/java/usage/atomic/create/)
-   [C# .NET](https://aerospike.com/docs/develop/client/csharp/usage/atomic/create/)
-   [Node.js](https://aerospike.com/docs/develop/client/node/usage/atomic/create/)
-   [Go](https://aerospike.com/docs/develop/client/go/usage/atomic/create/)
-   [Python](https://aerospike.com/docs/develop/client/python/usage/atomic/create/)
-   [C](https://aerospike.com/docs/develop/client/c/usage/atomic/create/)
-   [Ruby](https://aerospike.com/docs/develop/client/ruby/usage/atomic/create/)
-   [Rust](https://aerospike.com/docs/develop/client/rust/usage/atomic/create/)