3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

気軽にRedisに触れてみる

Posted at

環境

Docker for MacがインストールされているMac OS

Dokcer Hubからイメージを取得

$ docker image pull redis:latest
  • imageは省略可

取得したイメージからDockerコンテナの立ち上げ

$ docker container run --name test-redis -d redis
  • containerは省略可能

コンテナのプロセスを確認

$ docker contatiner ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
0d84da96b73b        redis               "docker-entrypoint.s…"   3 seconds ago       Up 4 seconds        6379/tcp            test-redis
  • containerは省略可能

クライアント用コンテナにログイン

$ docker container run -it --name test-redis-cli --link test-redis:redis --rm redis redis-cli -h redis -p 6379
redis:6379> scan 0 match *
1) "0"
2) (empty list or set)
  • containerは省略可能
  • プロセスを確認すると、ログイン中はコンテナが2つ立ち上がっている
$ docker container ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES
7b20f5d32830        redis               "docker-entrypoint.s…"   8 seconds ago        Up 8 seconds        6379/tcp            test-redis-cli
0d84da96b73b        redis               "docker-entrypoint.s…"   About a minute ago   Up About a minute   6379/tcp            test-redis

SET, GET

redis:6379> set foo bar
OK
redis:6379> get foo
"bar"

INCR, DECR

redis:6379> set foo 10
OK
redis:6379> incr foo
(integer) 11
redis:6379> incr foo
(integer) 12
redis:6379> decr foo
(integer) 11

DEL

redis:6379> set foo bar
OK
redis:6379> get foo
"bar"
redis:6379> del foo
(integer) 1
redis:6379> get foo
(nil)

SCAN

redis:6379> set A 10
OK
redis:6379> set B 11
OK
redis:6379> set C 12
OK
redis:6379> scan 0 match *
1) "0"
2) 1) "C"
   2) "B"
   3) "A"
  • keys *は良くない

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?