FdbKey

Namespace: FoundationDB.Client · class

Factory class for keys

Properties

DirectoryPrefixSpan

static ReadOnlySpan<byte> DirectoryPrefixSpan { get; }

Default Directory Layer prefix (0xFE...)

MaxValueSpan

static ReadOnlySpan<byte> MaxValueSpan { get; }

Biggest possible key (0xFF), excluding the system keys

MinValueSpan

static ReadOnlySpan<byte> MinValueSpan { get; }

Smallest possible key (0x00 ])

SpecialKeyPrefix

static ReadOnlySpan<byte> SpecialKeyPrefix { get; }

Prefix of the Special Keys keyspace (`\xFF\xFF...`)

SystemEndSpan

static ReadOnlySpan<byte> SystemEndSpan { get; }

Last possible key of System keyspace (`\xFF\xFF`)

SystemPrefixSpan

static ReadOnlySpan<byte> SystemPrefixSpan { get; }

Prefix of the System keyspace (`\xFF...`)

Methods

Batched

static IEnumerable<IEnumerable<KeyValuePair<int, int>>> Batched(int offset, int count, int workers, int batchSize)

Splits a range of indexes into a fixed number of 'worker' sequence, that will consume batches in parallel

  • offset — Offset from which to start counting
  • count — Total number of values that will be returned
  • workers — Number of concurrent workers that will take batches from the pool
  • batchSize — Maximum size of each batch

Returns: List of 'workers' enumerables that all fetch batches of values from the same common pool. All enumerables will stop when the last batch as been consumed by the last worker.

BatchedRange

static IEnumerable<IEnumerable<int>> BatchedRange(int offset, int count, int batchSize)

Splits a range of indexes into several batches

  • offset — Offset from which to start counting
  • count — Total number of values that will be returned
  • batchSize — Maximum size of each batch

Returns: Collection of B batches each containing at most batchSize contiguous indices, counting from offset to (offset + count - 1)

Batched(0, 100, 20) => [ {0..19}, {20..39}, {40..59}, {60..79}, {80..99} ]

Dump

static string Dump(Slice key)

Produces a user-friendly version of the slice

  • key — Any binary key

Returns: User-friendly version of the key. Attempts to decode the key as a tuple first. Then as an ASCII string. Then as a hex dump of the key.

This can be slow, and should only be used for logging or troubleshooting.

static string Dump(ReadOnlySpan<byte> key)

Produces a user-friendly version of the slice

  • key — Any binary key

Returns: User-friendly version of the key. Attempts to decode the key as a tuple first. Then as an ASCII string. Then as a hex dump of the key.

This can be slow, and should only be used for logging or troubleshooting.

EnsureKeyIsValid

static void EnsureKeyIsValid(Slice key, bool endExclusive = false)

Checks that a key is inside the global namespace of this database, and contained in the optional legal key space specified by the user

  • key — Key to verify
  • endExclusive — If true, the key is allowed to be one past the maximum key allowed by the global namespace

static void EnsureKeyIsValid(ReadOnlySpan<byte> key, bool endExclusive = false)

Checks that a key is inside the global namespace of this database, and contained in the optional legal key space specified by the user

  • key — Key to verify
  • endExclusive — If true, the key is allowed to be one past the maximum key allowed by the global namespace

EnsureKeysAreValid

static void EnsureKeysAreValid(ReadOnlySpan<Slice> keys, bool endExclusive = false)

Checks that one or more keys are inside the global namespace of this database, and contained in the optional legal key space specified by the user

  • keys — Array of keys to verify
  • endExclusive — If true, the keys are allowed to be one past the maximum key allowed by the global namespace

EnsureValueIsValid

static void EnsureValueIsValid(Slice value)

Ensures that a serialized value is valid

Throws an exception if the value is null, or exceeds the maximum allowed size (Fdb.MaxValueSize)

static void EnsureValueIsValid(ReadOnlySpan<byte> value)

Ensures that a serialized value is valid

Throws an exception if the value is null, or exceeds the maximum allowed size (Fdb.MaxValueSize)

FromBytes

static FdbRawKey FromBytes(Slice key)

Returns a key that wraps a pre-encoded Slice

static FdbRawKey FromBytes(byte[] key)

Returns a key that wraps a pre-encoded byte array

static FdbRawKey FromBytes(ReadOnlySpan<byte> key)

Returns a key that wraps a copy of a span of bytes

static FdbSuffixKey FromBytes(IKeySubspace subspace, Slice relativeKey)

Returns a key that wraps a pre-encoded binary suffix inside a IKeySubspace

static FdbSuffixKey FromBytes(IKeySubspace subspace, byte[] relativeKey)

Returns a key that wraps a pre-encoded binary suffix inside a IKeySubspace

static FdbSuffixKey FromBytes(IKeySubspace subspace, ReadOnlySpan<byte> relativeKey)

Returns a key that wraps a pre-encoded binary suffix inside a IKeySubspace

static FdbRawKey FromBytes(byte[] key, int start, int length)

Returns a key that wraps a pre-encoded byte array

static FdbSuffixKey FromBytes(IKeySubspace subspace, byte[] relativeKey, int start, int length)

Returns a key that wraps a pre-encoded binary suffix inside a IKeySubspace

FromTuple

static FdbTupleKey<T1> FromTuple<T1>((T1) key)

static FdbTupleKey<T1, T2> FromTuple<T1, T2>(in (T1, T2) key)

static FdbTupleKey<T1, T2, T3> FromTuple<T1, T2, T3>(in (T1, T2, T3) key)

static FdbTupleKey<T1, T2, T3, T4> FromTuple<T1, T2, T3, T4>(in (T1, T2, T3, T4) key)

static FdbTupleKey<T1, T2, T3, T4, T5> FromTuple<T1, T2, T3, T4, T5>(in (T1, T2, T3, T4, T5) key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6> FromTuple<T1, T2, T3, T4, T5, T6>(in (T1, T2, T3, T4, T5, T6) key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7> FromTuple<T1, T2, T3, T4, T5, T6, T7>(in (T1, T2, T3, T4, T5, T6, T7) key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7, T8> FromTuple<T1, T2, T3, T4, T5, T6, T7, T8>(in (T1, T2, T3, T4, T5, T6, T7, (T8)) key)

static FdbTupleKey FromTuple(IVarTuple items)

Returns a key that packs the given items inside the root subspace

  • items — Elements of the key

static FdbTupleKey<T1> FromTuple<T1>(STuple<T1> key)

static FdbTupleKey<T1, T2> FromTuple<T1, T2>(in STuple<T1, T2> key)

static FdbTupleKey<T1, T2, T3> FromTuple<T1, T2, T3>(in STuple<T1, T2, T3> key)

static FdbTupleKey<T1, T2, T3, T4> FromTuple<T1, T2, T3, T4>(in STuple<T1, T2, T3, T4> key)

static FdbTupleKey<T1, T2, T3, T4, T5> FromTuple<T1, T2, T3, T4, T5>(in STuple<T1, T2, T3, T4, T5> key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6> FromTuple<T1, T2, T3, T4, T5, T6>(in STuple<T1, T2, T3, T4, T5, T6> key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7> FromTuple<T1, T2, T3, T4, T5, T6, T7>(in STuple<T1, T2, T3, T4, T5, T6, T7> key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7, T8> FromTuple<T1, T2, T3, T4, T5, T6, T7, T8>(in STuple<T1, T2, T3, T4, T5, T6, T7, T8> key)

static FdbTupleKey<T1> FromTuple<T1>(IKeySubspace subspace, (T1) key)

static FdbTupleKey<T1, T2> FromTuple<T1, T2>(IKeySubspace subspace, in (T1, T2) key)

static FdbTupleKey<T1, T2, T3> FromTuple<T1, T2, T3>(IKeySubspace subspace, in (T1, T2, T3) key)

static FdbTupleKey<T1, T2, T3, T4> FromTuple<T1, T2, T3, T4>(IKeySubspace subspace, in (T1, T2, T3, T4) key)

static FdbTupleKey<T1, T2, T3, T4, T5> FromTuple<T1, T2, T3, T4, T5>(IKeySubspace subspace, in (T1, T2, T3, T4, T5) key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6> FromTuple<T1, T2, T3, T4, T5, T6>(IKeySubspace subspace, in (T1, T2, T3, T4, T5, T6) key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7> FromTuple<T1, T2, T3, T4, T5, T6, T7>(IKeySubspace subspace, in (T1, T2, T3, T4, T5, T6, T7) key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7, T8> FromTuple<T1, T2, T3, T4, T5, T6, T7, T8>(IKeySubspace subspace, in (T1, T2, T3, T4, T5, T6, T7, (T8)) key)

static FdbTupleKey FromTuple(IKeySubspace subspace, IVarTuple items)

Returns a key that packs the given items inside the root subspace

  • subspace — Subspace that contains the key
  • items — Elements of the key

static FdbTupleKey<T1> FromTuple<T1>(IKeySubspace subspace, STuple<T1> key)

static FdbTupleKey<T1, T2> FromTuple<T1, T2>(IKeySubspace subspace, in STuple<T1, T2> key)

static FdbTupleKey<T1, T2, T3> FromTuple<T1, T2, T3>(IKeySubspace subspace, in STuple<T1, T2, T3> key)

static FdbTupleKey<T1, T2, T3, T4> FromTuple<T1, T2, T3, T4>(IKeySubspace subspace, in STuple<T1, T2, T3, T4> key)

static FdbTupleKey<T1, T2, T3, T4, T5> FromTuple<T1, T2, T3, T4, T5>(IKeySubspace subspace, in STuple<T1, T2, T3, T4, T5> key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6> FromTuple<T1, T2, T3, T4, T5, T6>(IKeySubspace subspace, in STuple<T1, T2, T3, T4, T5, T6> key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7> FromTuple<T1, T2, T3, T4, T5, T6, T7>(IKeySubspace subspace, in STuple<T1, T2, T3, T4, T5, T6, T7> key)

static FdbTupleKey<T1, T2, T3, T4, T5, T6, T7, T8> FromTuple<T1, T2, T3, T4, T5, T6, T7, T8>(IKeySubspace subspace, in STuple<T1, T2, T3, T4, T5, T6, T7, T8> key)

Increment

static Slice Increment(Slice key)

Returns the first key (in lexicographically order) that does not have the passed in key as a prefix

  • key — Slice to increment

Returns: New slice that is guaranteed to be the first key lexicographically higher than key which does not have key as a prefix

If the last byte is already equal to 0xFF, it will roll over to 0x00 and the previous byte will be incremented.

FdbKey.Increment(Slice.FromString("ABC")) => "ABD" FdbKey.Increment(Slice.FromHexa("01 FF")) => { 02 }

static void Increment(Span<byte> key, out int length)

Increments the key in the buffer into the first key (in lexicographically order) that does not have the passed in key as a prefix.

If the last byte is already equal to 0xFF, the previous byte will be incremented instead.

If all bytes are equal to 0xFF, and exception is thrown

Examples: FdbKey.Increment([ 0x42, 0x12, 0x34, 0x00 ], out length) => [ 0x42, 0x12, 0x34, 0x01 ], length = 4 FdbKey.Increment([ 0x42, 0x12, 0x34, 0xFE ], out length) => [ 0x42, 0x12, 0x34, 0xFF ], length = 4 FdbKey.Increment([ 0x42, 0x12, 0x34, 0xFF ], out length) => [ 0x42, 0x12, 0x35 ], length = 3 FdbKey.Increment([ 0x42, 0x12, 0xFF, 0xFF ], out length) => [ 0x42, 0x13 ], length = 2 FdbKey.Increment([ 0x42, 0xFF, 0xFF, 0xFF ], out length) => [ 0x43 ], length = 1 FdbKey.Increment([ 0xFF, 0xFF, 0xFF, 0xFF ], out length) => throws!

IsKeyValid

static bool IsKeyValid(Slice key)

Tests if a key is allowed to be used with this database instance

  • key — Key to test

Returns: Returns true if the key is not null or empty, does not exceed the maximum key size, and is contained in the global key space of this database instance. Otherwise, returns false.

static bool IsKeyValid(ReadOnlySpan<byte> key)

Tests if a key is allowed to be used with this database instance

  • key — Key to test

Returns: Returns true if the key is not null or empty, does not exceed the maximum key size, and is contained in the global key space of this database instance. Otherwise, returns false.

IsSpecialKey

static bool IsSpecialKey(Slice key)

Checks if the key is in the SpecialKey keyspace (starts with `\xFF\xFF`)

static bool IsSpecialKey(ReadOnlySpan<byte> key)

Checks if the key is in the SpecialKey keyspace (starts with `\xFF\xFF`)

static bool IsSpecialKey<TKey>(in TKey key)

Checks if the key is in the System keyspace (starts with `\xFF`)

IsSystemKey

static bool IsSystemKey(Slice key)

Checks if the key is in the System keyspace (starts with `\xFF`)

static bool IsSystemKey(ReadOnlySpan<byte> key)

Checks if the key is in the System keyspace (starts with `\xFF`)

static bool IsSystemKey<TKey>(in TKey key)

Checks if the key is in the System keyspace (starts with `\xFF`)

Last

static FdbLastKey<FdbRawKey> Last(Slice key)

Returns a key that wraps a pre-encoded end of valid children of a Slice (key.`\xFF`)

Merge

static Slice[] Merge(Slice prefix, Slice[] keys)

Merges an array of keys with a same prefix, all sharing the same buffer

  • prefix — Prefix shared by all keys
  • keys — Array of keys to pack

Returns: Array of slices (for all keys) that share the same underlying buffer

static Slice[] Merge(Slice prefix, ReadOnlySpan<Slice> keys)

Merges an array of keys with a same prefix, all sharing the same buffer

  • prefix — Prefix shared by all keys
  • keys — Array of keys to pack

Returns: Array of slices (for all keys) that share the same underlying buffer

static Slice[] Merge(Slice prefix, IEnumerable<Slice> keys)

Merges a sequence of keys with a same prefix, all sharing the same buffer

  • prefix — Prefix shared by all keys
  • keys — Sequence of keys to pack

Returns: Array of slices (for all keys) that share the same underlying buffer

PrettyPrint

static string PrettyPrint(Slice key, PrettyPrintMode mode)

Produces a user-friendly version of the slice

  • key — Any binary key
  • mode — Defines if the key is standalone, or is the beginning or end part or a key range. This will enable or disable some heuristics that try to properly format key ranges.

Returns: User-friendly version of the key. Attempts to decode the key as a tuple first. Then as an ASCII string. Then as a hex dump of the key.

This can be slow, and should only be used for logging or troubleshooting.

static string PrettyPrint(ReadOnlySpan<byte> key, PrettyPrintMode mode)

Produces a user-friendly version of the slice

  • key — Any binary key
  • mode — Defines if the key is standalone, or is the beginning or end part or a key range. This will enable or disable some heuristics that try to properly format key ranges.

Returns: User-friendly version of the key. Attempts to decode the key as a tuple first. Then as an ASCII string. Then as a hex dump of the key.

This can be slow, and should only be used for logging or troubleshooting.

Successor

static FdbSuccessorKey<FdbRawKey> Successor(Slice key)

Returns a key that wraps a pre-encoded successor of a Slice (key.`\x00`)

ToSpecialKey

static FdbSystemKey ToSpecialKey(ReadOnlySpan<byte> relativeKey)

Returns a key in the Special Key subspace (`\xFF\xFF....`)

The relativeKey MUST NOT contain any characters greater than 0xFF. See FromStringAscii for more details.

Please be careful when using UTF-8 string literals: the value "\xff/hello/world"u8 will be encoded as UTF-8, meaning that it will start with bytes [ 0xC3, 0xBF, ...] and NOT [ 0xFF, .... ] !

static FdbSystemKey ToSpecialKey(Slice relativeKey)

Returns a key in the Special Key subspace (`\xFF\xFF....`)

static FdbSystemKey ToSpecialKey(byte[] relativeKey)

Returns a key in the Special Key subspace (`\xFF\xFF....`)

static FdbSystemKey ToSpecialKey(string relativeKey)

Returns a key in the Special Key subspace (`\xFF\xFF....`)

The MUST NOT contain any characters greater than 0xFF. See for more details.

static FdbSystemKey ToSpecialKey(ReadOnlySpan<char> relativeKey)

Returns a key in the Special Key subspace (`\xFF\xFF....`)

The MUST NOT contain any characters greater than 0xFF. See for more details.

ToSystemKey

static FdbSystemKey ToSystemKey(ReadOnlySpan<byte> relativeKey)

Returns a key in the System subspace (`\xFF....`)

static FdbSystemKey ToSystemKey(Slice relativeKey)

Returns a key in the System subspace (`\xFF....`)

static FdbSystemKey ToSystemKey(byte[] relativeKey)

Returns a key in the System subspace (`\xFF....`)

static FdbSystemKey ToSystemKey(string relativeKey)

Returns a key in the System subspace (`\xFF....`)

For example, FdbKey.ToSystemKey("/metadataVersion") will generate the key `\xFF/metadataVersion`

The relativeKey MUST NOT contain any characters greater than 0xFF. See FromStringAscii for more details.

static FdbSystemKey ToSystemKey(ReadOnlySpan<char> relativeKey)

Returns a key in the System subspace (`\xFF....`)

For example, FdbKey.ToSystemKey("/metadataVersion".AsSpan()) will generate the key `\xFF/metadataVersion`

The relativeKey MUST NOT contain any characters greater than 0xFF. See FromStringAscii for more details.

Fields

Directory

static readonly Slice Directory

Default Directory Layer prefix (0xFE...)

DirectoryPrefix

static readonly Slice DirectoryPrefix

Default Directory Layer prefix (0xFE...)

MaxSize

const int MaxSize

Maximum allowed size for a key in the database (10,000 bytes)

MaxValue

static readonly Slice MaxValue

Biggest possible key (0xFF), excluding the system keys

MinValue

static readonly Slice MinValue

Smallest possible key (0x00)

System

static readonly Slice System

Default System prefix (0xFF...)

SystemPrefix

static readonly Slice SystemPrefix

Default System prefix (0xFF...)