Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

学习使用 redis #15

Open
yinxin630 opened this issue Jun 4, 2019 · 0 comments
Open

学习使用 redis #15

yinxin630 opened this issue Jun 4, 2019 · 0 comments
Labels

Comments

@yinxin630
Copy link
Owner

yinxin630 commented Jun 4, 2019

中文文档

http://redisdoc.com/index.html

运行 redis

以 docker 为例:

docker pull redis
docker run --name redis redis

启动 redis 客户端

docker exec -it redis /usr/local/bin/redis-cli

操作 redis

存取数据

127.0.0.1:6379> set stringKey 'string data'
OK
127.0.0.1:6379> get stringKey
"string data"

定时删除

单位: 秒(s)

127.0.0.1:6379> set timer 111 ex 5
OK
127.0.0.1:6379> get timer
"111"
127.0.0.1:6379> get timer
(nil)

在 node 中使用 redis

const redis = require('redis');
const bluebird = require('bluebird');

bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);

(async () => {
    const client = redis.createClient();
    console.log(await client.setAsync('a', 'ccccc')); // OK
    console.log(await client.getAsync('a')); // ccccc
})();

定时删除, redis 的所有方法均与官网 API 文档一致

client.setAsync('timer', 'value', 'ex', 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant