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.

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.

array
getCleanupPatterns()

Get every pattern needed to remove benchmark-owned keys.

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 48
__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 61
Repository getStore()

Get the cache repository for this context.

Return Value

Repository

at line 70
RedisStore getStoreInstance()

Get the underlying store instance.

Return Value

RedisStore

at line 90
string getCachePrefix()

Get the cache prefix.

Return Value

string

at line 106
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 129
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 150
array getCleanupPatterns()

Get every pattern needed to remove benchmark-owned keys.

The all-mode value pattern overlaps tag storage today. The explicit tag patterns keep each key family covered if that value pattern narrows; deleting the overlap is idempotent.

Return Value

array

at line 164
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 172
ProgressBar createProgressBar(int $max)

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

Parameters

int $max

Return Value

ProgressBar

at line 180
void line(string $message)

Write a line to output.

Parameters

string $message

Return Value

void

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

Write a blank line to output.

Parameters

int $count

Return Value

void

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

Call another command (with output).

Parameters

string $command
array $arguments

Return Value

int

at line 206
void checkMemoryUsage()

Check memory usage and throw exception if approaching limit.

Return Value

void

Exceptions

BenchmarkMemoryException

at line 230
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 remaining benchmark values and tag storage across both modes
  3. Remove benchmark entries from the any-mode tag registry

Return Value

void