Redis(二)操作命令
127.0.0.1值本机IP 6379指端口号
key
EXISTS:查询key值是否存在,返回值为一个Integer类型
1 如果key存在
0 如果key不存在
127.0.0.1:6379> set fff hello #设置fff为"hello"
OK #添加成功
127.0.0.1:6379> exists ff1 #查询key为ff1
(integer) 0#不存在
127.0.0.1:6379> EXISTS fff
(integer) 1#存在
EXPIRE:设置key的过期时间(秒),超过时间后,将会自动删除该key。
1 如果成功设置过期时间。
0 如果key不存在或者不能设置过期时间。
127.0.0.1:6379> get fff
"hello"
127.0.0.1:6379> EXPIRE fff 10 #设置过期时间为10秒
(integer) 1 #设置成功
127.0.0.1:6379> get fff #查看
"hello"
127.0.0.1:6379> get fff #10秒过后查看
(nil) #不存在
查找所有符合给定模式pattern(正则表达式)的 key 。
时间复杂度为O(N),N为数据库里面key的数量。
支持的正则表达模式:
h?llo 匹配 hello, hallo 和 hxllo
h*llo 匹配 hllo 和 heeeello
Redis(二)操作命令
127.0.0.1值本机IP 6379指端口号
key
EXISTS:查询key值是否存在,返回值为一个Integer类型
1 如果key存在
0 如果key不存在
127.0.0.1:6379> set fff hello #设置fff为"hello"
OK #添加成功
127.0.0.1:6379> exists ff1 #查询key为ff1
(integer) 0#不存在
127.0.0.1:6379> EXISTS fff
(integer) 1#存在
EXPIRE:设置key的过期时间(秒),超过时间后,将会自动删除该key。
1 如果成功设置过期时间。
0 如果key不存在或者不能设置过期时间。
127.0.0.1:6379> get fff
"hello"
127.0.0.1:6379> EXPIRE fff 10 #设置过期时间为10秒
(integer) 1 #设置成功
127.0.0.1:6379> get fff #查看
"hello"
127.0.0.1:6379> get fff #10秒过后查看
(nil) #不存在
查找所有符合给定模式pattern(正则表达式)的 key 。
时间复杂度为O(N),N为数据库里面key的数量。
支持的正则表达模式:
h?llo 匹配 hello, hallo 和 hxllo
h*llo 匹配 hllo 和 heeeello
发布评论