1.
sudo apt install redis-server
2.
4. 試著在client端輸入 set food noodle
後get food
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;
import { Redisclient } from './redis';
import Redis from './redis';
Redis();
const payload = [{a:12,b:13},{a:12,b:13},{a:12,b:13}];
Redisclient.set("short", JSON.stringify(payload), () => {
});
Redisclient.get("short",function (err, reply) {
console.log(JSON.parse(reply)); // Will print `OK`
});
# #使用AWS的Redis ElastiCache
>預設只給EC2做內網連線
有兩種可選一種為Redis,一種為Memcached
我們這裡選擇開Redis
>注意:如果是要免費的記得選擇開啟的機器規格
預設的選項是要付費的,FREE TIRE的免費只有t2 micro的Redis
開完後記得先到`ElastiCache dashboard`上方點選Modify,並選擇和你EC2相同之security group,之後回到`EC2 dashboard`把security group的Inbound加上 6379的PORT
####連線:
ssh到EC2後使用 `telnet`
telnet test.aq9nab.ng.0001.apne1.cache.amazonaws.com 6379
#開放從電腦本機連線到AWS Redis
利用轉傳規則 ssh -f -N -L6379::6379
String (SET GET)
Hash (HSET HGET HDEL HGETALL)
List (LPUSH LPOP RPUSH RPOP)
Set (SADD SPOP)
Sorted Set (ZADD ZRANGE)