Repository navigation
Expand file tree
/
Copy pathkeyspace-notifications.ts
More file actions
50 lines (43 loc) · 2.14 KB
/
Copy pathkeyspace-notifications.ts
File metadata and controls
50 lines (43 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {Command, flags} from '@heroku-cli/command'
import {Args} from '@oclif/core'
import tsheredoc from 'tsheredoc'
import redisApi, {RedisFormationConfigResponse} from '../../lib/redis/api.js'
const heredoc = tsheredoc
export default class KeyspaceNotifications extends Command {
static args = {
database: Args.string({description: 'name of the Key-Value Store database. If omitted, it defaults to the primary database associated with the app.'}),
}
static description = heredoc`
set the keyspace notifications configuration
Set the configuration to enable keyspace notification events:
K Keyspace events, published with __keyspace@<db>__ prefix.
E Keyevent events, published with __keyevent@<db>__ prefix.
g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
$ String commands
l List commands
s Set commands
h Hash commands
z Sorted set commands
t Stream commands
x Expired events (events generated every time a key expires)
e Evicted events (events generated when a key is evicted for maxmemory)
m Key miss events (events generated when a key that doesn't exist is accessed)
A Alias for "g$lshztxe", so that the "AKE" string means all the events except "m".
pass an empty string ('') to disable keyspace notifications
`
static flags = {
app: flags.app({required: true}),
config: flags.string({char: 'c', description: 'set keyspace notifications configuration', required: true}),
remote: flags.remote(),
}
static topic = 'redis'
public async run(): Promise<void> {
const {args, flags} = await this.parse(KeyspaceNotifications)
const {app, config} = flags
const {database} = args
const api = redisApi(app, database, false, this.heroku)
const addon = await api.getRedisAddon()
const {body: updated_config} = await api.request<RedisFormationConfigResponse>(`/redis/v0/databases/${addon.name}/config`, 'PATCH', {notify_keyspace_events: config})
this.log(`Keyspace notifications for ${addon.name} (${addon.config_vars.join(', ')}) set to '${updated_config.notify_keyspace_events.value}'.`)
}
}