Using Redis 2019 01 08 KISTI Yeonghun Chae

  • Slides: 31
Download presentation
Using Redis 2019 -01 -08, KISTI, Yeonghun Chae

Using Redis 2019 -01 -08, KISTI, Yeonghun Chae

Redis

Redis

In-memory Database Software

In-memory Database Software

Redis 활용

Redis 활용

Redis 명령어 ▪ Redis 접속 및 Get / Set > redis-cli -h 127. 0.

Redis 명령어 ▪ Redis 접속 및 Get / Set > redis-cli -h 127. 0. 0. 1 > get testkey > set testkey testvalue > set testint 1 > INCR testint > INCRBY testint 10 > mget testkey testint

Redis 명령어 ▪ List & Hash > rpush testlist test 1 test 2 test

Redis 명령어 ▪ List & Hash > rpush testlist test 1 test 2 test 3 > lrange testlist 0 -1 > rpop testlist > hmset testhash name user 1 birth 2000 > hget testhash name > hgetall testhash

Redis 명령어 ▪ Set & Sorted Set > sadd testset v 1 v 2

Redis 명령어 ▪ Set & Sorted Set > sadd testset v 1 v 2 v 3 > smembers testset > zadd testsortedset 1 v 3 > zadd testsortedset 3 v 1 > zadd testsortedset 2 v 2 > zrange testsortedset 0 -1

Redis 명령어 ▪ 데이터 삭제 > keys * > del testlist > flushall

Redis 명령어 ▪ 데이터 삭제 > keys * > del testlist > flushall

Redis 명령어 ▪ Pub-Sub > subscribe ch 1 ch 2 > publish ch 1

Redis 명령어 ▪ Pub-Sub > subscribe ch 1 ch 2 > publish ch 1 hello, world!

Redis 응용 - Session

Redis 응용 - Session

app. js > npm install express -session connect-redis ioredis > node app. js

app. js > npm install express -session connect-redis ioredis > node app. js

Example Redis Node. js/Socket. io Web. Server

Example Redis Node. js/Socket. io Web. Server

const Redis = require("ioredis") let redis = new Redis({ host: "127. 0. 0. 1",

const Redis = require("ioredis") let redis = new Redis({ host: "127. 0. 0. 1", port: 6379 }) redis. subscribe("channel") redis. on("message", (channel, message)=> { console. log(message) }) const Redis = require("ioredis") let redis = new Redis({ host: "127. 0. 0. 1", port: 6379 }) redis. publish("channel", "Hello, World!") ioredis > npm install ioredis

Redis 응용 - Message Brocker

Redis 응용 - Message Brocker

const mosca = require("mosca") let ascoltatore = { type: "redis", redis: require("redis"), db: 12,

const mosca = require("mosca") let ascoltatore = { type: "redis", redis: require("redis"), db: 12, port: 6379, return_buffers: true, host: "127. 0. 0. 1" } let mosca. Settings = { port: 1883, backend: ascoltatore, persistence: { factory: mosca. persistence. Redis } } let server = new mosca. Server(mosca. Settings) server. on("ready", ()=> console. log("Server Running")) server. on("client. Connected", (client)=> console. log(client. id)) server. on("publish", (packet, client)=> console. log(client. topic, client. payload) ) Mosca > npm install mosca --save > https: //github. com/mcollina/ mosca

THANK YOU proin@kisti. re. kr

THANK YOU proin@kisti. re. kr