kcwredis 1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kcwredis-1.3/PKG-INFO +13 -0
- kcwredis-1.3/kcwredis/__init__.py +4 -0
- kcwredis-1.3/kcwredis/redisclass.py +608 -0
- kcwredis-1.3/kcwredis.egg-info/PKG-INFO +13 -0
- kcwredis-1.3/kcwredis.egg-info/SOURCES.txt +8 -0
- kcwredis-1.3/kcwredis.egg-info/dependency_links.txt +1 -0
- kcwredis-1.3/kcwredis.egg-info/requires.txt +1 -0
- kcwredis-1.3/kcwredis.egg-info/top_level.txt +1 -0
- kcwredis-1.3/setup.cfg +4 -0
- kcwredis-1.3/setup.py +57 -0
kcwredis-1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 1.2
|
|
2
|
+
Name: kcwredis
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: kcwcache
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: 百里
|
|
7
|
+
Author-email: kcwebs@kwebapp.cn
|
|
8
|
+
Maintainer: 坤坤
|
|
9
|
+
Maintainer-email: fk1402936534@qq.com
|
|
10
|
+
License: MIT License
|
|
11
|
+
Description: UNKNOWN
|
|
12
|
+
Keywords: kcwredis1.3
|
|
13
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import json,copy
|
|
3
|
+
try:
|
|
4
|
+
from kcwebs.config import redis as tempredisconf
|
|
5
|
+
tempredisconf['debug']=False
|
|
6
|
+
except:
|
|
7
|
+
tempredisconf={}
|
|
8
|
+
tempredisconf['debug']=False
|
|
9
|
+
tempredisconf['host']='127.0.0.1' #服务器地址
|
|
10
|
+
tempredisconf['port']=6379 #端口
|
|
11
|
+
tempredisconf['password']='' #密码
|
|
12
|
+
tempredisconf['db']=0 #Redis数据库 注:Redis用0或1或2等表示
|
|
13
|
+
tempredisconf['pattern']=True # True连接池链接 False非连接池链接
|
|
14
|
+
tempredisconf['ex']=0 #过期时间 (秒)
|
|
15
|
+
class redisclass:
|
|
16
|
+
"redis 注意:连接池链接模式下不支持动态配置"
|
|
17
|
+
db=copy.deepcopy(tempredisconf['db']) #默认数据库
|
|
18
|
+
__redisObj=None
|
|
19
|
+
__coninfo={}
|
|
20
|
+
__config=copy.deepcopy(tempredisconf)
|
|
21
|
+
__identifier=''
|
|
22
|
+
def close(self,pattern=False):
|
|
23
|
+
if self.__config['pattern']:
|
|
24
|
+
if pattern:
|
|
25
|
+
if not self.__identifier:
|
|
26
|
+
self.__identifier=self.__config['host']+self.__config['password']+str(self.__config['port'])+str(self.__config['db'])
|
|
27
|
+
self.__redisObj.close()
|
|
28
|
+
self.__redisObj=None
|
|
29
|
+
del self.__coninfo[self.__identifier]
|
|
30
|
+
elif self.__redisObj:
|
|
31
|
+
self.__redisObj.close()
|
|
32
|
+
self.__redisObj=None
|
|
33
|
+
def __connects(self):
|
|
34
|
+
"""设置redis链接"""
|
|
35
|
+
import redis as red
|
|
36
|
+
if self.__config['pattern']:
|
|
37
|
+
self.__identifier=self.__config['host']+self.__config['password']+str(self.__config['port'])+str(self.__config['db'])
|
|
38
|
+
if self.__identifier not in self.__coninfo:
|
|
39
|
+
if self.__config['password']:
|
|
40
|
+
redis_pool=red.ConnectionPool(host=self.__config['host'],password=self.__config['password'],port=self.__config['port'],db=self.__config['db'])
|
|
41
|
+
else:
|
|
42
|
+
redis_pool=red.ConnectionPool(host=self.__config['host'],port=self.__config['port'],db=self.__config['db'])
|
|
43
|
+
self.__coninfo[self.__identifier]=red.Redis(connection_pool=redis_pool)
|
|
44
|
+
if self.__config['debug']:
|
|
45
|
+
print("建立redis连接池",self.__identifier)
|
|
46
|
+
self.__redisObj=self.__coninfo[self.__identifier]
|
|
47
|
+
self.__config['db']=self.db
|
|
48
|
+
else:
|
|
49
|
+
if self.__config['password']:
|
|
50
|
+
self.__redisObj=red.Redis(host=self.__config['host'],password=self.__config['password'],port=self.__config['port'],db=self.__config['db'])
|
|
51
|
+
else:
|
|
52
|
+
self.__redisObj=red.Redis(host=self.__config['host'],port=self.__config['port'],db=self.__config['db'])
|
|
53
|
+
|
|
54
|
+
if self.__config['debug']:
|
|
55
|
+
print("建立redis连接",self.__identifier)
|
|
56
|
+
|
|
57
|
+
def __json_decode(self,strs):
|
|
58
|
+
"""json字符串转python类型"""
|
|
59
|
+
try:
|
|
60
|
+
return json.loads(strs)
|
|
61
|
+
except Exception:
|
|
62
|
+
return {}
|
|
63
|
+
def __json_encode(self,strs):
|
|
64
|
+
"""转成字符串"""
|
|
65
|
+
try:
|
|
66
|
+
return json.dumps(strs,ensure_ascii=False)
|
|
67
|
+
except Exception:
|
|
68
|
+
return ""
|
|
69
|
+
def getconfig(self):
|
|
70
|
+
return self.__config
|
|
71
|
+
def connect(self,configs):
|
|
72
|
+
"""设置redis链接信息
|
|
73
|
+
|
|
74
|
+
参数 config 参考配置信息格式
|
|
75
|
+
|
|
76
|
+
返回 redis
|
|
77
|
+
"""
|
|
78
|
+
if configs:
|
|
79
|
+
if isinstance(configs,int):
|
|
80
|
+
self.__config=copy.deepcopy(tempredisconf)
|
|
81
|
+
self.__config['db']=configs
|
|
82
|
+
elif isinstance(configs,dict):
|
|
83
|
+
if "host" in configs:
|
|
84
|
+
self.__config['host']=configs['host']
|
|
85
|
+
if "port" in configs:
|
|
86
|
+
self.__config['port']=configs['port']
|
|
87
|
+
if "password" in configs:
|
|
88
|
+
self.__config['password']=configs['password']
|
|
89
|
+
if "db" in configs:
|
|
90
|
+
self.__config['db']=configs['db']
|
|
91
|
+
else:
|
|
92
|
+
raise Exception("配置信息错误")
|
|
93
|
+
else:
|
|
94
|
+
self.__config=copy.deepcopy(tempredisconf)
|
|
95
|
+
return self
|
|
96
|
+
|
|
97
|
+
def redisObj(self):
|
|
98
|
+
"得到一个redis连接对象,执行更多高级操作"
|
|
99
|
+
self.__connects()
|
|
100
|
+
return self.__redisObj
|
|
101
|
+
def incrby(self,name,value,ex=0):
|
|
102
|
+
"""设置自增数量
|
|
103
|
+
|
|
104
|
+
name,键
|
|
105
|
+
|
|
106
|
+
value,值 自增 步长
|
|
107
|
+
|
|
108
|
+
ex,过期时间(秒)
|
|
109
|
+
"""
|
|
110
|
+
i=0
|
|
111
|
+
while True:
|
|
112
|
+
self.__connects()
|
|
113
|
+
try:
|
|
114
|
+
status=self.__redisObj.incrby(name,value)
|
|
115
|
+
except Exception as e:
|
|
116
|
+
stre=str(e)
|
|
117
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
118
|
+
i+=1
|
|
119
|
+
self.close(pattern=True)
|
|
120
|
+
if i>3:
|
|
121
|
+
raise Exception(e)
|
|
122
|
+
else:
|
|
123
|
+
print("__redisObj_e",e)
|
|
124
|
+
raise Exception(e)
|
|
125
|
+
else:
|
|
126
|
+
if ex and status:
|
|
127
|
+
self.__redisObj.expire(name, ex)
|
|
128
|
+
self.close()
|
|
129
|
+
break
|
|
130
|
+
return status
|
|
131
|
+
def getstr(self,name):
|
|
132
|
+
"""获取name的值
|
|
133
|
+
|
|
134
|
+
name,键
|
|
135
|
+
返回键“name”处的值,如果该键不存在,则返回“none”
|
|
136
|
+
"""
|
|
137
|
+
i=0
|
|
138
|
+
while True:
|
|
139
|
+
self.__connects()
|
|
140
|
+
try:
|
|
141
|
+
value=self.__redisObj.get(name)
|
|
142
|
+
except Exception as e:
|
|
143
|
+
stre=str(e)
|
|
144
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
145
|
+
i+=1
|
|
146
|
+
self.close(pattern=True)
|
|
147
|
+
if i>3:
|
|
148
|
+
raise Exception(e)
|
|
149
|
+
else:
|
|
150
|
+
print("__redisObj_e",e)
|
|
151
|
+
raise Exception(e)
|
|
152
|
+
else:
|
|
153
|
+
self.close()
|
|
154
|
+
break
|
|
155
|
+
return value
|
|
156
|
+
|
|
157
|
+
def setstr(self,name,value,ex=None, px=None, nx=False, xx=False):
|
|
158
|
+
"""
|
|
159
|
+
name,键
|
|
160
|
+
|
|
161
|
+
value,值 只能是字符串
|
|
162
|
+
|
|
163
|
+
ex,过期时间(秒)
|
|
164
|
+
|
|
165
|
+
px,过期时间(毫秒)
|
|
166
|
+
|
|
167
|
+
nx,如果设置为True,则只有key不存在时,当前set操作才执行,同#setnx(key, value)
|
|
168
|
+
|
|
169
|
+
xx,如果设置为True,则只有key存在时,当前set操作才执行
|
|
170
|
+
"""
|
|
171
|
+
if not ex and not px:
|
|
172
|
+
if self.__config['ex']:
|
|
173
|
+
ex=self.__config['ex']
|
|
174
|
+
i=0
|
|
175
|
+
while True:
|
|
176
|
+
self.__connects()
|
|
177
|
+
try:
|
|
178
|
+
status=self.__redisObj.set(name, value, ex=ex, px=px, nx=nx, xx=xx)
|
|
179
|
+
except Exception as e:
|
|
180
|
+
stre=str(e)
|
|
181
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
182
|
+
i+=1
|
|
183
|
+
self.close(pattern=True)
|
|
184
|
+
if i>3:
|
|
185
|
+
raise Exception(e)
|
|
186
|
+
else:
|
|
187
|
+
print("__redisObj_e",e)
|
|
188
|
+
raise Exception(e)
|
|
189
|
+
else:
|
|
190
|
+
self.close()
|
|
191
|
+
break
|
|
192
|
+
return status
|
|
193
|
+
def append(self,name,value):
|
|
194
|
+
"""将字符串“value”追加到“name”处的值。如果``键`` 不存在,请使用值“name”创建它。 返回位于“name”的值的新长度。
|
|
195
|
+
|
|
196
|
+
name,键
|
|
197
|
+
|
|
198
|
+
value,值 只能是字符串
|
|
199
|
+
"""
|
|
200
|
+
i=0
|
|
201
|
+
while True:
|
|
202
|
+
self.__connects()
|
|
203
|
+
try:
|
|
204
|
+
status=self.__redisObj.append(name,value)
|
|
205
|
+
except Exception as e:
|
|
206
|
+
stre=str(e)
|
|
207
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
208
|
+
i+=1
|
|
209
|
+
self.close(pattern=True)
|
|
210
|
+
if i>3:
|
|
211
|
+
raise Exception(e)
|
|
212
|
+
else:
|
|
213
|
+
print("__redisObj_e",e)
|
|
214
|
+
raise Exception(e)
|
|
215
|
+
else:
|
|
216
|
+
self.close()
|
|
217
|
+
break
|
|
218
|
+
return status
|
|
219
|
+
def set(self,name,value,ex=None, px=None, nx=False, xx=False):
|
|
220
|
+
"""
|
|
221
|
+
name,键
|
|
222
|
+
|
|
223
|
+
value,值 可以是字典 列表 或字符串
|
|
224
|
+
|
|
225
|
+
ex,过期时间(秒)
|
|
226
|
+
|
|
227
|
+
px,过期时间(毫秒)
|
|
228
|
+
|
|
229
|
+
nx,如果设置为True,则只有key不存在时,当前set操作才执行
|
|
230
|
+
|
|
231
|
+
xx,如果设置为True,则只有key存在时,当前set操作才执行
|
|
232
|
+
"""
|
|
233
|
+
if not ex and not px:
|
|
234
|
+
if self.__config['ex']:
|
|
235
|
+
ex=self.__config['ex']
|
|
236
|
+
value=self.__json_encode(value)
|
|
237
|
+
i=0
|
|
238
|
+
while True:
|
|
239
|
+
self.__connects()
|
|
240
|
+
try:
|
|
241
|
+
status=self.__redisObj.set(name, value, ex=ex, px=px, nx=nx, xx=xx)
|
|
242
|
+
except Exception as e:
|
|
243
|
+
stre=str(e)
|
|
244
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
245
|
+
i+=1
|
|
246
|
+
self.close(pattern=True)
|
|
247
|
+
if i>3:
|
|
248
|
+
raise Exception(e)
|
|
249
|
+
else:
|
|
250
|
+
print("__redisObj_e",e)
|
|
251
|
+
raise Exception(e)
|
|
252
|
+
else:
|
|
253
|
+
self.close()
|
|
254
|
+
break
|
|
255
|
+
return status
|
|
256
|
+
def get(self,name):
|
|
257
|
+
"""获取name的值
|
|
258
|
+
|
|
259
|
+
name,键
|
|
260
|
+
返回键“name”处的值,如果该键不存在,则返回“none”
|
|
261
|
+
"""
|
|
262
|
+
i=0
|
|
263
|
+
while True:
|
|
264
|
+
self.__connects()
|
|
265
|
+
try:
|
|
266
|
+
value=self.__redisObj.get(name)
|
|
267
|
+
except Exception as e:
|
|
268
|
+
stre=str(e)
|
|
269
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
270
|
+
i+=1
|
|
271
|
+
self.close(pattern=True)
|
|
272
|
+
if i>3:
|
|
273
|
+
raise Exception(e)
|
|
274
|
+
else:
|
|
275
|
+
print("__redisObj_e",e)
|
|
276
|
+
raise Exception(e)
|
|
277
|
+
else:
|
|
278
|
+
self.close()
|
|
279
|
+
break
|
|
280
|
+
if value:
|
|
281
|
+
value=self.__json_decode(value)
|
|
282
|
+
return value
|
|
283
|
+
def delete(self,name):
|
|
284
|
+
"""删除name的值
|
|
285
|
+
|
|
286
|
+
name,键
|
|
287
|
+
|
|
288
|
+
返回 True,如果该键不存在,则返回 0
|
|
289
|
+
"""
|
|
290
|
+
i=0
|
|
291
|
+
while True:
|
|
292
|
+
self.__connects()
|
|
293
|
+
try:
|
|
294
|
+
status=self.__redisObj.delete(name)
|
|
295
|
+
except Exception as e:
|
|
296
|
+
stre=str(e)
|
|
297
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
298
|
+
i+=1
|
|
299
|
+
self.close(pattern=True)
|
|
300
|
+
if i>3:
|
|
301
|
+
raise Exception(e)
|
|
302
|
+
else:
|
|
303
|
+
print("__redisObj_e",e)
|
|
304
|
+
raise Exception(e)
|
|
305
|
+
else:
|
|
306
|
+
self.close()
|
|
307
|
+
break
|
|
308
|
+
return status
|
|
309
|
+
def rpush(self,name, *values):
|
|
310
|
+
"元素从list的右边加入 ,可以添加多个"
|
|
311
|
+
i=0
|
|
312
|
+
while True:
|
|
313
|
+
self.__connects()
|
|
314
|
+
try:
|
|
315
|
+
status=self.__redisObj.rpush(name, *values)
|
|
316
|
+
except Exception as e:
|
|
317
|
+
stre=str(e)
|
|
318
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
319
|
+
i+=1
|
|
320
|
+
self.close(pattern=True)
|
|
321
|
+
if i>3:
|
|
322
|
+
raise Exception(e)
|
|
323
|
+
else:
|
|
324
|
+
print("__redisObj_e",e)
|
|
325
|
+
raise Exception(e)
|
|
326
|
+
else:
|
|
327
|
+
self.close()
|
|
328
|
+
break
|
|
329
|
+
return status
|
|
330
|
+
def rpop(self,name):
|
|
331
|
+
"元素从list的右边移出"
|
|
332
|
+
i=0
|
|
333
|
+
while True:
|
|
334
|
+
self.__connects()
|
|
335
|
+
try:
|
|
336
|
+
status=self.__redisObj.rpop(name)
|
|
337
|
+
except Exception as e:
|
|
338
|
+
stre=str(e)
|
|
339
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
340
|
+
i+=1
|
|
341
|
+
self.close(pattern=True)
|
|
342
|
+
if i>3:
|
|
343
|
+
raise Exception(e)
|
|
344
|
+
else:
|
|
345
|
+
print("__redisObj_e",e)
|
|
346
|
+
raise Exception(e)
|
|
347
|
+
else:
|
|
348
|
+
self.close()
|
|
349
|
+
break
|
|
350
|
+
return status
|
|
351
|
+
def rpoplpush(self,src, dst):
|
|
352
|
+
"元素从list的右边移出,并且从list的左边加入"
|
|
353
|
+
i=0
|
|
354
|
+
while True:
|
|
355
|
+
self.__connects()
|
|
356
|
+
try:
|
|
357
|
+
status=self.__redisObj.rpoplpush(src, dst)
|
|
358
|
+
except Exception as e:
|
|
359
|
+
stre=str(e)
|
|
360
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
361
|
+
i+=1
|
|
362
|
+
self.close(pattern=True)
|
|
363
|
+
if i>3:
|
|
364
|
+
raise Exception(e)
|
|
365
|
+
else:
|
|
366
|
+
print("__redisObj_e",e)
|
|
367
|
+
raise Exception(e)
|
|
368
|
+
else:
|
|
369
|
+
self.close()
|
|
370
|
+
break
|
|
371
|
+
return status
|
|
372
|
+
def rpushx(self,name, value):
|
|
373
|
+
"当name存在时,元素才能从list的右边加入"
|
|
374
|
+
i=0
|
|
375
|
+
while True:
|
|
376
|
+
self.__connects()
|
|
377
|
+
try:
|
|
378
|
+
status=self.__redisObj.rpushx(name, value)
|
|
379
|
+
except Exception as e:
|
|
380
|
+
stre=str(e)
|
|
381
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
382
|
+
i+=1
|
|
383
|
+
self.close(pattern=True)
|
|
384
|
+
if i>3:
|
|
385
|
+
raise Exception(e)
|
|
386
|
+
else:
|
|
387
|
+
print("__redisObj_e",e)
|
|
388
|
+
raise Exception(e)
|
|
389
|
+
else:
|
|
390
|
+
self.close()
|
|
391
|
+
break
|
|
392
|
+
return status
|
|
393
|
+
def lpush(self,name, *values):
|
|
394
|
+
"元素从list的左边加入,可以添加多个"
|
|
395
|
+
i=0
|
|
396
|
+
while True:
|
|
397
|
+
self.__connects()
|
|
398
|
+
try:
|
|
399
|
+
status=self.__redisObj.lpush(name, *values)
|
|
400
|
+
except Exception as e:
|
|
401
|
+
stre=str(e)
|
|
402
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
403
|
+
i+=1
|
|
404
|
+
self.close(pattern=True)
|
|
405
|
+
if i>3:
|
|
406
|
+
raise Exception(e)
|
|
407
|
+
else:
|
|
408
|
+
print("__redisObj_e",e)
|
|
409
|
+
raise Exception(e)
|
|
410
|
+
else:
|
|
411
|
+
self.close()
|
|
412
|
+
break
|
|
413
|
+
return status
|
|
414
|
+
def lpop(self,name):
|
|
415
|
+
"元素从list的左边移出"
|
|
416
|
+
i=0
|
|
417
|
+
while True:
|
|
418
|
+
self.__connects()
|
|
419
|
+
try:
|
|
420
|
+
status=self.__redisObj.lpop(name)
|
|
421
|
+
except Exception as e:
|
|
422
|
+
stre=str(e)
|
|
423
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
424
|
+
i+=1
|
|
425
|
+
self.close(pattern=True)
|
|
426
|
+
if i>3:
|
|
427
|
+
raise Exception(e)
|
|
428
|
+
else:
|
|
429
|
+
print("__redisObj_e",e)
|
|
430
|
+
raise Exception(e)
|
|
431
|
+
else:
|
|
432
|
+
self.close()
|
|
433
|
+
break
|
|
434
|
+
return status
|
|
435
|
+
def lpushxs(self,name):
|
|
436
|
+
"当name存在时,元素才能从list的左边加入"
|
|
437
|
+
i=0
|
|
438
|
+
while True:
|
|
439
|
+
self.__connects()
|
|
440
|
+
try:
|
|
441
|
+
status=self.__redisObj.lpushx(name)
|
|
442
|
+
except Exception as e:
|
|
443
|
+
stre=str(e)
|
|
444
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
445
|
+
i+=1
|
|
446
|
+
self.close(pattern=True)
|
|
447
|
+
if i>3:
|
|
448
|
+
raise Exception(e)
|
|
449
|
+
else:
|
|
450
|
+
print("__redisObj_e",e)
|
|
451
|
+
raise Exception(e)
|
|
452
|
+
else:
|
|
453
|
+
self.close()
|
|
454
|
+
break
|
|
455
|
+
return status
|
|
456
|
+
def hset(self,name,key,value):
|
|
457
|
+
"""在hash名称中将key设置为value如果HSET创建了新字段,则返回1,否则返回0
|
|
458
|
+
|
|
459
|
+
name,名
|
|
460
|
+
|
|
461
|
+
key,键
|
|
462
|
+
|
|
463
|
+
mapping,值
|
|
464
|
+
"""
|
|
465
|
+
i=0
|
|
466
|
+
while True:
|
|
467
|
+
self.__connects()
|
|
468
|
+
try:
|
|
469
|
+
status=self.__redisObj.hset(name,key,value)
|
|
470
|
+
except Exception as e:
|
|
471
|
+
stre=str(e)
|
|
472
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
473
|
+
i+=1
|
|
474
|
+
self.close(pattern=True)
|
|
475
|
+
if i>3:
|
|
476
|
+
raise Exception(e)
|
|
477
|
+
else:
|
|
478
|
+
print("__redisObj_e",e)
|
|
479
|
+
raise Exception(e)
|
|
480
|
+
else:
|
|
481
|
+
self.close()
|
|
482
|
+
break
|
|
483
|
+
return status
|
|
484
|
+
|
|
485
|
+
def hget(self,name,key):
|
|
486
|
+
"返回hash的name中的key值"
|
|
487
|
+
i=0
|
|
488
|
+
while True:
|
|
489
|
+
self.__connects()
|
|
490
|
+
try:
|
|
491
|
+
status=self.__redisObj.hget(name,key)
|
|
492
|
+
except Exception as e:
|
|
493
|
+
stre=str(e)
|
|
494
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
495
|
+
i+=1
|
|
496
|
+
self.close(pattern=True)
|
|
497
|
+
if i>3:
|
|
498
|
+
raise Exception(e)
|
|
499
|
+
else:
|
|
500
|
+
print("__redisObj_e",e)
|
|
501
|
+
raise Exception(e)
|
|
502
|
+
else:
|
|
503
|
+
self.close()
|
|
504
|
+
break
|
|
505
|
+
return status
|
|
506
|
+
def hgetall(self,name):
|
|
507
|
+
"返回hash名称/值对的Python dict"
|
|
508
|
+
i=0
|
|
509
|
+
while True:
|
|
510
|
+
self.__connects()
|
|
511
|
+
try:
|
|
512
|
+
data=self.__redisObj.hgetall(name)
|
|
513
|
+
except Exception as e:
|
|
514
|
+
stre=str(e)
|
|
515
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
516
|
+
i+=1
|
|
517
|
+
self.close(pattern=True)
|
|
518
|
+
if i>3:
|
|
519
|
+
raise Exception(e)
|
|
520
|
+
else:
|
|
521
|
+
print("__redisObj_e",e)
|
|
522
|
+
raise Exception(e)
|
|
523
|
+
else:
|
|
524
|
+
self.close()
|
|
525
|
+
break
|
|
526
|
+
return data
|
|
527
|
+
|
|
528
|
+
def hdel(self,name,key):
|
|
529
|
+
"""在hash名称中将key删除
|
|
530
|
+
|
|
531
|
+
name,名
|
|
532
|
+
|
|
533
|
+
key,键
|
|
534
|
+
"""
|
|
535
|
+
i=0
|
|
536
|
+
while True:
|
|
537
|
+
self.__connects()
|
|
538
|
+
try:
|
|
539
|
+
status=self.__redisObj.hdel(name,key)
|
|
540
|
+
except Exception as e:
|
|
541
|
+
stre=str(e)
|
|
542
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
543
|
+
i+=1
|
|
544
|
+
self.close(pattern=True)
|
|
545
|
+
if i>3:
|
|
546
|
+
raise Exception(e)
|
|
547
|
+
else:
|
|
548
|
+
print("__redisObj_e",e)
|
|
549
|
+
raise Exception(e)
|
|
550
|
+
else:
|
|
551
|
+
self.close()
|
|
552
|
+
break
|
|
553
|
+
return status
|
|
554
|
+
def hmset(self,name,mapping,ex=0):
|
|
555
|
+
"""在hash的name中为每个键设置值
|
|
556
|
+
name,键
|
|
557
|
+
|
|
558
|
+
mapping,值
|
|
559
|
+
|
|
560
|
+
ex,过期时间(秒)
|
|
561
|
+
|
|
562
|
+
"""
|
|
563
|
+
i=0
|
|
564
|
+
while True:
|
|
565
|
+
self.__connects()
|
|
566
|
+
try:
|
|
567
|
+
status=self.__redisObj.hmget(name, keys, *args)
|
|
568
|
+
except Exception as e:
|
|
569
|
+
stre=str(e)
|
|
570
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
571
|
+
i+=1
|
|
572
|
+
self.close(pattern=True)
|
|
573
|
+
if i>3:
|
|
574
|
+
raise Exception(e)
|
|
575
|
+
else:
|
|
576
|
+
print("__redisObj_e",e)
|
|
577
|
+
raise Exception(e)
|
|
578
|
+
else:
|
|
579
|
+
if not ex:
|
|
580
|
+
if self.__config['ex']:
|
|
581
|
+
ex=self.__config['ex']
|
|
582
|
+
if ex:
|
|
583
|
+
self.__redisObj.expire(name,ex)
|
|
584
|
+
self.close()
|
|
585
|
+
break
|
|
586
|
+
return status
|
|
587
|
+
def hmget(self,name, keys, *args):
|
|
588
|
+
"返回与“keys”顺序相同的值列表``"
|
|
589
|
+
i=0
|
|
590
|
+
while True:
|
|
591
|
+
self.__connects()
|
|
592
|
+
try:
|
|
593
|
+
status=self.__redisObj.hmget(name, keys, *args)
|
|
594
|
+
except Exception as e:
|
|
595
|
+
stre=str(e)
|
|
596
|
+
if 'Error while reading from socket' in stre or 'Error 10054 while writing to socket' in stre or 'Connection timed out' in stre:
|
|
597
|
+
i+=1
|
|
598
|
+
self.close(pattern=True)
|
|
599
|
+
if i>3:
|
|
600
|
+
raise Exception(e)
|
|
601
|
+
else:
|
|
602
|
+
print("__redisObj_e",e)
|
|
603
|
+
raise Exception(e)
|
|
604
|
+
else:
|
|
605
|
+
self.close()
|
|
606
|
+
break
|
|
607
|
+
return status
|
|
608
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 1.2
|
|
2
|
+
Name: kcwredis
|
|
3
|
+
Version: 1.3
|
|
4
|
+
Summary: kcwcache
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: 百里
|
|
7
|
+
Author-email: kcwebs@kwebapp.cn
|
|
8
|
+
Maintainer: 坤坤
|
|
9
|
+
Maintainer-email: fk1402936534@qq.com
|
|
10
|
+
License: MIT License
|
|
11
|
+
Description: UNKNOWN
|
|
12
|
+
Keywords: kcwredis1.3
|
|
13
|
+
Platform: UNKNOWN
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
redis==3.3.8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kcwredis
|
kcwredis-1.3/setup.cfg
ADDED
kcwredis-1.3/setup.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
# 打包上传 python setup.py sdist upload
|
|
3
|
+
# 打包并安装 python setup.py sdist install
|
|
4
|
+
# twine upload --repository-url https://test.pypi.org/legacy/ dist/* #上传到测试
|
|
5
|
+
# pip install --index-url https://pypi.org/simple/ kcwebs #安装测试服务上的kcwebs pip3 install kcwebs==4.12.4 -i https://pypi.org/simple/
|
|
6
|
+
# 安装 python setup.py install
|
|
7
|
+
############################################# pip3.8 install kcwebs==6.4.15 -i https://pypi.org/simple
|
|
8
|
+
import os,sys
|
|
9
|
+
from setuptools import setup, find_packages,Extension
|
|
10
|
+
current_dir = os.path.abspath(os.path.dirname(__file__))
|
|
11
|
+
sys.path.insert(0, current_dir)
|
|
12
|
+
confkcws={}
|
|
13
|
+
confkcws['name']='kcwredis'
|
|
14
|
+
confkcws['version']='1.3'
|
|
15
|
+
confkcws['description']='kcwcache'
|
|
16
|
+
confkcws['long_description']=''
|
|
17
|
+
confkcws['license']='MIT License'
|
|
18
|
+
confkcws['url']=''
|
|
19
|
+
confkcws['author']='百里'
|
|
20
|
+
confkcws['author_email']='kcwebs@kwebapp.cn'
|
|
21
|
+
confkcws['maintainer']='坤坤'
|
|
22
|
+
confkcws['maintainer_email']='fk1402936534@qq.com'
|
|
23
|
+
def get_file(folder='./',lists=[]):
|
|
24
|
+
lis=os.listdir(folder)
|
|
25
|
+
for files in lis:
|
|
26
|
+
if not os.path.isfile(folder+"/"+files):
|
|
27
|
+
if files=='__pycache__' or files=='.git':
|
|
28
|
+
pass
|
|
29
|
+
else:
|
|
30
|
+
lists.append(folder+"/"+files)
|
|
31
|
+
get_file(folder+"/"+files,lists)
|
|
32
|
+
else:
|
|
33
|
+
pass
|
|
34
|
+
return lists
|
|
35
|
+
def start():
|
|
36
|
+
b=get_file("kcwredis",['kcwredis'])
|
|
37
|
+
setup(
|
|
38
|
+
name = confkcws["name"],
|
|
39
|
+
version = confkcws["version"],
|
|
40
|
+
keywords = "kcwredis"+confkcws['version'],
|
|
41
|
+
description = confkcws["description"],
|
|
42
|
+
long_description = confkcws["long_description"],
|
|
43
|
+
license = confkcws["license"],
|
|
44
|
+
author = confkcws["author"],
|
|
45
|
+
author_email = confkcws["author_email"],
|
|
46
|
+
maintainer = confkcws["maintainer"],
|
|
47
|
+
maintainer_email = confkcws["maintainer_email"],
|
|
48
|
+
url=confkcws['url'],
|
|
49
|
+
packages = b,
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
install_requires = ['redis==3.3.8'], #第三方包
|
|
53
|
+
package_data = {
|
|
54
|
+
'': ['*.html', '*.js','*.css','*.jpg','*.png','*.gif'],
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
start()
|