"Python redis sample"의 두 판 사이의 차이
DB CAFE
(새 문서: 기타 python redis example 세모데 2017.03.26 17:24 댓글수0 공감수 0 # -*- coding:utf-8 -*- import sys, random, time from redis import Redis, exceptions, RedisError from...) |
|||
61번째 줄: | 61번째 줄: | ||
print "---------------------------------------------------" | print "---------------------------------------------------" | ||
print "[Time for writing]: ", time_elapsed_1, " sec., [Time for reading]: ", time_elapsed_2, " sec." | print "[Time for writing]: ", time_elapsed_1, " sec., [Time for reading]: ", time_elapsed_2, " sec." | ||
+ | [[Category:python]] |
2019년 12월 19일 (목) 20:35 기준 최신판
- DBA { Oracle DBA 명령어 > DBA 초급 과정 > DBA 고급 과정 }
- 튜닝 { 오라클 튜닝 목록 }
- 모델링 { 데이터 모델링 가이드 }
기타 python redis example 세모데 2017.03.26 17:24 댓글수0 공감수 0
- -*- coding:utf-8 -*-
import sys, random, time from redis import Redis, exceptions, RedisError from redis.sentinel import (Sentinel, SentinelConnectionPool,ConnectionError,
MasterNotFoundError, SlaveNotFoundError)
- Redis 접속 기본 설정값
listSentinel = [('10.0.10.1', 26379), ('10.0.10.2', 26379), ('10.0.10.3', 26379), ('10.0.0.2', 26379)] strServiceName = 'stn-master' strRedisPass = '1234' nDB = 0
nMaxUser = 1000
sentinel = Sentinel(listSentinel, socket_timeout=0.1) try:
#sentinel.discover_master(strServiceName) # No need for this #sentinel.discover_slaves(strServiceName) master = sentinel.master_for(strServiceName, password=strRedisPass, db=nDB, socket_timeout=0.1) slave = sentinel.slave_for(strServiceName, password=strRedisPass, db=nDB, socket_timeout=0.1)
except MasterNotFoundError:
print 'Master not found or Sentinel instances not runnung' sys.exit()
except SlaveNotFoundError:
print 'Slave not found or Sentinel instances not runnung' sys.exit()
except ConnectionError:
print 'Connection Error. Check if Sentinel instances are running' sys.exit()
start_time = time.time()
for n in range(1, nMaxUser):
for m in range(1, random.randint(0, 5)): master.hset( "cart.user:"+str(n), random.randint(1, 300), random.randint(1, 5) )
time_elapsed_1 = time.time() - start_time
start_time = time.time()
for n in range(1, nMaxUser):
slave.hgetall("cart.user:"+str(n))
time_elapsed_2 = time.time() - start_time
count = 0
for n in range(1, nMaxUser):
data = slave.hgetall("cart.user:"+str(n)) if len(data) > 0: count = count + 1 print count, " [Cart.user:"+str(n)+"] ", data
print "---------------------------------------------------" print "[Time for writing]: ", time_elapsed_1, " sec., [Time for reading]: ", time_elapsed_2, " sec."