forked from Apriluestc/2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile
More file actions
197 lines (157 loc) · 6.55 KB
/
Copy pathfile
File metadata and controls
197 lines (157 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**********************************************************
* Author : Apriluestc
* Email : 13669186256@163.com
* Last modified : 2019-07-01 20:41
* Filename : file
* Description :
* *******************************************************/
常见文件安装
###########################################################################
gcc@
$ sudo yum install gcc -y
centos7-gcc 版本升级至5.3
$ yum install centos-release-scl
$ yum install devtoolset-4-toolchain
$ scl enable devtoolset-4 bash
将 scl enable devtoolset-4 bash 添加至 /etc/profile
$ gcc --version
###########################################################################
##########################################################################
target : gdb、 git、make、cmake、gcc-c++、zip & unzip、tree
sudo install -y $(target)
###########################################################################
vim 配置
Centos 7
$ git clone https://github.com/chxuan/vimplus.git ~/.vimplus
$ cd ~/.vimplus
$ ./install.sh
MacOS:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ git clone https://github.com/chxuan/vimplus.git ~/.vimplus
$ cd ~/.vimplus
$ ./install.sh
ubuntu:
$ git clone https://github.com/chxuan/vimplus.git ~/.vimplus
$ cd ~/.vimplus
$ ./install.sh
vim 中添加作者属性:版权、邮箱、文件名、描述
map <F4> ms:call AddAuthor()<cr>'s
function AddAuthor()
let n=1
while n < 5
let line = getline(n)
if line =~'^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
function UpdateTitle()
normal m'
execute '/* Last modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@'
normal "
normal mk
execute '/* Filename\s*:/s@:.*$@\=": ".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function AddTitle()
call append(0,"/**********************************************************")
call append(1," * Author : Apriluestc")
call append(2," * Email : 13669186256@163.com")
call append(3," * Last modified : ".strftime("%Y-%m-%d %H:%M"))
call append(4," * Filename : ".expand("%:t"))
call append(5," * Description : ")
call append(6," * *******************************************************/")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
##########################################################################
为普通用户添加 sudo 权限
安装 sudo :
$ yum install -y sudo
$ vim /etc/sudoers
找到类似:
sudoers
root ALL=(ALL) ALL
user ALL=(ALL) ALL
注意在修改 sudoers 文件时,为其添加修改权限
$ chmod u+w /etc/sudoers
$ chmod u-w /etc/sudoers
sudo 用户免密码
$ user ALL=(ALL)NOPASSWD:ALL
###############################################################################
防火墙开启端口号@
$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
$ sudo firewall-cmd --reload
查看防火墙状态: $ sudo systemctl status firewalld
开启防火墙: $ sudo systemctl start firewalld
关闭防火墙: $ sudo systemctl stop firewalld
查看当前防火墙状态: $ sudo firewall-cmd --state
重启防火墙: $ sudo firewall-cmd --reload
禁止开机自启动: $ sudo systemctl disable firewalld.service
永久开启端口号: $ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
查看已经开启的端口号: $ sudo firewall-cmd --list-ports
###########################################################################
###########################################################################
新添加第三方库
$ cp -r json.h /home/shiny/usr/include/
$ cp libjsoncpp.so /home/shiny/lib/
$ sudo vim /etc/profile
$ source /etc/profile
$ cd /usr/include/
$ sudo ln -s /home/shiny/usr/include/jsoncpp jsoncpp
$ cd /usr/lib/
$ cp -r /home/shiny/lib/libjsoncpp.so .
详见:/etc/profile
····
ok 完成
###########################################################################
常见第三方库安装
jsoncpp、curl、ncurses、ctemplate、httplib
###########################################################################
redis 服务开启
先修改配置文件:redis.conf 中的 daemonize no 改为 yes 即支持后台启动(默认后台运行)
sudo redis-server /etc/redis.conf
开启客户端首先要保证服务端先运行:sudo redis-server /etc/redis.conf
##########################################################################
C++ 使用 hredis 库
1、连接数据库
1.1 无超时时间,阻塞:redisContext* redisConnect(const char* ip, int port);
1.2 设置超时时间,阻塞:redisContext* redisConnectWithTimeout(const char* ip, int port, const struct timeval tv);
1.3 非阻塞立刻返回,也就是无超时:redisContext* redisConnectNoBlock(const char* ip, int port);
2、执行命令
2.1 返回值
/* This is the reply object returned by redisCommand() */
typedef struct redisReply {
int type; /* REDIS_REPLY_* */
PORT_LONGLONG integer; /* The integer when type is REDIS_REPLY_INTEGER */
int len; /* Length of string */
char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
} redisReply;
2.2 返回值类型
#define REDIS_REPLY_STRING 1 //字符串
#define REDIS_REPLY_ARRAY 2 //数组,例如mget返回值
#define REDIS_REPLY_INTEGER 3 //数字类型
#define REDIS_REPLY_NIL 4 //空
#define REDIS_REPLY_STATUS 5 //状态,例如set成功返回的‘OK’
#define REDIS_REPLY_ERROR 6 //执行失败
3、基本命令
3.1 set
redisReply *r1 = (redisReply*)redisCommand(c, "set k v");
3.2 get
redisReply *r2 = (redisReply*)redisCommand(c, "get k");
4、存取二进制
char sz[] = { 0,1,2,3,0 };
redisReply *r3 = (redisReply*)redisCommand(c, "set kb %b",sz,sizeof(sz));
存二进制的时候,使用%b,后面需要对应两个参数,指针和长度
redisReply *r4 = (redisReply*)redisCommand(c, "get kb");
5、存取多个值
存取多个值,可以通过拼接字符串
redisReply *r5 = (redisReply*)redisCommand(c, "mset k1 v1 k2 v2");
取多个值:redisReply *r6 = (redisReply*)redisCommand(c, "mget k1 k2");
#########################################################################