xb18
xb18
文章39
标签0
分类0
redis使用

redis使用

命令行查询

1
2
3
4
5
6
7
8
redis-cli -p 6383 # 默认是6379
redis-cli # 默认端口连接

HGETALl 'dict:wb:cur:boardlist'

# 命名
# 存储数据 dict:wb:cur:boardlist
# 发布消息 msg:wb:cur:boardlist:change

常用命令

1
2
3
4
5
6
7
8
9
10
11
# set
HSET myhash field1 "Hello"
# get
HGETALL myhash
HGET myhash field1
# del
HDEL myhash field1

SET mykey "Hello"
GET mykey
DEL key1 key2 key3

nodejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { createClient } from 'redis'; // @4.x  https://github.com/redis/node-redis

const client = await createClient()
.on('error', err => console.log('Redis Client Error', err))
.connect();

// raw Redis commands
await client.HSET('key', 'field', 'value');
await client.HGETALL('key');

// friendly JavaScript commands
await client.hSet('key', 'field', 'value');
await client.hGetAll('key');

await client.sendCommand(['HGETALL', 'key']); // ['key1', 'field1', 'key2', 'field2']
本文作者:xb18
本文链接:http://xb18.github.io/2023/10/17/redis/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可