码迷,mamicode.com
首页 > 数据库 > 详细

【数据库】Redis基础知识整理

时间:2021-06-02 20:44:24      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:https   alice   star   returns   union   members   nio   sub   ash   

SET赋值

SET server:name "fido"

GET server:name

=> "fido"

EXISTS判断值是否存在

EXISTS server:name

=> 1

EXISTS server:blabla

=> 0

INCR增加DECR减少

原子性,同时发生的事务不会影响正确结果

INCR a

=> 1

DECR a

=> 0

INCRBY a 100

=> 100

DECRBY a 100

=> 0

DEL删除(删除成功返回1,不存在返回0)

SET a 100

GET a

=> "100"

DEL a

INCR a

=> 1

EXPIRE TTL过期(PEXPIRE PTTL毫秒过期)

EXPIRE a 120 (expired in 120s)

TTL a (returns the number of seconds until it will be deleted)

(-2 shows it has expired and -1 shows permanent)

SET a 100 EX 5

PERSIST永久

PERSIST a

TTL a

=> -1

列表list操作

RPUSH puts the new element at the end of the list.

RPUSH friends "Alice"

LPUSH puts the new element at the start of the list.

LPUSH friends "Bob"

LRANGE subset of the list 类似substring

LRANGE friends 0 -1 => 1) "Sam", 2) "Alice", 3) "Bob"

LRANGE friends 0 1 => 1) "Sam", 2) "Alice"

LRANGE friends 1 2 => 1) "Alice", 2) "Bob"

LPOP removes the first element from the list and returns it.

RPOP removes the last element from the list and returns it.

LLEN return length of the list.

集合set操作

SADD adds the given member to the set 可多个参数同时添加,0存在 1不存在

SREM removes the given member from the set 1存在,0不存在

SISMEMBER tests if the given value is in the set 1存在,0不存在

SMEMBERS returns a list of all the members of this set.

SUNION 合并两个或多个,返回一个包含所有元素的集合,相同项只会保留一个

SPOP 随机删除元素 可以设置个数

SADD letters a b c d e f => 6

SPOP letters 2 => 1) "c" 2) "a"

SRANDMEMBER 返回随机元素 可以设置个数

Sorted Set排列集合

ZADD ZRANGE…

Hash哈希

HSET 添加元素 HMSET 添加多个元素

HSET user:1000 name "John Smith"

HGET 获得元素 HGETALL 全部元素

HGET user:1001 name => "Mary Jones"

HGETALL user:1000 (键和值会分开输出?)

=> 1) "name" 2) "John Smith" 3) "email" 4) "john.smith@example.com" 5) "password" 6) "s3cret"

Numerical value操作

HSET user:1000 visits 10 HINCRBY user:1000 visits 1 => 11 HINCRBY user:1000 visits 10 => 21 HDEL user:1000 visits HINCRBY user:1000 visits 1 => 1

Hash的全部操作

Check out the following links to continue learning about Redis.

【数据库】Redis基础知识整理

标签:https   alice   star   returns   union   members   nio   sub   ash   

原文地址:https://www.cnblogs.com/Zeiion/p/14839254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!