티스토리 뷰

Redis 를 Ubuntu 에 설치하고 파일을 읽어서 레디스에 저장하는 방법을 간단하게 알아보려 한다.

 

apt update 

hsquare@ep-big:~$ sudo apt update
Ign:1 http://repos.azulsystems.com/ubuntu stable InRelease
Hit:2 http://repos.azulsystems.com/ubuntu stable Release
Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Hit:5 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu xenial InRelease
Hit:6 http://kr.archive.ubuntu.com/ubuntu xenial InRelease
Get:7 http://kr.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [783 kB]
Get:9 http://kr.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:10 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1069 kB]
Get:11 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages [615 kB]
Get:12 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [464 kB]
Get:13 http://kr.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [881 kB]
Get:14 http://security.ubuntu.com/ubuntu xenial-security/universe i386 Packages [399 kB]
Get:15 http://kr.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [769 kB]
Get:16 http://kr.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [698 kB]
Fetched 6004 kB in 19s (312 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
146 packages can be upgraded. Run 'apt list --upgradable' to see them.

 

redis install

sudo apt install redis-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  redis-server
0 upgraded, 1 newly installed, 0 to remove and 146 not upgraded.
Need to get 344 kB of archives.
After this operation, 919 kB of additional disk space will be used.
Get:1 http://kr.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 redis-server amd64 2:3.0.6-1ubuntu0.4 [344 kB]
Fetched 344 kB in 2s (153 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = "en_US:en",
	LC_ALL = (unset),
	LC_CTYPE = "ko_KR.UTF-8",
	LC_TERMINAL_VERSION = "3.3.6",
	LC_TERMINAL = "iTerm2",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package redis-server.
(Reading database ... 107110 files and directories currently installed.)
Preparing to unpack .../redis-server_2%3a3.0.6-1ubuntu0.4_amd64.deb ...
Unpacking redis-server (2:3.0.6-1ubuntu0.4) ...
Processing triggers for systemd (229-4ubuntu21.21) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up redis-server (2:3.0.6-1ubuntu0.4) ...

 

redis start and status

$sudo systemctl restart redis

$sudo systemctl status redis
● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-11-15 09:38:19 KST; 21s ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
  Process: 71620 ExecStopPost=/bin/run-parts --verbose /etc/redis/redis-server.post-down.d (code=exited, status=0/SUCCESS)
  Process: 71615 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 71611 ExecStop=/bin/run-parts --verbose /etc/redis/redis-server.pre-down.d (code=exited, status=0/SUCCESS)
  Process: 71635 ExecStartPost=/bin/run-parts --verbose /etc/redis/redis-server.post-up.d (code=exited, status=0/SUCCESS)
  Process: 71632 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
  Process: 71627 ExecStartPre=/bin/run-parts --verbose /etc/redis/redis-server.pre-up.d (code=exited, status=0/SUCCESS)
 Main PID: 71634 (redis-server)
    Tasks: 3
   Memory: 4.2M
      CPU: 42ms
   CGroup: /system.slice/redis-server.service
           └─71634 /usr/bin/redis-server 0.0.0.0:6379

Nov 15 09:38:19 ep-big systemd[1]: Starting Advanced key-value store...
Nov 15 09:38:19 ep-big run-parts[71627]: run-parts: executing /etc/redis/redis-server.pre-up.d/00_example
Nov 15 09:38:19 ep-big run-parts[71635]: run-parts: executing /etc/redis/redis-server.post-up.d/00_example
Nov 15 09:38:19 ep-big systemd[1]: Started Advanced key-value store.

 

redis auth 패스워드

redis-cli 에서 사용하기 위한 사용자 비밀번호를 찾는다.

$ sudo cat /etc/redis/redis.conf|grep requirepass
# If the master is password protected (using the "requirepass" configuration
requirepass 1234

 

redis-cli and Authentication

redis-cli 구동 및 인증

hsquare@ep-big:/etc/redis$ redis-cli
127.0.0.1:6379> auth 1234
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

 

data file into redis-cli

shell command를 이용해 대용량 파일을 읽어서 redis 서버에 저장한다. 예제 파일의 필드는 ':' 로 구분 되어있고 아래와 같다.

AAA:JAVA
BBB:Python
CCC:Ruby
DDD:C#
EEE:Fultter

cat test.data | awk -F':' '{print " SET \""$1"\" \""$2"\" \n"}'|redis-cli -a 1234 --pipe
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 5

$ redis-cli -a 1234
127.0.0.1:6379> get AAA
"JAVA"

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크