Redis的详细资料

Redis的安装

  1. Redis的安装
    Redis是c语言开发的。
    安装redis需要c语言的编译环境。如果没有gcc需要在线安装。yum install gcc-c++

    安装步骤:
    第一步:redis的源码包上传到linux系统。
    第二步:解压缩redis。
    第三步:编译。进入redis源码目录。make
    第四步:安装。make install PREFIX=/usr/local/redis
    PREFIX参数指定redis的安装目录。一般软件安装到/usr目录下

  2. redis的启动
    前端启动:
    在redis的安装目录下直接启动redis-server
    [root@localhost bin]# ./redis-server

    后台启动:
    把/root/redis-3.0.0/redis.conf复制到/usr/local/redis/bin目录下
    [root@localhost redis-3.0.0]# cp redis.conf /usr/local/redis/bin/
    修改配置文件:
    修改配置文件:
    [root@localhost bin]# ./redis-server redis.conf

    查看redis进程:
    [root@localhost bin]# ps aux|grep redis
    root 5190 0.1 0.3 33936 1712 ? Ssl 18:23 0:00 ./redis-server *:6379
    root 5196 0.0 0.1 4356 728 pts/0 S+ 18:24 0:00 grep redis

    Redis-cli
    [root@localhost bin]# ./redis-cli
    默认连接localhost运行在6379端口的redis服务。
    [root@localhost bin]# ./redis-cli -h 192.168.25.153 -p 6379
    -h:连接的服务器的地址

    关闭redis:
    [root@localhost bin]# ./redis-cli shutdown


Redis五种数据类型

String
String:key-value(做缓存)
Redis中所有的数据都是字符串。命令不区分大小写,key是区分大小写的。Redis是单线程的。Redis中不适合保存内容大的数据。
get、set、
incr:加一(生成id)
Decr:减一

demo:

set str abc (其实就是,key=str,values = “abc”)
get str (显示)
del (删这个key的数据) 

Hash
key-fields-values(做缓存)
相当于一个key对于一个map,map中还有key-value
使用hash对key进行归类。
Hset:向hash中添加内容
Hget:从hash中取内容

demo:

--hash是自定义的key
hset hash field a  (存一个value,这值里面存的是一个map  <hash: <filed : a>>)
hkeys hash (看有hash多少个 key)
hvals hash (看hash有多少值)
hget hash field (看hash单个值)
hgetall hash (查看hash所有,值和key)
hdel hash a (删除hash里面key是a的)

List
demo

192.168.25.153:6379> lpush list1 a b c d
(integer) 4
192.168.25.153:6379> lrange list1 0 -1
1) "d"
2) "c"
3) "b"
4) "a"
192.168.25.153:6379> rpush list1 1 2 3 4
(integer) 8
192.168.25.153:6379> lrange list1 0 -1
1) "d"
2) "c"
3) "b"
4) "a"
5) "1"
6) "2"
7) "3"
8) "4"
192.168.25.153:6379> 
192.168.25.153:6379> lpop list1 
"d"
192.168.25.153:6379> lrange list1 0 -1
1) "c"
2) "b"
3) "a"
4) "1"
5) "2"
6) "3"
7) "4"
192.168.25.153:6379> rpop list1
"4"
192.168.25.153:6379> lrange list1 0 -1
1) "c"
2) "b"
3) "a"
4) "1"
5) "2"
6) "3"
192.168.25.153:6379> 

在这里感谢黑马资料,是参考黑马资料

猜你喜欢

转载自blog.csdn.net/yuhaifei_123/article/details/79145754