Skip to content

Mac OS安装Redis

  1. 下载Redis
    shell
    brew install redis
  2. 启动Redis
    shell
    brew services start redis
  3. 验证安装
    shell
    redis-cli ping
    如果它响应“PONG”,则 Redis 运行正常。
  4. 连接Redis(进入redis命令行界面)
    shell
    redis-cli
  5. 关闭Redis
    shell
    redis-cli shutdown
  6. 查看Redis状态
    shell
    redis-cli info
  7. 查看Redis进程
    shell
    ps aux | grep redis
  8. 查看Redis版本
    shell
    redis-server --version

进入redis命令行界面后的基本命令

  1. 进入redis-cli
    shell
    redis-cli
  2. 设置键值对
    shell
    set key value
  3. 获得值
    shell
    get key
  4. 删除键
    shell
    del key
  5. 检查键是否存在
    shell
    exists key
  6. 设置带有过期时间的键值对(以秒为单位)
    shell
    SETEX key seconds value
  7. 设置带有过期时间的键值对(以毫秒为单位)
    shell
    PSETEX key milliseconds value

8.设置键的过期时间(以秒为单位)

shell
EXPIRE key seconds
  1. 设置键的过期时间(以毫秒为单位)
    shell
    PEXPIRE key milliseconds
  2. 移除键的过期时间
    shell
    PERSIST key
  3. 获取所有匹配的键
    shell
    KEYS pattern
  4. 查看所有键
shell
keys *
  1. 查看键的类型
shell
type key
  1. 查看键的过期时间
shell
ttl key
  1. 退出
    shell
    exit

Redis数据类型

  1. String
  2. Hash
  3. List
  4. Set
  5. Sorted Set

Released under the MIT License.