You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/kv/api/read-key-value-pairs.mdx
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,9 @@ The following methods are provided to read from KV:
46
46
To get the value for a given key, call the `get()` method on any KV namespace you have bound to your Worker code:
47
47
48
48
```js
49
-
env.NAMESPACE.get(key, type?, options?);
49
+
env.NAMESPACE.get(key, type?);
50
+
// OR
51
+
env.NAMESPACE.get(key, options?);
50
52
```
51
53
52
54
The `get()` method returns a promise you can `await` on to get the value. If the key is not found, the promise will resolve with the literal value `null`.
@@ -58,10 +60,10 @@ The `get()` method returns a promise you can `await` on to get the value. If the
58
60
- `type`: `"text"|"json"|"arrayBuffer"|"stream"`
59
61
- Optional. The type of the value to be returned. `text` is the default.
60
62
- `options`: `{
61
-
cacheTtl: number,
62
-
type:"text"|"json"|"arrayBuffer"|"stream"
63
+
cacheTtl?: number,
64
+
type?:"text"|"json"|"arrayBuffer"|"stream"
63
65
}`
64
-
- Optional. Object containing the `cacheTtl` and `type` properties. The `cacheTtl` property defines the length of time in seconds that a KV result is cached in the global network location it is accessed from (minimum: 60). The `type` property defines the type of the value to be returned.
66
+
- Optional. Object containing the optional `cacheTtl` and `type` properties. The `cacheTtl` property defines the length of time in seconds that a KV result is cached in the global network location it is accessed from (minimum: 60). The `type` property defines the type of the value to be returned.
65
67
66
68
#### Response
67
69
@@ -79,7 +81,9 @@ The `get()` method may return stale values. If a given key has recently been rea
79
81
To get the value for a given key along with its metadata, call the `getWithMetadata()` method on any KV namespace you have bound to your Worker code:
Metadata is a serializable value you append to each KV entry.
@@ -91,10 +95,10 @@ Metadata is a serializable value you append to each KV entry.
91
95
- `type`: `"text"|"json"|"arrayBuffer"|"stream"`
92
96
- Optional. The type of the value to be returned. `text` is the default.
93
97
- `options`: `{
94
-
cacheTtl: number,
95
-
type:"text"|"json"|"arrayBuffer"|"stream"
98
+
cacheTtl?: number,
99
+
type?:"text"|"json"|"arrayBuffer"|"stream"
96
100
}`
97
-
- Optional. Object containing the `cacheTtl` and `type` properties. The `cacheTtl` property defines the length of time in seconds that a KV result is cached in the global network location it is accessed from (minimum: 60). The `type` property defines the type of the value to be returned.
101
+
- Optional. Object containing the optional `cacheTtl` and `type` properties. The `cacheTtl` property defines the length of time in seconds that a KV result is cached in the global network location it is accessed from (minimum: 60). The `type` property defines the type of the value to be returned.
0 commit comments