我们在使用redis的时候可能一般都是用于缓存等服务。

要查询现在redis的服务是什么状态,可以用以下方式:

redis-cli 命令:
redis-cli [-h localhost] [-p 6379] monitor

Dump all the received requests in real time;
监控host为localhost,端口为6380,redis的连接及读写操作

使用这个命令会输出如下信息(实时请求):
+OK
+1289800615.808225 "monitor"
+1289800615.839079 "GET" "name"
+1289800615.853694 "PING"
+1289800615.853783 "PING"
+1289800615.854646 "PING"
+1289800615.854974 "PING"
+1289800615.857693 "PING"
+1289800615.866862 "PING"
+1289800615.871944 "PING"

redis-cli info 命令:
redis-cli info

此命令打印出当前REIDS服务的全部状态信息

三、 showlog功能
Redis 有一个实用的slowlog功能,正如你可以猜到的,可以让你检查运行缓慢的查询。

Slowlog 将会记录运行时间超过Y微秒的最后X条查询. X 和 Y 可以在 redis.conf 或者在运行时通过 CONFIG 命令:

CONFIG SET slowlog-log-slower-than 5000
CONFIG SET slowlog-max-len 25
slowlog-log-slower-than 是用来设置微秒数的, 因此上面的设置将记录执行时间超过5秒的查询. 要获取记录的日志,你可以使用 SLOWLOG GET X 命令, 这里 X 是你想要获取的记录条数:

SLOWLOG GET 10
四、Redis中统计各种数据大小的方法
Redis 内存比较大的话,我们就不太容易查出是哪些(种)键占用的空间。

有一些工具能够提供必要的帮助,比如 redis-rdb-tools 可以直接分析 RDB 文件来生成报告

五、超强、超详细Redis数据库入门教程
http://www.jb51.net/article/56448.htm

http://www.yiibai.com/redis/

六、 Redis操作命令总结
http://www.jb51.net/article/61793.htm

你可以像node npm 工具那样 使用 Composer 提供的包,放到项目中直接使用,这个工具会管理你项目中使用的各种包代码。

安装
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

要全局使用的话,再执行这个命令
sudo mv composer.phar /usr/local/bin/composer

Windows 系统:
找到并进入 PHP 的安装目录(和你在命令行中执行的 php 指令应该是同一套 PHP)。
将 composer.phar 复制到 PHP 的安装目录下面,也就是和 php.exe 在同一级目录。
在 PHP 安装目录下新建一个 composer.bat 文件,并将下列代码保存到此文件中。

@php "%~dp0composer.phar" %*

由于包的管理服务是在国外,国内用户推荐使用国内镜像,用法
https://pkg.phpcomposer.com/#how-to-use-packagist-mirror

以微信overtrue/wechat包为例:
composer.json:
{
"config": {

"vendor-dir": "packages",
"bin-dir": "packages/bin",
"preferred-install": "dist"

},
"require": {

"overtrue/wechat": "~4.0"

},
"repositories": {

"packagist": {
  "type": "composer",
  "url": "https://packagist.phpcomposer.com"
}

}
}

执行:
php composer.phar install
或者
composer install

1.分割 -- split命令

可以指定按行数分割和按字节大小分割两种模式。

(1) 按行数分割

$ split -l 300 large_file.txt new_file_prefix
加上-d,使用数字后缀;加上--verbose,显示分割进度:

$ split -l50000 -d large_file.txt part_ --verbose
(2) 按字节大小分割

$ split -b 10m large_file.log new_file_prefix

2.合并 -- cat命令

$ cat part_* > merge_file.txt

[注] split命令语法:

复制代码
$ split --h
Usage: split [OPTION]... [FILE [PREFIX]]
Output pieces of FILE to PREFIXaa, PREFIXab, ...;
default size is 1000 lines, and default PREFIX is 'x'.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N generate suffixes of length N (default 2) 后缀名称的长度 (默认为2)

  --additional-suffix=SUFFIX  append an additional SUFFIX to file names

-b, --bytes=SIZE put SIZE bytes per output file 每个输出文件的字节大小
-C, --line-bytes=SIZE put at most SIZE bytes of records per output file 每个输出文件每行的最大字节大小
-d use numeric suffixes starting at 0, not alphabetic 使用数字后缀代替字母后缀

  --numeric-suffixes[=FROM]  same as -d, but allow setting the start value

-e, --elide-empty-files do not generate empty output files with '-n' 不产生空的输出文件

  --filter=COMMAND    write to shell COMMAND; file name is $FILE           写入到shell命令行

-l, --lines=NUMBER put NUMBER lines/records per output file 设定每个输出文件的行数,默认行数是1000行
-n, --number=CHUNKS generate CHUNKS output files; see explanation below 产生chunks文件
-t, --separator=SEP use SEP instead of newline as the record separator; 使用新字符分割

                        '\0' (zero) specifies the NUL character

-u, --unbuffered immediately copy input to output with '-n r/...' 无需缓存

  --verbose           print a diagnostic just before each                  显示分割进度
                        output file is opened
  --help     display this help and exit                                    显示帮助信息
  --version  output version information and exit                           显示版本信息

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

CHUNKS may be:
N split into N files based on size of input
K/N output Kth of N to stdout
l/N split into N files without splitting lines/records
l/K/N output Kth of N to stdout without splitting lines/records
r/N like 'l' but use round robin distribution
r/K/N likewise but only output Kth of N to stdout

GNU coreutils online help: http://www.gnu.org/software/coreutils/
Full documentation at: http://www.gnu.org/software/coreutils/split
or available locally via: info '(coreutils) split invocation'
复制代码

cat命令语法:

复制代码
$ cat --h
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.

With no FILE, or when FILE is -, read standard input.

-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends display $ at end of each line
-n, --number number all output lines
-s, --squeeze-blank suppress repeated empty output lines
-t equivalent to -vT
-T, --show-tabs display TAB characters as ^I
-u (ignored)
-v, --show-nonprinting use ^ and M- notation, except for LFD and TAB

  --help     display this help and exit
  --version  output version information and exit

Examples:
cat f - g Output f's contents, then standard input, then g's contents.
cat Copy standard input to standard output.

GNU coreutils online help: http://www.gnu.org/software/coreutils/
Full documentation at: http://www.gnu.org/software/coreutils/cat
or available locally via: info '(coreutils) cat invocation'
复制代码

git 操作方法笔记

自动补全
git --version
下载对应版本的文件:
https://raw.githubusercontent.com/git/git/v2.22.0/contrib/completion/git-completion.bash

如果你用的是 Bash shell,可以试试看 Git 提供的自动补全脚本。下载 Git 的源代码,进入 contrib/completion 目录,会看到一个 git-completion.bash 文件。将此文件复制到你自己的用户主目录中(译注:按照下面的示例,还应改名加上点:cp git-completion.bash ~/.git-completion.bash),并把下面一行内容添加到你的 .bashrc 文件中:

source ~/.git-completion.bash

保存账号密码
git config --global credential.helper store

忽略本地文件权限修改
git config core.fileMode false

tag标签
git tag xxxx [-m xxxxx]
git show xxxx
git push origin xxxx
推送本地所有标签到远程仓库
git push origin [--tags]

删除本地仓库中的文件
git rm与git rm --cached

当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用
1 git rm file_path
2 git commit -m 'delete somefile'
3 git push
当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用
git rm --cached file_path
git commit -m 'delete remote somefile'
git push

本地修改不提交到远程仓库

git update-index --assume-unchanged index.jsp
取消本地忽略
git update-index --no-assume-unchanged index.jsp
查看本地仓库哪些文件被加入忽略列表

恢复跟踪

git update-index --no-assume-unchanged   sp_edaijia/protected/controllers/ApiController.php  //恢复跟踪

#或者
git update-index --skip-worktree xx.php
git update-index --no-skip-worktree xx.php

如果不生效,查看是不是已经被add到暂存区,是的话需要移除暂存区再次执行以上忽略命令

git restore --staged xx.php

如果忽略的文件多了,可以使用以下命令查看忽略列表

git ls-files -v | grep '^h\ '

#查看当前标记状态:
# Windows
git ls-files -v | findstr index.jsp
# Linux/macOS
git ls-files -v | grep index.jsp

#输出以 h 开头:assume-unchanged 生效
#输出以 S 开头:skip-worktree 生效

提取文件路径,方法如下

git ls-files -v | grep '^h\ ' | awk '{print $2}'

所有被忽略的文件,取消忽略的方法,如下

git ls-files -v | grep '^h' | awk '{print $2}' |xargs git update-index --no-assume-unchanged  

查找历史代码片段

git log -G 正则 -p
git log -s 文件名

php-fpm添加service服务

nginx通过FastCGI运行PHP比Apache包含PHP环境有明显的优势,最近有消息称,PHP5.4将很有可能把PHP-FPM补丁包含在内核里,nginx服务器平台上运行PHP将更加轻松,下面我们就来看一篇php-fpm平滑启动并配置服务例子。我的php是源码安装的。php-fpm在PHP 5.3.2以后的版本不支持以前的php-fpm (start|restart|stop|reload) ,那么如果将php-fpm配置成服务,并添加平滑启动/重启。
配置php-fpm.conf(vi /usr/local/php54/etc/php-fpm.conf),将pid(;pid = run/php-fpm.pid)前的;去掉。
因为编译安装php的,所以会在php目录生成很多二进制文件,找到init.d.php-fpm,拷贝到init.d下。
cp /usr/local/src/php54/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
设置权限,并添加服务
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
以后可以使用如下命令管理php-fpm了
service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload