-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredis-init.ts
45 lines (39 loc) · 1.25 KB
/
redis-init.ts
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
import { Redis, DBT, KEYS } from '@elara/lib'
const cKEY = KEYS.Chain
enum NodeType {
Node = 'node',
Kv = 'kv',
Mem = 'memory'
}
interface ChainConfig {
name: string,
nodeId: number, // default 0, elara node instance id
type: NodeType,
baseUrl: string, // host
rpcPort?: number, // only for Node type. default 9933,
wsPort: number, // default 9944
poolSize: number,
[key: string]: any // for redis
}
// default localhost:6379, configure your own connection
// NOTE: don't change DBT.Chain type
const cRd = new Redis(DBT.Chain).getClient()
const newChain = async (chain: string) => {
const polkadot: ChainConfig = {
name: chain,
type: NodeType.Node,
baseUrl: '127.0.0.1', // node url
wsPort: 19944, // websocket port
rpcPort: 19933, // http port
nodeId: 0, // node instance id, when multi node deploy
poolSize: 20
}
await cRd.hmset(cKEY.hChain(chain, 0), polkadot)
let cnt = await cRd.incr(cKEY.chainNum())
await cRd.zadd(cKEY.zChainList(), cnt, chain.toLowerCase())
}
async function init() {
await newChain('Polkadot')
process.exit(0)
}
init()