Created
August 10, 2020 16:03
-
-
Save simonespa/dfffdff0cbb53c3d8f047c40ce12988c to your computer and use it in GitHub Desktop.
Catbox test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { Client } = require("@hapi/catbox"); | |
| const CatboxRedis = require("@hapi/catbox-redis"); | |
| const RMSClient = require("@bbc/rms-client"); | |
| const stats = { | |
| increment: (metric) => { | |
| console.log(`stats.increment("${metric}")`); | |
| }, | |
| timing: (metric, value) => { | |
| console.log(`stats.timing("${metric}", ${value})`); | |
| } | |
| }; | |
| const redis = new Client(CatboxRedis, { | |
| partition: "partition" | |
| }); | |
| // const cache = { | |
| // start: async () => { | |
| // console.log("cache.start()"); | |
| // return redis.start(); | |
| // }, | |
| // stop: async () => { | |
| // console.log("cache.stop()"); | |
| // return redis.stop(); | |
| // }, | |
| // isReady: () => { | |
| // console.log("cache.isReady()"); | |
| // // return false; | |
| // return redis.isReady(); | |
| // }, | |
| // validateSegmentName: (name) => { | |
| // console.log(`cache.validateSegmentName("${name}")`); | |
| // return redis.validateSegmentName(name); | |
| // }, | |
| // get: async (key) => { | |
| // console.log(`cache.get("${JSON.stringify(key, null, 2)}")`); | |
| // return redis.get(key); | |
| // }, | |
| // set: (key, value, ttl) => { | |
| // console.log( | |
| // `cache.set("${JSON.stringify(key, null, 2)}", ${value}, ${ttl})` | |
| // ); | |
| // return redis.set(key, value, ttl); | |
| // }, | |
| // drop: (key) => { | |
| // console.log(`cache.drop("${key}")`); | |
| // return redis.drop(key); | |
| // }, | |
| // generateKey: ({ id, segment }) => { | |
| // console.log(`cache.generateKey({ id: "${id}", segment: "${segment}"})`); | |
| // return redis.generateKey({ id, segment }); | |
| // }, | |
| // }; | |
| const cache = { | |
| start: async () => { | |
| return redis.start(); | |
| }, | |
| stop: async () => { | |
| return redis.stop(); | |
| }, | |
| isReady: () => { | |
| // return false; | |
| return redis.isReady(); | |
| }, | |
| validateSegmentName: (name) => { | |
| return redis.validateSegmentName(name); | |
| }, | |
| get: async (key) => { | |
| return redis.get(key); | |
| }, | |
| set: (key, value, ttl) => { | |
| return redis.set(key, value, ttl); | |
| }, | |
| drop: (key) => { | |
| return redis.drop(key); | |
| }, | |
| generateKey: ({ id, segment }) => { | |
| return redis.generateKey({ id, segment }); | |
| }, | |
| }; | |
| const rmsClient = RMSClient.createClient({ | |
| apiKey: "", | |
| userAgent: "test", | |
| baseUrl: "http://localhost.bbc.co.uk:7080", | |
| retries: 3, | |
| timeout: 500, | |
| cache, | |
| cacheTimeout: 200, | |
| stats, | |
| }); | |
| (async function () { | |
| try { | |
| const response = await rmsClient | |
| .v2BroadcastsPollSignedOutQuery() | |
| .sid("bbc_radio_one") | |
| .get(); | |
| } catch (error) { | |
| console.log(error); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment