$ redis-cli -c -p 7000 redis 127.0.0.1:7000> set foo bar -> Redirected to slot [12182] located at 127.0.0.1:7002 OK redis 127.0.0.1:7002> set hello world -> Redirected to slot [866] located at 127.0.0.1:7000 OK redis 127.0.0.1:7000> get foo -> Redirected to slot [12182] located at 127.0.0.1:7002 "bar" redis 127.0.0.1:7000> get hello -> Redirected to slot [866] located at 127.0.0.1:7000 "world"
ZADD key [NX|XX] [CH] [INCR] score member [score member ...] 从3.0.2版本开始,增加以下选项:
XX: Only update elements that already exist. Never add elements.
NX: Don’t update already existing elements. Always add new elements.
CH: Modify the return value from the number of new elements added, to the total number of elements changed (CH is an abbreviation of changed). Changed elements are new elements added and elements already existing for which the score was updated. So elements specified in the command line having the same score as they had in the past are not counted. Note: normally the return value of ZADD only counts the number of new elements added.
INCR: When this option is specified ZADD acts like ZINCRBY. Only one score-element pair can be specified in this mode.
常见实现方式:在数据表增加version字段,每次事务开始时将取出version字段值,而后在更新数据的同时version增加1(如:update xxx set data=#{data},version=version+1 where version=#{version}),如没有数据被更新,那么说明数据由其它的事务进行了更新,此时就可以判断当前事务所操作的历史快照数据。
悲观锁
和乐观锁相比,悲观锁则是一把真正的锁了,它通过SQL语句“select for update”锁住select出的那批数据,这时如果其他事务来更新这批数据时会等待。
scrub-anchor "com.apple/*" nat-anchor "com.apple/*" rdr-anchor "com.apple/*" rdr on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080 dummynet-anchor "com.apple/*" anchor "com.apple/*" load anchor "com.apple" from "/etc/pf.anchors/com.apple"
-a, --all Show all images (default hides intermediate images) --digests Show digests -f, --filter=[] Filter output based on conditions provided --format Pretty-print images using a Go template --help Print usage --no-trunc Don't truncate output -q, --quiet Only show numeric IDs
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
-a, --attach=[] Attach to STDIN, STDOUT or STDERR --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight Block IO (relative weight), between 10 and 1000 --blkio-weight-device=[] Block IO weight (relative device weight) --cpu-shares CPU shares (relative weight) --cap-add=[] Add Linux capabilities --cap-drop=[] Drop Linux capabilities --cgroup-parent Optional parent cgroup for the container --cidfile Write the container ID to the file --cpu-period Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota Limit CPU CFS (Completely Fair Scheduler) quota --cpuset-cpus CPUs in which to allow execution (0-3, 0,1) --cpuset-mems MEMs in which to allow execution (0-3, 0,1) -d, --detach Run container in background and print container ID --detach-keys Override the key sequence for detaching a container --device=[] Add a host device to the container --device-read-bps=[] Limit read rate (bytes per second) from a device --device-read-iops=[] Limit read rate (IO per second) from a device --device-write-bps=[] Limit write rate (bytes per second) to a device --device-write-iops=[] Limit write rate (IO per second) to a device --disable-content-trust=true Skip image verification --dns=[] Set custom DNS servers --dns-opt=[] Set DNS options --dns-search=[] Set custom DNS search domains -e, --env=[] Set environment variables --entrypoint Overwrite the default ENTRYPOINT of the image --env-file=[] Read in a file of environment variables --expose=[] Expose a port or a range of ports --group-add=[] Add additional groups to join -h, --hostname Container host name --help Print usage -i, --interactive Keep STDIN open even if not attached --ip Container IPv4 address (e.g. 172.30.100.104) --ip6 Container IPv6 address (e.g. 2001:db8::33) --ipc IPC namespace to use --isolation Container isolation level --kernel-memory Kernel memory limit -l, --label=[] Set meta data on a container --label-file=[] Read in a line delimited file of labels --link=[] Add link to another container --log-driver Logging driver for container --log-opt=[] Log driver options -m, --memory Memory limit --mac-address Container MAC address (e.g. 92:d0:c6:0a:29:33) --memory-reservation Memory soft limit --memory-swap Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness=-1 Tune container memory swappiness (0 to 100) --name Assign a name to the container --net=default Connect a container to a network --net-alias=[] Add network-scoped alias for the container --oom-kill-disable Disable OOM Killer --oom-score-adj Tune host's OOM preferences (-1000 to 1000) -P, --publish-all Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host --pid PID namespace to use --privileged Give extended privileges to this container --read-only Mount the container's root filesystem as read only --restart=no Restart policy to apply when a container exits --rm Automatically remove the container when it exits --security-opt=[] Security Options --shm-size Size of /dev/shm, default value is 64MB --sig-proxy=true Proxy received signals to the process --stop-signal=SIGTERM Signal to stop a container, SIGTERM by default -t, --tty Allocate a pseudo-TTY --tmpfs=[] Mount a tmpfs directory -u, --user Username or UID (format: <name|uid>[:<group|gid>]) --ulimit=[] Ulimit options --uts UTS namespace to use -v, --volume=[] Bind mount a volume --volume-driver Optional volume driver for the container --volumes-from=[] Mount volumes from the specified container(s) -w, --workdir Working directory inside the container
IMAGE可以为镜像名或者镜像ID。 示例:
1 2
sudo docker run -t -i ouruser/sinatra:v2 /bin/bash sudo docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done" #守护态运行
在执行 docker run 的时候如果添加 –rm 标记,则容器在终止后会立刻删除。注意,–rm 和 -d 参数不能同时使用。
docker logs
说明:获取容器输出的信息,适用于守护态运行docker容器。
1 2 3 4 5 6 7 8 9 10 11
[root@localhost ~]# docker logs --help
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
-f, --follow Follow log output --help Print usage --since Show logs since timestamp -t, --timestamps Show timestamps --tail=all Number of lines to show from the end of the logs
--help Print usage -t, --time=10 Seconds to wait for stop before killing the container
docker attach
说明:在使用 -d 参数时,容器启动后会进入后台。 某些时候需要进入容器进行操作就可以用它。
1 2 3 4 5 6 7 8 9 10
[root@localhost ~]# docker attach --help
Usage: docker attach [OPTIONS] CONTAINER
Attach to a running container
--detach-keys Override the key sequence for detaching a container --help Print usage --no-stdin Do not attach STDIN --sig-proxy=true Proxy all received signals to the process
-a, --all Show all containers (default shows just running) -f, --filter=[] Filter output based on conditions provided --format Pretty-print containers using a Go template --help Print usage -l, --latest Show the latest created container (includes all states) -n=-1 Show n last created containers (includes all states) --no-trunc Don't truncate output -q, --quiet Only display numeric IDs -s, --size Display total file sizes
示例:
1
[root@localhost ~]# docker ps -a
docker export
说明:导出本地某个容器为快照文件
1 2 3 4 5 6 7 8
[root@localhost ~]# docker export --help
Usage: docker export [OPTIONS] CONTAINER
Export a container's filesystem as a tar archive
--help Print usage -o, --output Write to a file, instead of STDOUT
-f, --force Force the removal of a running container (uses SIGKILL) --help Print usage -l, --link Remove the specified link -v, --volumes Remove the volumes associated with the container
示例:
1
[root@localhost ~]# docker rm $(docker ps -a -q) #清理所有处于终止状态的容器
docker rmi
说明:移除本地镜像,移出前需要先移除到镜像对应的容器。
1 2 3 4 5 6 7 8 9
[root@localhost ~]# docker rmi --help
Usage: docker rmi [OPTIONS] IMAGE [IMAGE...]
Remove one or more images
-f, --force Force removal of the image --help Print usage --no-prune Do not delete untagged parents
Return low-level information on a container or image
-f, --format Format the output using the given go template --help Print usage -s, --size Display total file sizes if the type is container --type Return JSON for specified type, (e.g image or container)
docker port
说明:来查看当前映射的端口配置,也可以查看到绑定的地址。
1 2 3 4 5 6 7
[root@localhost ~]# docker port --help
Usage: docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]]
List port mappings or a specific mapping for the CONTAINER