1, first from Linux into the installation directory of Redis
2. Use Redis-cli to start the Redis Client tool under shell command line.
3, select Library name into the library
4.flushdb Refresh the current library
The appropriate commands for Redis:
Examples of commands:
1. Keys/rename/del/exists/move/renamenx:
#在Shell命令行下启动Redis客户端工具.
/> REDIS-CLI
#清空当前选择的数据库 in order to understand the following example.
Redis 127.0.0.1:6379>Flushdb
Ok
#添加String类型的模拟数据.
Redis 127.0.0.1:6379>Set MyKey 2
Ok
Redis 127.0.0.1:6379>set Mykey2 "Hello"
Ok
#添加Set类型的模拟数据.
Redis 127.0.0.1:6379>sadd Mysetkey 1 2 3
(integer) 3
#添加Hash类型的模拟数据.
Redis 127.0.0.1:6379>hset mmtest username "Stephen"
(integer) 1
#根据参数中的模式, gets all the keys in the current database that conform to the pattern, as you can see from the output, that the command does not distinguish between the value type associated with a key when it executes.
Redis 127.0.0.1:6379>Keys my*
1) "Mysetkey"
2) "MyKey"
3) "Mykey2"
#删除了两个Keys.
Redis 127.0.0.1:6379>del MyKey Mykey2
(integer) 2
#查看一下刚刚删除的Key是否还存在, from the returned results, MyKey has indeed been deleted.
Redis 127.0.0.1:6379>exists MyKey
(integer) 0
#查看一下没有删除的Key to compare to the result of the above command.
Redis 127.0.0.1:6379>exists Mysetkey
(integer) 1
#将当前数据库中的mysetkey键移入到ID为1的数据库中, the results can be seen to have moved successfully.
Redis 127.0.0.1:6379>Move Mysetkey 1
(integer) 1
#打开ID为1的数据库.
Redis 127.0.0.1:6379>Select 1
Ok
#查看一下刚刚移动过来的Key是否存在, from the return of the results see already exist.
Redis 127.0.0.1:6379[1]>exists Mysetkey
(integer) 1
#在重新打开ID为0的缺省数据库.
Redis 127.0.0.1:6379[1]>Select 0
Ok
#查看一下刚刚移走的Key是否已经不存在, removed from the returned results.
Redis 127.0.0.1:6379>exists Mysetkey
(integer) 0
#准备新的测试数据.
Redis 127.0.0.1:6379>set MyKey "Hello"
Ok
#将mykey改名为mykey1
Redis 127.0.0.1:6379>Rename MyKey mykey1
Ok
#由于mykey已经被重新命名, fetching again will return nil.
Redis 127.0.0.1:6379>Get MyKey
(nil)
#通过新的键名获取.
Redis 127.0.0.1:6379>Get Mykey1
"Hello"
#由于mykey已经不存在了, so the error message is returned.
Redis 127.0.0.1:6379>Rename MyKey mykey1
(Error) ERR no such key
#为renamenx准备测试key
Redis 127.0.0.1:6379>set Oldkey "Hello"
Ok
Redis 127.0.0.1:6379>set Newkey "World"
Ok
#由于newkey已经存在, so the command failed to execute successfully.
Redis 127.0.0.1:6379>Renamenx Oldkey Newkey
(integer) 0
#查看newkey的值, and found that it was not covered by Renamenx.
Redis 127.0.0.1:6379>Get Newkey
"World"
2. Persist/expire/expireat/ttl:
#为后面的示例准备的测试数据.
Redis 127.0.0.1:6379>set MyKey "Hello"
Ok
#将该键的超时设置为100秒.
Redis 127.0.0.1:6379>expire MyKey
(integer) 1
#通过ttl命令查看一下还剩下多少秒.
Redis 127.0.0.1:6379>TTL MyKey
(integer) 97
#立刻执行persist命令, the time-out key becomes a persisted key, and the timeout for that key is removed.
Redis 127.0.0.1:6379>persist MyKey
(integer) 1
#ttl的返回值告诉我们, the key has not timed out.
Redis 127.0.0.1:6379>TTL MyKey
(integer)-1
#为后面的expire命令准备数据.
Redis 127.0.0.1:6379>del MyKey
(integer) 1
Redis 127.0.0.1:6379>set MyKey "Hello"
Ok
#设置该键的超时被100秒.
Redis 127.0.0.1:6379>expire MyKey
(integer) 1
#用ttl命令看一下当前还剩下多少秒, you can see that there are 96 seconds left in the results.
Redis 127.0.0.1:6379>TTL MyKey
(integer) 96
#重新更新该键的超时时间为20秒, you can see from the return value that the command executed successfully.
Redis 127.0.0.1:6379>expire MyKey
(integer) 1
#再用ttl确认一下, you can see from the results that it was updated.
Redis 127.0.0.1:6379>TTL MyKey
(integer) 17
#立刻更新该键的值 so that its timeout is invalid.
Redis 127.0.0.1:6379>set MyKey "World"
Ok
#从ttl的结果可以看出, after the last command that modified the key was executed, the timeout for that key was not valid.
Redis 127.0.0.1:6379>TTL MyKey
(integer)-1
3. Type/randomkey/sort:
#由于mm键在数据库中不存在, so the command returns none.
Redis 127.0.0.1:6379>type mm
None
#mykey的值是字符串类型, so a string is returned.
Redis 127.0.0.1:6379>type MyKey
String
#准备一个值是set类型的键.
Redis 127.0.0.1:6379>sadd Mysetkey 1 2
(integer) 2
#mysetkey的键是set, so the string set is returned.
Redis 127.0.0.1:6379>type Mysetkey
Set
#返回数据库中的任意键.
Redis 127.0.0.1:6379>Randomkey
"Oldkey"
#清空当前打开的数据库.
Redis 127.0.0.1:6379>Flushdb
Ok
#由于没有数据了, so return nil.
Redis 127.0.0.1:6379>Randomkey
(nil)
Redis's Delete library application (Linux)