Redis安装及key、string操作

安装

在官网下载的数据包上传到Linux家目录

Install Redis from Source | Redis

Redis安装及key、string操作_第1张图片

wget https://download.redis.io/redis-stable.tar.gz
tar -xzvf redis-stable.tar.gz
cd redis-stable
make

 编译后出现以下提示后输入make install

Redis安装及key、string操作_第2张图片

出现以下提示则安装成功

Redis安装及key、string操作_第3张图片

输入redis-sever启动

Redis安装及key、string操作_第4张图片

服务启动后,新开个标签页,输入redis-cli -p 6379开始使用

Redis安装及key、string操作_第5张图片

Key操作

127.0.0.1:6379> EXPIRE mystr1 15
(integer) 1
127.0.0.1:6379> ttl mystr1
(integer) 12

127.0.0.1:6379> ttl mystr1
(integer) 1
127.0.0.1:6379> ttl mystr1
(integer) -2
127.0.0.1:6379> get mystr1
(nil)

127.0.0.1:6379> exists mystr1
(integer) 0
127.0.0.1:6379> exists mystr2
(integer) 1

127.0.0.1:6379> RANDOMKEY
"mystr5"
127.0.0.1:6379> RANDOMKEY
"mystr4"
127.0.0.1:6379> RANDOMKEY
"mystr3"
127.0.0.1:6379> RANDOMKEY
"mystr2"
127.0.0.1:6379> RANDOMKEY
"mystr4"
127.0.0.1:6379> RANDOMKEY
"mystr5"
127.0.0.1:6379> RANDOMKEY
"mystr4"

127.0.0.1:6379> RENAME mystr2 mystr02
OK
127.0.0.1:6379> RENAMENX mystr02 mystr2
(integer) 1
127.0.0.1:6379> GET mystr2
"2"

127.0.0.1:6379> dump mystr2
"\x00\xc0\x02\x0b\x00\xe6}\r\xcf\x05K\x97B"

String操作

127.0.0.1:6379> set mystr1 01
OK

127.0.0.1:6379> get mystr1
"01"

127.0.0.1:6379> set mystr3 1234567890
OK


127.0.0.1:6379> get mystr3
"1234567890"

127.0.0.1:6379> GETRANGE mystr3 3 4
"45"

127.0.0.1:6379> SETBIT mystr3 6 1
(integer) 0
127.0.0.1:6379> GET mystr3
"3234567890"

127.0.0.1:6379> MGET mystr1 mystr2
1) "01"
2) "2"

127.0.0.1:6379> MSET mystr4 44 mystr5 055
OK
127.0.0.1:6379> MGET mystr4 mystr5
1) "44"
2) "055"

127.0.0.1:6379> SETNX mystr4 11
(integer) 0
127.0.0.1:6379> GET mystr4
"44"

127.0.0.1:6379> SETRANGE mystr3 4 aaa
(integer) 10
127.0.0.1:6379> GET mystr3
"3234aaa890"

127.0.0.1:6379> STRLEN mystr3
(integer) 10

127.0.0.1:6379> INCR mystr4
(integer) 45
127.0.0.1:6379> GET mystr4
"45"

127.0.0.1:6379> DECRBY mystr4 2
(integer) 43
127.0.0.1:6379> GET mystr4
"43"

你可能感兴趣的:(redis,java,数据库)