Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理。
Redis用途: 数据库缓存登录redis(redis默认的数据库有16) 1. 无密码 redis-cli -h 127.0.0.1 -p 6379 2. 有密码 redis-cli -h 127.0.0.1 -p 6379 -a 123456 3. 打开redis终端 redis-cli 4. 选择指定的数据库,默认的数据库有16,mongodb是3个:admin/local/test select index
字符串 set name #保存 get name #获得 type name #查看类型 keys * clear
哈希(Hash),Redis hash是一个string类型的field和value的映射表,hash特别适合用于存储对象 hmset key attr1 value1 attr2 value2 hmget key attr1 hgetall key
列表(List) lpush key value1 value2 value3 llen key lindex key index lrange key start stop #stop可以为-1,到末尾的意思
Set是string类型的无序集合。集合成员是唯一的,这就意味着集合中不能出现重复的数据。 sadd key value #sadd idcard 100 sadd key value1 value2 vlaue3 scard key sscan key cursor [MATCH pattern] [COUNT count]
exists key #检查key是否存在
注1:不需要记得API的方法,只需要查redis命令