redis 学习

 

redis 安装:

brew install redis

 

启动redis:

/usr/local/opt/redis/bin/redis-server /usr/local/etc/redis.conf

 

String

127.0.0.1:6379>
127.0.0.1:6379> set name "ruanjiyong"
OK
127.0.0.1:6379> get name
"ruanjiyong"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)

Hash

127.0.0.1:6379> hset myhashkey xk 35 yn 36 yy 6
(integer) 3
127.0.0.1:6379> get myhashkey     //hash 不能直接用get,要用hget
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> hget myhashkey    //hget的时候,不仅要指定key,还需要指定object中fieldname
(error) ERR wrong number of arguments for 'hget' command
127.0.0.1:6379> hget myhashKey xk
(nil)
127.0.0.1:6379> hget myhashkey xk
"35"
127.0.0.1:6379> hget myhashkey yn
"36"
127.0.0.1:6379> hget myhashkey yy
"6"
127.0.0.1:6379> hset myhashkey xk 36
(integer) 0
127.0.0.1:6379> hget myhashkey xk
"36"

List

127.0.0.1:6379> lpush mylist rxk
(integer) 1
127.0.0.1:6379> lpush mylist rjy  //从头部加入元素
(integer) 2127.0.0.1:6379> llen mylist  //查看元素个数
(integer) 2127.0.0.1:6379> lrange mylist 0 5 //范围检索
1) "rjy"
2) "rxk"
127.0.0.1:6379> lset mylist 1 cyn  //重新设置某个index位置的值
OK
127.0.0.1:6379> lrange mylist 0 5  
1) "rjy"
2) "cyn"
127.0.0.1:6379> lpop mylist  //从头部获取元素并删除
"rjy"
127.0.0.1:6379> lpop mylist
"cyn"
127.0.0.1:6379> llen mylist
(integer) 0

Set

127.0.0.1:6379> sadd myset rjy
(integer) 1
127.0.0.1:6379> sadd myset rjy
(integer) 0127.0.0.1:6379> smembers myset
1) "rjy"
127.0.0.1:6379> sadd myset rxk
(integer) 1
127.0.0.1:6379> smembers myset
1) "rjy"
2) "rxk"
127.0.0.1:6379> sadd hisset cyn
(integer) 1
127.0.0.1:6379> smembers hisset
1) "cyn"
127.0.0.1:6379> smove myset hisset rjy
(integer) 1
127.0.0.1:6379> smembers myset
1) "rxk"
127.0.0.1:6379> smembers hisset
1) "rjy"
2) "cyn"

 

上一篇:idea数据库连接时区错误解决方法


下一篇:MyBaits异常:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than o