Package: redis-extensions-base
redis-extensions-baseRedis-extensions-base is a base collection of custom extensions for Redis-py.Installationpip install redis-extensions-baseUsageIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.zaddwithstamps('sorted_set',1,'a',2,'b')Out[3]:1In[4]:r.zrange('sorted_set',0,100,withscores=True)Out[4]:[('a',11472205032192.0),('b',21472205032192.0)]In[5]:r.zrange('sorted_set',0,100,withscores=True,score_cast_func=r.rawscore)Out[5]:[('a',1.0),('b',2.0)]In[6]:r.zincrbywithstamps('sorted_set','a')Out[6]:0In[7]:r.zrange('sorted_set',0,100,withscores=True)Out[7]:[('b',21472205032192.0),('a',21472205071514.0)]In[8]:r.zrange('sorted_set',0,100,withscores=True,score_cast_func=r.rawscore)Out[8]:[('b',2.0),('a',2.0)]ExpiredIn[1]:fromredis_extensionsimportRedisExpiresasexpIn[2]:exp.REDIS_EXPIREDexp.REDIS_EXPIRED_HALF_HOURexp.REDIS_EXPIRED_ONE_HOURexp.REDIS_EXPIRED_ONE_WEEKexp.REDIS_EXPIRED_ONE_DAYexp.REDIS_EXPIRED_ONE_MONTHexp.REDIS_EXPIRED_ONE_YEARIn[2]:exp.REDIS_EXPIRED_ONE_HOUROut[2]:3600In[3]:In[3]:importredis_extensionsasredisIn[4]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[5]:r.REDIS_EXPIREDr.REDIS_EXPIRED_HALF_HOURr.REDIS_EXPIRED_ONE_HOURr.REDIS_EXPIRED_ONE_WEEKr.REDIS_EXPIRED_ONE_DAYr.REDIS_EXPIRED_ONE_MONTHr.REDIS_EXPIRED_ONE_YEARIn[5]:r.REDIS_EXPIRED_ONE_HOUROut[5]:3600WarningsIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.delete_keys('redis_extensions')``r.keys()``used,maybeveryveryveryslowwhenkeys' amount very largeOut[3]:0In[4]:r.lock_exists('redis_extensions',regex=True)``r.keys()``used,maybeveryveryveryslowwhenkeys' amount very largeOut[4]:[]SolutionsLockIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.acquire_lock('redis_extensions')Out[3]:'026ad2a7-2b58-435f-8ba2-467458a687f1'In[4]:r.acquire_lock('redis_extensions')Out[4]:FalseIn[5]:r.release_lock('redis_extensions','026ad2a7-2b58-435f-8ba2-467458a687f1')Out[5]:TrueIn[6]:r.acquire_lock('redis_extensions',ex=10)Out[6]:'84f6b991-7c30-4210-947a-deb56bbc769a'In[7]:r.exists('redis:extensions:lock:redis_extensions')Out[7]:TrueIn[8]:# 10 Seconds LaterIn[9]:r.exists('redis:extensions:lock:redis_extensions')Out[9]:FalseQuotaIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.quota('redis_extensions',amount=1,time=10)Out[3]:FalseIn[4]:r.quota('redis_extensions',amount=1,time=10)Out[4]:TrueQuote/UnQuoteIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.quote('http://a.com')Out[3]:'6eb19fa3-9e26-457b-bb88-83ea5927ac29'In[4]:r.unquote('6eb19fa3-9e26-457b-bb88-83ea5927ac29')Out[4]:'http://a.com'TokenIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:phone='18888888888'In[4]:r.token(phone)Out[4]:'8bde88aa-71e9-4dea-846c-b1684a02b0f5'In[5]:r.token_exists(phone,'8bde88aa-71e9-4dea-846c-b1684a02b0f5')Out[5]:TrueIn[6]:r.token_delete(phone)Out[6]:1SigninIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.signin_status('redis_extensions')Out[3]:{'delta_days':10394,# Signin Interval, Check Duplicate Signin'signed_today':False,# Signed Today Or Not'signin_date':'1988-06-15',# Last Signin Date'signin_days':0,# Continuous Signin Days'signin_longest_days':0,# Longest Continuous Signin Days In History'signin_total_days':0}# Total Signin DaysIn[4]:r.signin('redis_extensions')Out[4]:{'delta_days':10394,'signed_today':True,'signin_date':'2016-11-29','signin_days':1,'signin_longest_days':1,'signin_total_days':1}In[5]:r.signin_status('redis_extensions')Out[5]:{'delta_days':0,'signed_today':True,u'signin_date':u'2016-11-29',u'signin_days':1,u'signin_longest_days':1,u'signin_total_days':1}In[6]:r.signin('redis_extensions')Out[6]:{'delta_days':0,# Duplicate Signin'signed_today':True,u'signin_date':u'2016-11-29',u'signin_days':1,u'signin_longest_days':1,u'signin_total_days':1}CounterIn[1]:importredis_extensionsasredisIn[2]:r=redis.RedisExtensions(host='localhost',port=6379,db=0)In[3]:r.counter('a')Out[3]:(1,0,1)# cur, pre, incrIn[4]:r._counter_key('a')Out[4]:'redis:extensions:counter:a:20170215'In[5]:r.ttl(_4)Out[5]:86390L