Redis菜鸟教程(一)

1下载安装后启动客户端调试:

cd到安装路径

cd C:\Program Files\Redis

redis-cli.exe -h 127.0.0.1 -p 6379

密码修改:修改配置文件“redis.windows-service.conf

################################## SECURITY ##################

# Require clients to issue AUTH <PASSWORD> before processing any other

# commands. This might be useful in environments in which you do not trust

# others with access to the host running redis-server.

#

# This should stay commented out for backward compatibility and because most

# people do not need auth (e.g. they run their own servers).

#

# Warning: since Redis is pretty fast an outside user can try up to

# 150k passwords per second against a good box. This means that you should

# use a very strong password otherwise it will be very easy to break.

#

# requirepass foobared

requirepass 密码

修改新密码需要重启服务,认证密码

C:\Program Files\Redis>redis-server –service-start

[15236] 17 Mar 08:40:19.111 # Redis service successfully started.

C:\Program Files\Redis>redis-cli.exe -h 127.0.0.1 -p 6379

127.0.0.1:6379> keys *

(error) NOAUTH Authentication required.

127.0.0.1:6379> auth food

OK ————-认证成功

2查看所有key

《Redis菜鸟教程(一)》 查看所有key

3判断 key的类型

《Redis菜鸟教程(一)》 image.png

4 string 类型数据

1) 设置值set ,取值get

《Redis菜鸟教程(一)》 image.png

  1. 修改key的名字

《Redis菜鸟教程(一)》 image.png

3)删除key

《Redis菜鸟教程(一)》 image.png

4) 查看key是否存在

《Redis菜鸟教程(一)》 image.png

5)设置key的过期时间,以秒计算 EXPIRE KEY Second

《Redis菜鸟教程(一)》 image.png

6)以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。

PTTL key以毫秒为单位返回 key 的剩余的过期时间

《Redis菜鸟教程(一)》 image.png

5 LIST列表数据类型

6 哈希数据

6.1 HGETALL key 获取在哈希表中指定 key 的所有字段和值

《Redis菜鸟教程(一)》 image.png

6.2 HSET key field value 将哈希表 key 中的字段 field 的值设为 value 。

6.3 设置哈希的过期时间

《Redis菜鸟教程(一)》 image.png
《Redis菜鸟教程(一)》 image.png

哈希 key 设置过期时间后,若哈希值由更改,过期时间原先设置的剩余过期时间不变。若想改变过期时间,需要重新设置。key过期后,Redis中将key自动从Redis数据库中删除。若想继续使用,可以重新创建。

    原文作者:凌雲木
    原文地址: https://www.jianshu.com/p/48f0ee9846c3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞