python脚本往redis加数据

#-*-coding:utf-8-*-
from rediscluster import StrictRedisCluster
import pymysql
import time
import cProfile
import timeit

def get_redis_connection():
rc = StrictRedisCluster(startup_nodes=[{'host':'10.101.32.97', 'port':1633}, {'host': '10.101.32.95', 'port':1633}, {'host': '10.101.32.96', 'port': 1633}],decode_responses=True)
return rc

def get_redis_value(command):
rc = get_redis_connection()
# Sspent = showCnt = Cspent = clickCnt = 0
allAppStoreSpent = allCashSpent = 0
for key in rc.scan_iter(match = command):
print(key)
re = rc.hgetall(key)
if 'cashSpent' in re:
i = int(re['cashSpent'])
allCashSpent = i + allCashSpent
elif 'appStoreDiscountSpent' in re:
x = int(re['appStoreDiscountSpent'])
allAppStoreSpent = x + allAppStoreSpent
else:
return False
return "allCashSpent: " + str(allCashSpent), "allAppStoreSpent: " + str(allAppStoreSpent)


if __name__ == "__main__":
valueN = get_redis_value('billing:advertiser:spent:????????????????????')
print(valueN)

#-*-coding:utf-8-*-
from rediscluster import StrictRedisCluster
import pymysql
import time
import cProfile
import timeit

def get_redis_connection():
rc = StrictRedisCluster(startup_nodes=[{'host':'10.101.82.101', 'port':6379}, {'host': '10.101.81.25', 'port':6379}, {'host': '10.101.82.31', 'port': 6379}],decode_responses=True)
return rc

def get_redis_value():
rc1 = get_redis_connection()
count = 1
while (count < 2):
#key="DL:1:8765432100000" + str(count) +":com.athinkthings.note.android.phone"
key="DL:IMEI:87654321000000" + str(count) +":com.athinkthings.note.android.phone"
rc1.hset(key, "creativeId", "20004641")
rc1.hset(key, "serviceTime", "1571194801000")
print ('The count is:', count)
count = count + 1


if __name__ == "__main__":
valueN = get_redis_value()
print(valueN)

猜你喜欢

转载自www.cnblogs.com/pshik/p/11692154.html