redis学习笔记

1.SET key value ================set  name zhangsan


2.GET key ====================get name


3.INCR key 


key对应的value必须为数字,否则报错。

调用INCR后,自动加1


4.expire key   设置生存时间,ttl key 查看剩余的生存时间


.list

 RPUSHLPUSHLLENLRANGELPOPand RPOP.

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

RPUSH friends "Tom"RPUSH friends "Bob"

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

LRANGE gives subset of the list.
LRANGE friends -1=> ["Sam","Tom","Bob"]
    LRANGE friends 1=> ["Sam","Tom"]
    LRANGE friends 2=> ["Tom","Bob"]LLEN returns the current length of the list.LLEN friends=> 3LPOP removes the first element from the list and returns it.LPOP friends=> "Sam"RPOP removes the last element from the list and returns it.RPOP friends=> "Bob"


6.set

 SADDSREMSISMEMBERSMEMBERS and SUNION.


SADD adds the given value to the set.

SADD superpowers "flight"SADD superpowers "x-ray vision"SADD superpowers "reflexes"

SREM removes the given value from the set.

SREM superpowers "reflexes"

SISMEMBER tests if the given value is in the set.

SISMEMBER superpowers "flight"=> true
    SISMEMBER superpowers "reflexes"=> false

SMEMBERS returns list of all the members of this set.

SMEMBERS superpowers=> ["flight","x-ray vision"]

SUNION combines two or more sets and returns the list of all elements.

SADD birdpowers "pecking"SADD birdpowers "flight"SUNION superpowers birdpowers=> ["flight","x-ray vision","pecking"]



7.zset


The last data structure which Redis supports is the sorted set. It is similar to regular set, but now each value has an associated score. This score is used to sort the elements in the set.


ZADD hackers 1940 "Alan Kay"ZADD hackers 1953 "Richard Stallman"ZADD hackers 1965 "Yukihiro Matsumoto"ZADD hackers 1916 "Claude Shannon"ZADD hackers 1969 "Linus Torvalds"ZADD hackers 1912 "Alan Turing"

In these examples, the scores are years of birth and the values are the names of famous hackers.

ZRANGE hackers 4=> ["Alan Kay","Richard Stallman","Yukihiro Matsumoto"]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值