class BenchmarkContext

Context object that bundles shared state for benchmark scenarios.

Constants

KEY_PREFIX

Key prefix for benchmark-generated cache entries.

Matches the pattern used by DoctorContext (_doctor:test:).

Methods

__construct(string $storeName, int $items, int $tagsPerItem, int $heavyTags, Command $command, Factory $cacheManager)

Create a new benchmark context instance.

getStore()

Get the cache repository for this context.

getStoreInstance()

Get the underlying store instance.

string
getCachePrefix()

Get the cache prefix.

TagMode
getTagMode()

Get the current tag mode.

bool
isAnyMode()

Check if the store is configured for 'any' tag mode.

bool
isAllMode()

Check if the store is configured for 'all' tag mode.

array
getTagStoragePatterns(string $tagNamePrefix)

Get patterns to match all tag storage structures with a given tag name prefix.

array
getCacheValuePatterns(string $keyPrefix)

Get patterns to match all cache value keys with a given key prefix.

string
prefixed(string $value)

Get a value prefixed with the benchmark prefix.

ProgressBar
createProgressBar(int $max)

Create a progress bar using the command's output style.

void
line(string $message)

Write a line to output.

void
newLine(int $count = 1)

Write a blank line to output.

int
call(string $command, array $arguments = [])

Call another command (with output).

void
checkMemoryUsage()

Check memory usage and throw exception if approaching limit.

void
cleanup()

Perform cleanup of benchmark data.

Details

at line 49
__construct(string $storeName, int $items, int $tagsPerItem, int $heavyTags, Command $command, Factory $cacheManager)

Create a new benchmark context instance.

Parameters

string $storeName
int $items
int $tagsPerItem
int $heavyTags
Command $command
Factory $cacheManager

at line 64
Repository getStore()

Get the cache repository for this context.

Return Value

Repository

at line 73
RedisStore getStoreInstance()

Get the underlying store instance.

Return Value

RedisStore

at line 93
string getCachePrefix()

Get the cache prefix.

Return Value

string

at line 101
TagMode getTagMode()

Get the current tag mode.

Return Value

TagMode

at line 109
bool isAnyMode()

Check if the store is configured for 'any' tag mode.

Return Value

bool

at line 117
bool isAllMode()

Check if the store is configured for 'all' tag mode.

Return Value

bool

at line 133
array getTagStoragePatterns(string $tagNamePrefix)

Get patterns to match all tag storage structures with a given tag name prefix.

Returns patterns for BOTH tag modes to ensure complete cleanup regardless of current mode (important for --compare-tag-modes):

  • Any mode: {cachePrefix}_any:tag:{tagNamePrefix}*
  • All mode: {cachePrefix}_all:tag:{tagNamePrefix}*

Parameters

string $tagNamePrefix

The prefix to match tag names against

Return Value

array

Patterns to use with SCAN/KEYS commands

at line 156
array getCacheValuePatterns(string $keyPrefix)

Get patterns to match all cache value keys with a given key prefix.

Returns patterns for BOTH tag modes to ensure complete cleanup regardless of current mode (important for --compare-tag-modes):

  • Untagged keys: {cachePrefix}{keyPrefix}* (same in both modes)
  • Tagged keys in all mode: {cachePrefix}{xxh128}:{keyPrefix}* (namespaced)

Parameters

string $keyPrefix

The prefix to match cache keys against

Return Value

array

Patterns to use with SCAN/KEYS commands

at line 174
string prefixed(string $value)

Get a value prefixed with the benchmark prefix.

Used for both cache keys and tag names to ensure complete isolation from production data and safe cleanup.

Parameters

string $value

Return Value

string

at line 182
ProgressBar createProgressBar(int $max)

Create a progress bar using the command's output style.

Parameters

int $max

Return Value

ProgressBar

at line 190
void line(string $message)

Write a line to output.

Parameters

string $message

Return Value

void

at line 198
void newLine(int $count = 1)

Write a blank line to output.

Parameters

int $count

Return Value

void

at line 206
int call(string $command, array $arguments = [])

Call another command (with output).

Parameters

string $command
array $arguments

Return Value

int

at line 216
void checkMemoryUsage()

Check memory usage and throw exception if approaching limit.

Return Value

void

Exceptions

BenchmarkMemoryException

at line 241
void cleanup()

Perform cleanup of benchmark data.

This method uses mode-aware patterns to ensure complete cleanup:

  1. Flush all tagged items via $store->tags()->flush()
  2. Clean non-tagged benchmark keys
  3. Clean any remaining tag storage structures (matching _bench: prefix)
  4. Run prune command to clean up orphans

Return Value

void