Administrator
2024-05-20 e110671e3a2231fc6f16e5f4fba425416232f7ff
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
B
0óJf%ã@s¾dZddlZddlZddlZddlZddlmZddlmZm    Z    ddl
m Z m Z e j Zdd„edƒDƒZGd    d
„d
ƒZGd d „d ƒZed krºx$edƒD]Ze dde ¡d¡q–We ¡dS)u
redis管理器
éN)Úasync_log_util)Úlogger_redis_debugÚ logger_system)ÚconstantÚmiddle_api_protocolc
Cs.g|]&}tjtdtdtd|ddd‘qS)ÚhostÚportÚpwdTé2)rrÚpasswordÚdbÚdecode_responsesZmax_connections)ÚredisÚConnectionPoolÚconfig)Ú.0r ©rú2D:\workspace\trade_cb\db\redis_manager_delegate.pyú
<listcomp>sréc@s,eZdZedfdd„Zdd„Zdd„ZdS)    Ú RedisManagerr cCst||_||_dS)N)Ú pool_cachesÚpoolr )Úselfr rrrÚ__init__s
zRedisManager.__init__cCstj|jdS)N)Úconnection_pool)rÚRedisr)rrrrÚgetRedisszRedisManager.getRediscCs"tjtdtdtd|jddS)Nrrr    T)rrr r r )rrrr )rrrrÚgetRedisNoPoolszRedisManager.getRedisNoPoolN)Ú__name__Ú
__module__Ú __qualname__rrrrrrrrrsrc@s¾eZdZe ¡Zedd„ƒZedCdd„ƒZedd„ƒZ    edd    „ƒZ
edDd d „ƒZ edEd d„ƒZ edFdd„ƒZ edGdd„ƒZedHdd„ƒZedIdd„ƒZedJdd„ƒZedKdd„ƒZedLdd„ƒZedMdd„ƒZedNd d!„ƒZedOd"d#„ƒZedPd$d%„ƒZedQd&d'„ƒZedRd(d)„ƒZedSd*d+„ƒZedTd,d-„ƒZedUd.d/„ƒZedVd0d1„ƒZedWd2d3„ƒZedXd4d5„ƒZedYd6d7„ƒZ edZd8d9„ƒZ!ed:d;„ƒZ"ee#d<œd=d>„ƒZ$ed?d@„ƒZ%edAdB„ƒZ&dS)[Ú
RedisUtilscCst ¡}z|ƒSXdS)N)Útime)ÚclsÚ method_nameÚkeyZ lamada_methodZ_RedisUtils__start_timerrrÚexec%szRedisUtils.execNcCs4|||dœ}|dk    r||d<t |¡}t |¡}|S)N)r Úcmdr&Úargs)rZload_redis_cmdÚrequest)r$r r(r&r)ÚdataÚfdataÚresultrrrÚ    __request.s
 
zRedisUtils.__requestcCsdg}xF|D]>}|d|d|ddœ}|ddk    r>|d|d<| |¡q
Wt |¡}t |¡}|S)Nréé)r r(r&ér))ÚappendrZload_redis_cmdsr*)r$ZodatasZ_datasÚdr+r,ÚresultsrrrZ__batch__request<s
 
 
zRedisUtils.__batch__requestcCs |jjdS)Nr )rZconnection_kwargs)r$Úredis_rrrZ__get_dbLszRedisUtils.__get_dbTcsˆ dˆ‡‡‡fdd„¡S)NÚgetcsˆ ˆ ˆ¡dˆ¡S)Nr6)Ú_RedisUtils__requestÚ_RedisUtils__get_dbr)r$r&r5rrÚ<lambda>Róz RedisUtils.get.<locals>.<lambda>)r')r$r5r&Ú    auto_freer)r$r&r5rr6PszRedisUtils.getcsˆ dˆ‡‡‡fdd„¡S)NÚscardcsˆ ˆ ˆ¡dˆ¡S)Nr<)r7r8r)r$r&r5rrr9Vr:z"RedisUtils.scard.<locals>.<lambda>)r')r$r5r&r;r)r$r&r5rr<TszRedisUtils.scardFcsˆ dˆ‡‡‡fdd„¡S)NÚdeletecsˆ ˆ ˆ¡dˆ¡S)Nr=)r7r8r)r$r&r5rrr9Zr:z#RedisUtils.delete.<locals>.<lambda>)r')r$r5r&r;Ú_asyncr)r$r&r5rr=XszRedisUtils.deletecCs| |d|¡dS)Nr=)Úadd_async_task)r$r r&r;rrrÚ delete_async\szRedisUtils.delete_asynccs,t tdˆ›¡ˆ dˆ‡‡‡fdd„¡S)Nzkeys:Úkeyscsˆ ˆ ˆ¡dˆ¡S)NrA)r7r8r)r$r&r5rrr9dr:z!RedisUtils.keys.<locals>.<lambda>)rÚinforr')r$r5r&r;r)r$r&r5rrAaszRedisUtils.keyscsˆ dˆ‡‡‡‡fdd„¡S)NÚsetcsˆ ˆ ˆ¡dˆˆ¡S)NrC)r7r8r)r$r&r5Úvalrrr9hr:z RedisUtils.set.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrCfszRedisUtils.setcCs| |d||f¡dS)NrC)r?)r$r r&rDr;rrrÚ    set_asyncjszRedisUtils.set_asyncc    sˆ dˆ‡‡‡‡‡fdd„¡S)NÚsetexcsˆ ˆ ˆ¡dˆˆˆg¡S)NrF)r7r8r)r$Úexpirer&r5rDrrr9qr:z"RedisUtils.setex.<locals>.<lambda>)r')r$r5r&rGrDr;r>r)r$rGr&r5rDrrFoszRedisUtils.setexcCs| |d|||f¡dS)NrF)r?)r$r r&rGrDr;rrrÚ setex_asyncsszRedisUtils.setex_asynccsˆ dˆ‡‡‡‡fdd„¡S)NÚsetnxcsˆ ˆ ˆ¡dˆˆ¡S)NrI)r7r8r)r$r&r5rDrrr9zr:z"RedisUtils.setnx.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrIxszRedisUtils.setnxcsˆ dˆ‡‡‡‡fdd„¡S)NrGcsˆ ˆ ˆ¡dˆˆ¡S)NrG)r7r8r)r$rGr&r5rrr9~r:z#RedisUtils.expire.<locals>.<lambda>)r')r$r5r&rGr;r)r$rGr&r5rrG|szRedisUtils.expirecCs| |d||f¡dS)NrG)r?)r$r r&rGr;rrrÚ expire_async€szRedisUtils.expire_asynccsˆ dˆ‡‡‡‡fdd„¡S)NÚsaddcsˆ ˆ ˆ¡dˆˆ¡S)NrK)r7r8r)r$r&r5rDrrr9‡r:z!RedisUtils.sadd.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrK…szRedisUtils.saddcCs| |d||f¡dS)NrK)r?)r$r r&rDr;rrrÚ
sadd_async‰szRedisUtils.sadd_asynccsˆ dˆ‡‡‡‡fdd„¡S)NÚ    sismembercsˆ ˆ ˆ¡dˆˆ¡S)NrM)r7r8r)r$r&r5rDrrr9r:z&RedisUtils.sismember.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrMŽszRedisUtils.sismembercs2ˆ dˆ‡‡‡fdd„¡}t|ƒtkr.t|ƒ}|S)NÚsmemberscsˆ ˆ ˆ¡dˆ¡S)NrN)r7r8r)r$r&r5rrr9”r:z%RedisUtils.smembers.<locals>.<lambda>)r'ÚtypeÚlistrC)r$r5r&r;r-r)r$r&r5rrN’s zRedisUtils.smemberscsˆ dˆ‡‡‡‡fdd„¡S)NÚsremcsˆ ˆ ˆ¡dˆˆ¡S)NrQ)r7r8r)r$r&r5rDrrr9›r:z!RedisUtils.srem.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrQ™szRedisUtils.sremcCs| |d||f¡dS)NrQ)r?)r$r r&rDr;rrrÚ
srem_asyncszRedisUtils.srem_asynccsˆ dˆ‡‡‡‡fdd„¡S)NÚincrbycsˆ ˆ ˆ¡dˆˆ¡S)NrS)r7r8r)r$r&Únumr5rrr9¤r:z#RedisUtils.incrby.<locals>.<lambda>)r')r$r5r&rTr;r>r)r$r&rTr5rrS¢szRedisUtils.incrbycCs| |d||f¡dS)NrS)r?)r$r r&rTr;rrrÚ incrby_async¦szRedisUtils.incrby_asynccsˆ dˆ‡‡‡‡fdd„¡S)NÚlpushcsˆ ˆ ˆ¡dˆˆ¡S)NrV)r7r8r)r$r&r5rDrrr9­r:z"RedisUtils.lpush.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrV«szRedisUtils.lpushcsˆ dˆ‡‡‡fdd„¡S)NÚlpopcsˆ ˆ ˆ¡dˆ¡S)NrW)r7r8r)r$r&r5rrr9±r:z!RedisUtils.lpop.<locals>.<lambda>)r')r$r5r&r;r)r$r&r5rrW¯szRedisUtils.lpopcsˆ dˆ‡‡‡‡fdd„¡S)NÚrpushcsˆ ˆ ˆ¡dˆˆ¡S)NrX)r7r8r)r$r&r5rDrrr9µr:z"RedisUtils.rpush.<locals>.<lambda>)r')r$r5r&rDr;r)r$r&r5rDrrX³szRedisUtils.rpushcCsdS)Nr)r$r5rrrÚrealse·szRedisUtils.realse)r cCs|j |||f¡dS)N)Ú_RedisUtils__async_task_queueÚ
put_nowait)r$r Úmethodr)rrrr?»szRedisUtils.add_async_taskcCs
|j ¡S)N)rZÚqsize)r$rrrÚget_async_task_count¿szRedisUtils.get_async_task_countc
Cszt d¡t dt ¡›¡g}t ¡}xHy|j ¡}|r|d|dg}t|dƒtksrt|dƒt    kr¸| 
|dd¡t |dƒdkr¬| 
|ddd…¡qÐ| 
d¡n| 
|d¡| 
d¡| 
t|ƒ¡t |ƒdkrz|  |¡}t ¡}Wd|  ¡X|r@t ¡|dkr@|  |¡}t ¡}|  ¡Wq.tk
rp}zt |¡Wdd}~XYq.Xq.WdS)Nu启动Redis数据同步服务uredis çº¿ç¨‹ID:rr/r0éé)rrBÚtoolÚ get_thread_idr#rZr6rOÚtuplerPr2ÚlenÚ_RedisUtils__batch__requestÚclearÚ    ExceptionÚloggingÚ    exception)r$ZdataListZlast_upload_timer+Z    temp_datar4Úe1rrrÚrun_loopÄs:
 
  
 
 
 
 
zRedisUtils.run_loop)N)T)T)TF)T)T)T)T)TF)T)T)T)T)T)T)T)T)T)T)TF)T)T)T)T)'rr r!ÚqueueÚQueuerZÚ classmethodr'r7rer8r6r<r=r@rArCrErFrHrIrGrJrKrLrMrNrQrRrSrUrVrWrXrYÚintr?r^rkrrrrr""sr                                r"Ú__main__ézbuy_position_info-002547ió)Ú__doc__rhrlr#rZ
log_modulerÚlog_module.logrrÚutilsrrÚ REDIS_CONFIGrÚrangerrr"rÚirHraZ
get_expirerkrrrrÚ<module>s"  X