Redis

Redis

1.

windows下載 https://github.com/MSOpenTech/redis/releases https://github.com/dmajkic/redis/downloads (下載後點選redis-server.exe 之後點選redis-cli)

Linux

sudo apt install redis-server

Mac using homebrew

https://medium.com/@petehouston/install-and-config-redis-on-mac-os-x-via-homebrew-eb8df9a4f298#.su9r2yd8u

2.

cd到目錄後執行redis-server.exe

3.再開一個terminal一樣cd 到redis路徑 輸入redis-cli可產生client端

4. 試著在client端輸入 set food noodleget food

#使用

基本上使用set 與get 即可用來存儲js相關字串或物件及array,但記得要先轉為string,記得要加上第三個參數callback不然可能無法使用

另外操作的過程不用像mongodb一樣寫在ready裡面

const redis = require("redis");
const Redisclient = redis.createClient();

export default () => {

  Redisclient.on("ready", function (err) {
      console.log("Ready");
  });

  Redisclient.on("error", function (err) {
      console.log("Error " + err);
  });
}

exports.Redisclient = Redisclient;

之後即可本機端和EC2共用同一個Redis 伺服器

再輸入redis-cli即可使用

http://stackoverflow.com/questions/21917661/can-you-connect-to-amazon-elasticache-redis-outside-of-amazon

可用資料結構

Last updated

Was this helpful?