<div class="single-title">Redis启动多端口,运行多实例
<div class="single-title">Redis启动多端口,运行多实例
使用redis在同一台机器上,启用多个端口,实现多个实例,完成集群的模拟实现。
redis默认启动端口为6379,我们可以使用 --port 来指定多个端口,如下,在linux终端命令:
查看启动的redis实例:
使用其中一个redis实例:
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">><span class="pln"><span class="pln"> keys <span class="str"><span class="str">'*'<span class="pln"><span class="pln"><span class="pun"><span class="pun">(<span class="pln"><span class="pln">empty list <span class="kwd"><span class="kwd">or<span class="pln"><span class="pln"> <span class="kwd"><span class="kwd">set<span class="pun"><span class="pun">)<span class="pln"><span class="pln">
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">><span class="pln"><span class="pln"> <span class="kwd"><span class="kwd">set<span class="pln"><span class="pln"> foo hello
OK
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">><span class="pln"><span class="pln"> keys <span class="str"><span class="str">'*'<span class="pln"><span class="pln">
<span class="lit"><span class="lit">1<span class="pun"><span class="pun">)<span class="pln"><span class="pln"> <span class="str"><span class="str">"foo"<span class="pln"><span class="pln">
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">><span class="pln"><span class="pln"> <span class="kwd"><span class="kwd">set<span class="pln"><span class="pln"> foo1 hello
OK
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">><span class="pln"><span class="pln"> keys <span class="str"><span class="str">'*'<span class="pln"><span class="pln">
<span class="lit"><span class="lit">1<span class="pun"><span class="pun">)<span class="pln"><span class="pln"> <span class="str"><span class="str">"foo1"<span class="pln"><span class="pln">
<span class="lit"><span class="lit">2<span class="pun"><span class="pun">)<span class="pln"><span class="pln"> <span class="str"><span class="str">"foo"<span class="pln"><span class="pln">
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">><span class="pln"><span class="pln"> <span class="kwd"><span class="kwd">get<span class="pln"><span class="pln"> foo1
<span class="str"><span class="str">"hello"<span class="pln"><span class="pln">
<span class="lit"><span class="lit">127.0<span class="pun"><span class="pun">.<span class="lit"><span class="lit">0.1<span class="pun"><span class="pun">:<span class="lit"><span class="lit">6380<span class="pun"><span class="pun">>
完成了redis多端口,多实例的部署和使用了
redis 的关闭如下:
指定端口实例