20250203
redis
설치
npm install redis
자바스크립트 연결 구문
import { createClient } from 'redis';
const client = createClient();
client.on('error', err => console.log('Redis Client Error', err));
await client.connect();
저장 불러오기 하는 내용
await client.set('key', 'value');
const value = await client.get('key');
맵으로 저장하고 받아오기
await client.hSet('user-session:123', {
name: 'John',
surname: 'Smith',
company: 'Redis',
age: 29
})
let userSession = await client.hGetAll('user-session:123');
console.log(JSON.stringify(userSession, null, 2));
/*
{
"surname": "Smith",
"name": "John",
"company": "Redis",
"age": "29"
}
*/
맵을 저장하고 불러올 수 있다.
다른 호스트나 서버에 연결할때
createClient({
url: 'redis://alice:foobared@awesome.redis.server:6380'
});
다음의 형식에 따라 만들어져 있다.
redis[s]://[[username][:password]@][host][:port][/db-number]:
alice
foobared
awesome.redis.server
6380
공식문서는 다음에서 찾아볼 수 있다.
https://redis.io/docs/latest/develop/clients/nodejs/