Skip to content

Commit ab5db30

Browse files
Update bitfields.md (redis#2560)
* Update bitfields.md update bitfields data type page to include hugo short code - condense example and add relevant context * Update bitfields.md to incorporate feedback on PR * Update docs/data-types/bitfields.md Co-authored-by: David Dougherty <david.dougherty@redis.com> --------- Co-authored-by: David Dougherty <david.dougherty@redis.com>
1 parent 00cdad8 commit ab5db30

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

docs/data-types/bitfields.md

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,25 @@ Bitfields support atomic read, write and increment operations, making them a goo
2121

2222
## Examples
2323

24-
Suppose you're keeping track of activity in an online game.
25-
You want to maintain two crucial metrics for each player: the total amount of gold and the number of monsters slain.
26-
Because your game is highly addictive, these counters should be at least 32 bits wide.
24+
## Example
2725

28-
You can represent these counters with one bitfield per player.
26+
Suppose you want to maintain two metrics for various bicycles: the current price and the number of owners over time. You can represent these counters with a 32-bit wide bitfield per for each bike.
2927

30-
* New players start the tutorial with 1000 gold (counter in offset 0).
31-
```
32-
> BITFIELD player:1:stats SET u32 #0 1000
33-
1) (integer) 0
34-
```
28+
* Bike 1 initially costs 1,000 (counter in offset 0) and has never had an owner. After being sold, it's now considered used and the price instantly drops to reflect its new condition, and it now has an owner (offset 1). After quite some time, the bike becomes a classic. The original owner sells it for a profit, so the price goes up and the number of owners does as well.Finally, you can look at the bike's current price and number of owners.
3529

36-
* After killing the goblin holding the prince captive, add the 50 gold earned and increment the "slain" counter (offset 1).
37-
```
38-
> BITFIELD player:1:stats INCRBY u32 #0 50 INCRBY u32 #1 1
39-
1) (integer) 1050
40-
2) (integer) 1
41-
```
42-
43-
* Pay the blacksmith 999 gold to buy a legendary rusty dagger.
44-
```
45-
> BITFIELD player:1:stats INCRBY u32 #0 -999
46-
1) (integer) 51
47-
```
48-
49-
* Read the player's stats:
50-
```
51-
> BITFIELD player:1:stats GET u32 #0 GET u32 #1
52-
1) (integer) 51
30+
{{< clients-example bitfield_tutorial bf >}}
31+
> BITFIELD bike:1:stats SET u32 #0 1000
32+
1) (integer) 0
33+
> BITFIELD bike:1:stats INCRBY u32 #0 -50 INCRBY u32 #1 1
34+
1) (integer) 950
5335
2) (integer) 1
54-
```
36+
> BITFIELD bike:1:stats INCRBY u32 #0 500 INCRBY u32 #1 1
37+
1) (integer) 1450
38+
2) (integer) 2
39+
> BITFIELD bike:1:stats GET u32 #0 GET u32 #1
40+
1) (integer) 1450
41+
2) (integer) 2
42+
{{< /clients-example >}}
5543

5644

5745
## Performance

0 commit comments

Comments
 (0)