# Is it possible to store only key and no bins for some records?

**URL:** <https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412>\
**Category:** General Discussion\
**Created:** [July 18, 2017, 8:10am UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412 "2017-07-18T08:10:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debapriya\_Padhy](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Debapriya\_Padhy](https://discuss.aerospike.com/u/Debapriya_Padhy)\
**Post date:** [July 18, 2017, 8:10am UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/1 "2017-07-18T08:10:58Z")

</div>

Currently I am not able to add a record without any bins(3.12 version). Any reasons why this is not supported?

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [July 18, 2017, 3:10pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/2 "2017-07-18T15:10:38Z")

</div>

When all bins are deleted, record is deleted. You have to have at least one bin in a record. If you want, you can store your key in a bin. Aerospike does not store your key - rather a 20 byte hash of the set name (or null) plus your key.

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [July 18, 2017, 3:30pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/3 "2017-07-18T15:30:47Z")

</div>

What would be the point of doing that? Are you asking about a way to do ‘set membership’ - not ‘set’ as it’s used in Aerospike (a schema-less table) but rather the data type.

---

<div class="post-metadata">

**Author:** ![Debapriya\_Padhy](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Debapriya\_Padhy](https://discuss.aerospike.com/u/Debapriya_Padhy)\
**Post date:** [July 18, 2017, 3:41pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/4 "2017-07-18T15:41:18Z")

</div>

@rbotzerSomething similar. Basically have a use case where we store identifiers as a persistent cache with the only query on them being exists. So, I was thinking of storing the key only.

Other approaches I thought of is duplicating the key as a default bin / storing a single record like a large list. But then I don’t think there is ‘contains’ query available for a list, right?

---

<div class="post-metadata">

**Author:** ![Debapriya\_Padhy](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Debapriya\_Padhy](https://discuss.aerospike.com/u/Debapriya_Padhy)\
**Post date:** [July 18, 2017, 3:46pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/5 "2017-07-18T15:46:22Z")

</div>

@pguptaYes, considered that, but then we are effectively storing double the amount of data correct? (In the hypothetical case that Aerospike would have supported storing only keys without any bins as well).

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [July 18, 2017, 5:08pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/6 "2017-07-18T17:08:00Z")

</div>

The best way to do this in Aerospike is to leverage the [data-in-index](http://www.aerospike.com/docs/operations/configure/namespace/storage) configuration. This is a namespace defined as storing its data in-memory, single-bin, with the additional and important fact of the data being stored in the [primary index](http://www.aerospike.com/docs/architecture/primary-index.html) itself (as long as it’s an numeric value, integer or double).

First, this means that you’re spending no additional RAM for storage - it’s overwriting a portion of the 64B metadata entry that is always allocated per-record. This also means that the operation has a much lower latency, since it doesn’t need to read the value from RAM after the server looks up the record’s metadata in the primary index. So, checking for existence can’t get any faster. It’s also a great configuration for counters, since increment operations happen in-place. Lastly, because Enterprise Edition stores the primary index in shared memory, a data-in-index namespace will take advantage of [fast restart](http://www.aerospike.com/docs/operations/manage/aerospike/fast_start) (its data isn’t in the process memory).

For your use case you’d create the record with the given key and assign it the integer value 1. You can then use the _[exists](http://www.aerospike.com/apidocs/java/com/aerospike/client/AerospikeClient.html#exists(com.aerospike.client.policy.Policy,%20com.aerospike.client.Key))_ method of your client to check for existence. This approach works for things like blacklists, where you also associate a TTL for the record, with the blacklisting holding until the record expires.

---

<div class="post-metadata">

**Author:** ![Debapriya\_Padhy](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Debapriya\_Padhy](https://discuss.aerospike.com/u/Debapriya_Padhy)\
**Post date:** [July 19, 2017, 6:11am UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/7 "2017-07-19T06:11:09Z")

</div>

@rbotzer Thanks for explaining. This looks like a good approach for the use case. One more question, AFAIK from aerospike docs, data in index works only at a namespace level. Is it possible to make it work at a set level by any chance? Basically asking if we can have some sets in the namespace with actual data and some with only data in index (cause i read, data in memory needs to be true for data in index).

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [July 19, 2017, 8:10am UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/8 "2017-07-19T08:10:30Z")

</div>

With release 3.13 and 3.14 you can add a namespace through rolling upgrade, so it’s not as painful to add one that is data-in-index. It’s not configurable for the set level.

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [July 19, 2017, 6:17pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/9 "2017-07-19T18:17:27Z")

</div>

You can have up to 32 namespaces - so segregate out by namespace if needed.

---

<div class="post-metadata">

**Author:** ![rbotzer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/rbotzer/32/2114_2.png) [@rbotzer](https://discuss.aerospike.com/u/rbotzer)\
**Post date:** [July 19, 2017, 7:05pm UTC](https://discuss.aerospike.com/t/is-it-possible-to-store-only-key-and-no-bins-for-some-records/4412/10 "2017-07-19T19:05:35Z")

</div>

As Piyush pointed out, there’s a limit there, so no need to have many namespaces that are data-in-index. You can set one up, then have multiple sets for ‘set membership’ checks (up to 1023 of those per-namespace).
