Redis
安装Redis环境
要在 Ubuntu 上安装 Redis,打开终端,然后输入以下命令:
$sudo apt-get update $sudo apt-get install redis-server
这将在您的计算机上安装Redis
启动 Redis
$redis-server
查看 redis 是否还在运行
$redis-cli
这将打开一个 Redis 提示符,如下图所示:
redis 127.0.0.1:6379>
在上面的提示信息中:127.0.0.1 是本机的IP地址,6379是 Redis 服务器运行的端口。现在输入 PING 命令,如下图所示:
redis 127.0.0.1:6379> ping PONG
这说明现在你已经成功地在计算机上安装了 Redis。
rico@rico-virtual-machine:~$ ps -ef |grep redis redis 4262 1 0 09:14 ? 00:00:02 /usr/bin/redis-server 127.0.0.1:6379 rico 5614 5061 0 09:38 pts/0 00:00:00 grep --color=auto redis rico@rico-virtual-machine:~$ redis-cli 127.0.0.1:6379> set name jack OK 127.0.0.1:6379> get name "jack" 127.0.0.1:6379> set name tom OK 127.0.0.1:6379> get name "tom" 127.0.0.1:6379> set age 22 OK 127.0.0.1:6379> keys * 1) "age" 2) "name" 127.0.0.1:6379>
127.0.0.1:6379> help set SET key value [EX seconds] [PX milliseconds] [NX|XX] summary: Set the string value of a key since: 1.0.0 group: string 127.0.0.1:6379> set name Rain ex 3 OK 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> set name Rain ex 3 OK 127.0.0.1:6379> get name "Rain" 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> set name sss px 3000 OK 127.0.0.1:6379> get name "sss" 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> get name (nil) 127.0.0.1:6379> set name sssfff nx OK 127.0.0.1:6379> get name "sssfff" 127.0.0.1:6379> set name sssffdddf nx (nil) 127.0.0.1:6379> get name "sssfff" 127.0.0.1:6379> set name sssff11f xx OK 127.0.0.1:6379> get name "sssff11f" 127.0.0.1:6379> set name sssff11f2 xx OK 127.0.0.1:6379> get name "sssff11f2" 127.0.0.1:6379> set age1 df2 xx (nil) 127.0.0.1:6379> keys * 1) "age" 2) "name"
1 rico@rico-virtual-machine:~$ redis-cli 2 127.0.0.1:6379> hset info name jack 3 (integer) 1 4 127.0.0.1:6379> hset info age 12 5 (integer) 1 6 127.0.0.1:6379> hset info id stu110 7 (integer) 1 8 127.0.0.1:6379> hget info 9 (error) ERR wrong number of arguments for 'hget' command 10 127.0.0.1:6379> hget info name 11 "jack" 12 127.0.0.1:6379> hget info age 13 "12" 14 127.0.0.1:6379> hget info id 15 "stu110" 16 127.0.0.1:6379> hkeys info 17 1) "name" 18 2) "age" 19 3) "id" 20 127.0.0.1:6379> hmget info name age 21 1) "jack" 22 2) "12" 23 127.0.0.1:6379> help hmset 24 25 HMSET key field value [field value ...] 26 summary: Set multiple hash fields to multiple values 27 since: 2.0.0 28 group: hash 29 30 127.0.0.1:6379> hmset info name tom age 33 hobbies football 31 OK 32 127.0.0.1:6379> hkeys info 33 1) "name" 34 2) "age" 35 3) "id" 36 4) "hobbies" 37 127.0.0.1:6379> hmget info id name age 38 1) "stu110" 39 2) "tom" 40 3) "33" 41 127.0.0.1:6379> hmget info id name age hobbies 42 1) "stu110" 43 2) "tom" 44 3) "33" 45 4) "football" 46 127.0.0.1:6379> hgetall info 47 1) "name" 48 2) "tom" 49 3) "age" 50 4) "33" 51 5) "id" 52 6) "stu110" 53 7) "hobbies" 54 8) "football" 55 127.0.0.1:6379> hlen info 56 (integer) 4 57 127.0.0.1:6379> hvals info 58 1) "tom" 59 2) "33" 60 3) "stu110" 61 4) "football" 62 127.0.0.1:6379> hkeys info 63 1) "name" 64 2) "age" 65 3) "id" 66 4) "hobbies" 67 127.0.0.1:6379> hexists info id 68 (integer) 1 69 127.0.0.1:6379> hdel info id 70 (integer) 1 71 127.0.0.1:6379> hexists info id 72 (integer) 0 73 127.0.0.1:6379> hdel info id 74 (integer) 0 75 127.0.0.1:6379>
https://www.cnblogs.com/alex3714/articles/6217453.html