# Redis introduces the BITFIELD command for arbitrary-sized integers at bit offsets

DevFeed: [Redis introduces the BITFIELD command for arbitrary-sized integers at bit offsets](<https://devfeed.tech/articles/100-more-of-those-bitfields-20594.md>)

Original publisher: [Read original article](<http://antirez.com/news/103>)

Published: 2016-02-26T15:02:54Z

Content type: release

Language: en

Sources: [Antirez](<https://devfeed.tech/sources/antirez.md>)

Topics: [Redis](<https://devfeed.tech/topics/redis.md>), [coding](<https://devfeed.tech/topics/coding.md>)

Tags: [coding](<https://devfeed.tech/tags/coding.md>), [commands](<https://devfeed.tech/tags/commands.md>), [redis](<https://devfeed.tech/tags/redis.md>), [release](<https://devfeed.tech/tags/release.md>)

## AI overview

The article describes the implementation of Redis's BITFIELD command, which stores arbitrary-sized integers at arbitrary bit offsets. It introduces SET, GET, and INCRBY subcommands, along with configurable overflow semantics.

## Source excerpt

Today Redis is 7 years old, so to commemorate the event a bit I passed the latest couple of days doing a fun coding marathon to implement a new crazy command called BITFIELD. The essence of this command is not new, it was proposed in the past by me and others, but never in a serious way, the idea always looked a bit strange. We already have bit operations in Redis: certain users love it, it's a good way to represent a lot of data in a compact way. However so far we handle each bit separately, setting, testing, getting bits, counting all the bits that are set in a range, and so forth. What about implementing bitfields? Short or large, arbitrary sized integers, at arbitrary offsets, so that I can use a Redis string as an array of 5 bits signed integers, without losing a single bit of juice. A few days ago, Yoav Steinberg from Redis Labs, proposed a set of commands on arbitrary sized integers stored at bit offsets in a more serious way. I smiled when I read the email, since this was kinda of a secret dream. Starting from Yoav proposal and with other feedbacks from Redis Labs engineers, I wrote an initial specification of a single command with sub-commands, using short names for types definitions, and adding very fine grained control on the overflow semantics. I finished the first implementation a few minutes ago, since the plan was to release it for today, in the hope Redis appreciates we do actual work in its bday. The resulting BITFIELD command supports different subcommands: SET -- Set the specified value and return its previous value. GET -- Get the specified value. INCRBY -- Increment the specified counter. There is an additional meta command called OVERFLOW, used to set (guess what) the overflow semantics of the commands that will follow (so OVERFLOW can be specified multiple times): OVERFLOW SAT -- Saturation, so that overflowing in one direction or the other, will saturate the integer to its maximum value in the direction of the overflow. OVERFLOW WRAP -- This is us