website/src/content/docs/actors/keys.mdx
Actor keys can be either a string or an array of strings:
<CodeSnippet file="examples/docs/actors-keys/key-format.ts" />Array keys are useful when you need compound keys with user-provided data. Using arrays makes adding user data safe by preventing key injection attacks:
<CodeSnippet file="examples/docs/actors-keys/compound-keys.ts" />This allows you to create hierarchical addressing schemes and organize actors by multiple dimensions.
<Warning> Don't build keys using string interpolation like `"foo:${userId}:bar"` when `userId` contains user data. If a user provides a value containing the delimiter (`:` in this example), it can break your key structure and cause key injection attacks. </Warning>You can create actors without specifying a key in situations where there is a singleton actor (i.e. only one actor of a given type). For example:
<CodeSnippet file="examples/docs/actors-keys/omitting-keys.ts" />This pattern should be avoided, since a singleton actor usually means you have a single actor serving all traffic & your application will not scale. See scaling documentation for more information.
Keys are unique within each actor name. Different actor types can use the same key:
<CodeSnippet file="examples/docs/actors-keys/key-uniqueness.ts" />Access the actor's key within the actor using the metadata API:
<CodeGroup> <CodeSnippet file="examples/docs/actors-keys/metadata-index.ts" title="index.ts" /> <CodeSnippet file="examples/docs/actors-keys/metadata-client.ts" title="client.ts" /> </CodeGroup>Use keys to provide basic actor configuration:
<CodeGroup> <CodeSnippet file="examples/docs/actors-keys/config-index.ts" title="index.ts" /> <CodeSnippet file="examples/docs/actors-keys/config-client.ts" title="client.ts" /> </CodeGroup>For more complex configuration, use input parameters:
<CodeSnippet file="examples/docs/actors-keys/complex-config.ts" title="client.ts" />ActorKey - Key type for actorsActorQuery - Query type using keysGetOptions - Options for getting by keyQueryOptions - Options for querying