深度优先

这个家伙好懒,除了文章什么都没留下

0%

https://www.cnblogs.com/caijt/p/13455471.html

一开始我是按微软官网文档那样配置的,然后发现这也太简单了,不止配置简单,连使用都这么简单,简单得有点过分。如下图所示,它是基于IDistributedCache接口注入的

这么简单,怎么玩,我连判断某个key值存不存在都没办法。

当然了。绝对不是这么简单的。更高级的用法如下,要引入Microsoft.Extensions.Caching.StackExchangeRedis包

1
2
3
4
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("127.0.0.1:6379");
IDatabase cache = connection.GetDatabase(0);
cache.HashSet("key", "hashKey", "value");
cache.SetAdd("key2", "value");

那要怎么用在系统里呢,当然直接使用IDatabase也可以,但不够优雅,而且我还想通过配置文件,来决定是否启用Redis,如果不启用的话,就使用MemoryCache。非常好。想法有了。

先定义一个接口ICacheHelper,这是用来注入的接口,我暂时只定义了string类型跟hash类型的缓存方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public interface ICacheHelper
{
bool Exists(string key);

void Set<T>(string key, T value);

T Get<T>(string key);

void Delete(string key);

void Expire(string key, DateTime dateTime);
void Expire(string key, TimeSpan timeSpan);

void HashSet(string key, string hashKey, object hashValue);
T HashGet<T>(string key, string hashKey);

bool HashExists(string key, string hashKey);

void HashDelete(string key, string hashKey);
}

然后用Redis实现这个接口,RedisCacheHelper类

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
/// <summary>
/// Redis助手
/// </summary>
public class RedisCacheHelper : ICacheHelper
{
public IDatabase _cache;

private ConnectionMultiplexer _connection;

private readonly string _instance;
public RedisCacheHelper(RedisCacheOptions options, int database = 0)
{
_connection = ConnectionMultiplexer.Connect(options.Configuration);
_cache = _connection.GetDatabase(database);
_instance = options.InstanceName;
}

public bool Exists(string key)
{
return _cache.KeyExists(_instance + key);
}

public void Set<T>(string key, T value)
{
_cache.StringSet(_instance + key, CommonHelper.ObjectToJsonString(value));
}

public T Get<T>(string key)
{
return CommonHelper.JsonStringToObject<T>(_cache.StringGet(_instance + key));
}

public void Delete(string key)
{
_cache.KeyDelete(_instance + key);
}

public void Expire(string key, DateTime dateTime)
{
_cache.KeyExpire(_instance + key, dateTime);
}
public void Expire(string key, TimeSpan timeSpan)
{
_cache.KeyExpire(_instance + key, timeSpan);
}
public void HashSet(string key, string hashKey, object hashValue)
{
string value = CommonHelper.ObjectToJsonString(hashValue);
_cache.HashSet(_instance + key, hashKey, value);
}

public T HashGet<T>(string key, string hashKey)
{
var value = _cache.HashGet(_instance + key, hashKey);
return CommonHelper.JsonStringToObject<T>(value);
}

public object HashGet(string key, string hashKey, Type type)
{
var value = _cache.HashGet(_instance + key, hashKey);
return CommonHelper.JsonStringToObject(value, type);
}

public bool HashExists(string key, string hashKey)
{
return _cache.HashExists(_instance + key, hashKey);
}

public void HashDelete(string key, string hashKey)
{
_cache.HashDelete(_instance + key, hashKey);
}
}

再用MemoryCache实现接口,MemoryCacheHelper类

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
/// <summary>
/// 缓存助手
/// </summary>
public class MemoryCacheHelper : ICacheHelper
{
private readonly IMemoryCache _cache;
public MemoryCacheHelper(IMemoryCache cache)
{
_cache = cache;
}

public bool Exists(string key)
{
return _cache.TryGetValue(key, out _);
}

public T Get<T>(string key)
{
return _cache.Get<T>(key);
}

public void Delete(string key)
{
_cache.Remove(key);
}

public void Set<T>(string key, T value)
{
_cache.Set(key, value);
}
public void Expire(string key, DateTime dateTime)
{
var value = _cache.Get(key);
_cache.Set(key, value, dateTime);
}

public void Expire(string key, TimeSpan timeSpan)
{
var value = _cache.Get(key);
_cache.Set(key, value, timeSpan);
}
public void HashSet(string key, string hashKey, object hashValue)
{
var hash = _cache.Get<Dictionary<string, object>>(key);
if (hash.ContainsKey(hashKey))
{
hash[key] = hashValue;
}
else
{
hash.Add(hashKey, hashValue);
}
_cache.Set<Dictionary<string, object>>(key, hash);
}

public T HashGet<T>(string key, string hashKey)
{
var hash = _cache.Get<Dictionary<string, object>>(key);
if (hash.ContainsKey(hashKey))
{
return (T)hash[hashKey];
}
else
{
return default(T);
}
}

public bool HashExists(string key, string hashKey)
{
var hash = _cache.Get<Dictionary<string, object>>(key);
return hash.ContainsKey(hashKey);
}

public void HashDelete(string key, string hashKey)
{
var hash = _cache.Get<Dictionary<string, object>>(key);
if (hash.ContainsKey(hashKey))
{
hash.Remove(hashKey);
}
}
}

实现类都有了,那现在就来实现根据配置值来决定是否使用Redis还是MemoryCache,先在appsettings.json里添加这个配置值,当Enable为false时,就不启用Redis,使用MemoryCache,Connection是Redis的连接字符串,InstanceName是缓存的前缀,Database是使用哪个数据库

1
2
3
4
5
6
"Redis": {
"Enable": true,
"Connection": "127.0.0.1:6379",
"InstanceName": "LessSharp:",
"Database": 0
}

再定义一个选项类 RedisOption

1
2
3
4
5
6
7
public class RedisOption
{
public bool Enable { get; set; }
public string Connection { get; set; }
public string InstanceName { get; set; }
public int Database { get; set; }
}

然后在Startup.cs类里的ConfigureServices里根据配置值进行注入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var RedisConfiguration = Configuration.GetSection("Redis");
services.Configure<RedisOption>(RedisConfiguration);
RedisOption redisOption = RedisConfiguration.Get<RedisOption>();
if (redisOption != null && redisOption.Enable)
{
var options = new RedisCacheOptions
{
InstanceName = redisOption.InstanceName,
Configuration = redisOption.Connection
};
var redis = new RedisCacheHelper(options, redisOption.Database);
services.AddSingleton(redis);
services.AddSingleton<ICacheHelper>(redis);
}
else
{
services.AddMemoryCache();
services.AddScoped<ICacheHelper, MemoryCacheHelper>();
}

OK,测试后完美

站点版

企业站

  1. 搜狐:http://mirrors.sohu.com/
  2. 腾讯:https://mirrors.cloud.tencent.com/
  3. 网易:http://mirrors.163.com/
  4. 阿里:http://mirrors.aliyun.com/
  5. 华为:https://mirrors.huaweicloud.com/

教育站

  1. 上海交通大学:http://ftp.sjtu.edu.cn/html/resources.xml
  2. 华中科技大学:http://mirror.hust.edu.cn/
  3. 清华大学:http://mirrors.tuna.tsinghua.edu.cn/
  4. 北京理工大学:http://mirror.bit.edu.cn/web/
  5. 兰州大学:http://mirror.lzu.edu.cn/
  6. 中国科技大学:http://mirrors.ustc.edu.cn/
  7. 大连东软信息学院:http://mirrors.neusoft.edu.cn/
  8. 东北大学:http://mirror.neu.edu.cn/
  9. 大连理工大学:http://mirror.dlut.edu.cn/
  10. 哈尔滨工业大学:http://run.hit.edu.cn/html/
  11. 北京交通大学:http://mirror.bjtu.edu.cn/cn/
  12. 中国地质大学:http://mirrors.cug.edu.cn/
  13. 浙江大学:http://mirrors.zju.edu.cn/
  14. 厦门大学:http://mirrors.xmu.edu.cn/
  15. 中山大学:http://mirror.sysu.edu.cn/
  16. 重庆大学:http://mirrors.cqu.edu.cn/
  17. 北京化工大学:http://ubuntu.buct.edu.cn/
  18. 南阳理工学院:http://mirror.nyist.edu.cn/
  19. 中国科学院:http://www.opencas.org/mirrors/
  20. 电子科技大学星辰工作室:http://mirrors.stuhome.net/
  21. 西北农林科技大学:http://mirrors.nwsuaf.edu.cn/

其他站

  1. 首都在线科技股份有限公司(英文名CapitalOnlineDataService):http://mirrors.yun-idc.com/
  2. 中国电信天翼云:http://mirrors.ctyun.cn/
  3. 常州贝特康姆软件技术有限公司:http://centos.bitcomm.cn/
  4. 公云PubYun(母公司为贝特康姆):http://mirrors.pubyun.com/
  5. 中国互联网络信息中心:http://mirrors.cnnic.cn/
  6. Fayea工作室:http://apache.fayea.com/

软件版

操作系统类

Ubuntu
  1. 阿里云:http://mirrors.aliyun.com/ubuntu-releases/
  2. 网易:http://mirrors.163.com/ubuntu-releases/
  3. 搜狐:http://mirrors.sohu.com/ubuntu-releases/
  4. 首都在线科技股份有限公司:http://mirrors.yun-idc.com/ubuntu-releases/
CentOS
  1. 网易:http://mirrors.163.com/centos/
  2. 搜狐:http://mirrors.sohu.com/centos/
  3. 阿里云:http://mirrors.aliyun.com/centos/

操作系统类

Tomcat、Apache
  1. 中国互联网络信息中心:http://mirrors.cnnic.cn/apache/
  2. 华中科技大学:http://mirrors.hust.edu.cn/apache/
  3. 北京理工大学:http://mirror.bit.edu.cn/apache/
MySQL
  1. 北京理工大学:http://mirror.bit.edu.cn/mysql/Downloads/
  2. 中国电信天翼云:http://mirrors.ctyun.cn/Mysql/
PostgreSQL
  1. 浙江大学:http://mirrors.zju.edu.cn/postgresql/
MariaDB
  1. 中国电信天翼云:http://mirrors.ctyun.cn/MariaDB/
VideoLAN
  1. 大连东软信息学院:http://mirrors.neusoft.edu.cn/videolan/
  2. 中国科技大学:http://mirrors.ustc.edu.cn/videolan-ftp/

开发工具类

Eclipse
  1. 中国科技大学:http://mirrors.ustc.edu.cn/eclipse/
  2. 中国科学院:http://mirrors.opencas.cn/eclipse/
  3. 东北大学A:http://ftp.neu.edu.cn/mirrors/eclipse/
  4. 东北大学B:http://mirror.neu.edu.cn/eclipse/
安卓SDK
  1. 中国科学院:http://mirrors.opencas.ac.cn/android/repository/
  2. 南洋理工学院:http://mirror.nyist.edu.cn/android/repository/
  3. 中国科学院:http://mirrors.opencas.cn/android/repository/
  4. 大连东软信息学院:http://mirrors.neusoft.edu.cn/android/repository/

官方镜像列表状态地址

  1. CentOS:http://mirror-status.centos.org/#cn
  2. Archlinux:https://www.archlinux.org/mirrors/status/
  3. Ubuntu:https://launchpad.net/ubuntu/+cdmirrors
  4. Debian:http://mirror.debian.org/status.html
  5. FedoraLinux/FedoraEPEL:https://admin.fedoraproject.org/mirrormanager/mirrors
  6. Apache:http://www.apache.org/mirrors/#cn
  7. Cygwin:https://www.cygwin.com/mirrors.html

https://www.quchao.net/WEB-Disable.html

前言

下午帮客户分析某文学登陆业务中,发现有页面禁用了网页右键,非常影响调试,平时遇到这种情况通常都是JS即可,但是网上查阅了资料后发现用控制台调节更灵活一些,毕竟禁用 JS 可能出现一些错位现象,于是就有了下文。


实现禁止操作

既然我们要解除就要先看看禁止效果是如何失效的,以下代码放入网站JS里面引用即可实现效果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 禁止右键菜单
document.oncontextmenu = function(){ return false; };
document.oncontextmenu= new Function("event.returnValue=false");
// 禁止文字选择
document.onselectstart = function(){ return false; };
document.onselectstart = new Function("event.returnValue=false");
// 禁止复制
document.oncopy = function(){ return false; };
document.oncopy = new Function("event.returnValue=false");
// 禁止剪切
document.oncut = function(){ return false; };
document.oncopy = new Function("event.returnValue=false");
// 禁止粘贴
document.onpaste = function(){ return false; };
document.onpaste = new Function("event.returnValue=false");
// 禁止F12
document.onkeydown = function () {
if (window.event && window.event.keyCode == 123) {
event.keyCode = 0;
event.returnValue = true;
return true;
}
};


解除禁止操作

通常直接按F12,如果此键被禁止可以通过SHIFT + CTRL + I打开,或者通过浏览器菜单里面的“开发人员工具”
选择控制台,输入以下代码回车即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 开启右键菜单
document.oncontextmenu = function(){ return true; };
// 开启文字选择
document.onselectstart = function(){ return true; };
// 开启复制
document.oncopy = function(){ return true; };
// 开启剪切
document.oncut = function(){ return true; };
// 开启粘贴
document.onpaste = function(){ return true; };
// 开启F12键
document.onkeydown = function () {
if (window.event && window.event.keyCode == 123) {
event.keyCode = 0;
event.returnValue = true;
return true;
}
};


结语

细心的朋友可能发现F12 键盘的代码中含有123,其实这个是键盘的键盘码,同理可以换成其他按键(键盘码)进行禁止某键或者开启某个按键,最后附上一份键盘码便于使用。

键盘码列表

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
按键名(key)    按键码(keyCode)
Escape【退出键】 27
F1 112
F2 113
F3 114
F4 115
F5 116
F6 117
F7 118
F8 119
F9 120
F10 121
F11 122
F12 123
ScrollLock【滚动锁定键】 145
Print【打印键,亦可截取整个屏幕,在画图、doc、ppt等粘贴】 42
Pause【暂停键】 19
`【反引号】 192
~【波浪号】 192
! 49
@【艾特符,小老鼠,圈a,蜗牛】 50
#【井号】 51
$【美元符,中文状态下是人民币符】 52
% 53
^【 折音符】 54
&【and符,和,且】 55
*【星号】 56
( 57
) 48
-【减号,横杆】 173
+ 61
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
0 48
_【下划线】 173
= 61
Backspace【← 回退键】 8
Tab【制表键】 9
CapsLock【⇪字母大写锁】 20
Shift【⇧上档转换键或上档键】 16
q 81
w 87
e 69
r 82
t 84
y 89
u 85
i 73
o 79
p 80
[ 219
] 221
Q 81
W 87
E 69
R 82
T 84
Y 89
U 85
I 73
O 79
P 80
{ 219
} 221
a 65
s 83
d 68
f 70
g 71
h 72
j 74
k 75
l 76
;【分号】 59
'【单引号】 222
\【反斜杠】 220
A 65
S 83
D 68
F 70
G 71
H 72
J 74
K 75
L 76
:【冒号】 59
"【双引号】 222
|【竖杠】 220
z 90
x 88
c 67
v 86
b 66
n 78
m 77
,【逗号】 188
.【句号】 190
/【斜杠】 191
Z 90
X 88
C 67
V 86
B 66
N 78
M 77
<【小于号】 188
>【大于号】 190
? 191
Control【控制键】 17
OS【window键】 91
Alt【换挡键】 18
【空格键】 32
ContextMenu【上下文菜单键,等价于鼠标右键】 93
Enter【↩回车键】 13
Insert【插入键】 45
Delete【删除键】 46
Home【起始键】 36
End【结束建】 35
PageUp【上页键】 33
PageDown【下页键】 34
ArrowUp【↑上移键】 38
ArrowRight【→右移键】 39
ArrowDown【↓下移键】 40
ArrowLeft【←左移键】 37
以下是小键盘部分
NumLock【数字锁定键】 144
/ 111
* 106
- 109
+ 107
Enter 13
0 96
.【点】 110
1 97
2 98
3 99
4 100
5 101
6 102
7 103
8 104
9 105