尝试使用Mac上的Redis

安装Redis

你可以通过Homebrew来安装。

$ brew install redis
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/redis-2.8.13.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-2.8.13.mavericks.bottle.tar.gz
==> Caveats
To have launchd start redis at login:
    ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
    redis-server /usr/local/etc/redis.conf
==> Summary
?  /usr/local/Cellar/redis/2.8.13: 10 files, 1.3M

启动Redis服务器

您可以使用以下命令来启动Redis。

$ redis-server
[86861] 19 Jul 00:04:43.047 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[86861] 19 Jul 00:04:43.049 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 2.8.13 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 86861
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

[86861] 19 Jul 00:04:43.055 # Server started, Redis version 2.8.13
[86861] 19 Jul 00:04:43.055 * The server is now ready to accept connections on port 6379

连接到Redis

要连接启动的Redis,可以使用以下命令。

$ redis-cli
127.0.0.1:6379>

设置和获取值到Redis

设定命令

要在Redis中设置值,可以使用set命令。

设定[key]为[value]

127.0.0.1:6379> set test-key test
OK

获取命令

要获取在Redis中设置的值,可以使用get命令。

获取[key]

127.0.0.1:6379> get test-key
"test"

删除命令

要删除在Redis中设置的键,您需要使用del命令。

127.0.0.1:6379> del test-key
(integer)1

其他

删除Redis中注册的所有键。

$ redis-cli --raw -n 0 KEYS "*" | xargs redis-cli -n 0 DEL
bannerAds