-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from pharvinee-noi/feature/get-redis-sentinel-…
…master Update RedisLibraryKeywords.py
- Loading branch information
Showing
1 changed file
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,37 @@ | |
from robot.api import logger | ||
from robot.api.deco import keyword | ||
import redis | ||
from redis.sentinel import Sentinel | ||
|
||
__author__ = 'Traitanit Huangsri' | ||
__email__ = '[email protected]' | ||
|
||
|
||
class RedisLibraryKeywords(object): | ||
|
||
@keyword('Get Redis Master') | ||
def get_redis_master(self, redis_host, redis_port=26379, service_name=None): | ||
"""Get from the Redis master's address corresponding. | ||
Arguments: | ||
- redis_host: hostname or IP address of the Redis server. | ||
- redis_port: Redis port number (default=6379) | ||
- service_name: Redis master's address corresponding | ||
Return sentinel detail lists | ||
Examples: | ||
| @{sentinel_detail}= | Get Redis Master | 'redis-dev.com' | 6379 | 'service-name' | | ||
""" | ||
try: | ||
sentinel = Sentinel([(redis_host, redis_port)], socket_timeout=0.1) | ||
sentinel_detail = sentinel.discover_master(service_name) | ||
|
||
except Exception as ex: | ||
logger.error(str(ex)) | ||
raise Exception(str(ex)) | ||
return sentinel_detail | ||
|
||
@keyword('Connect To Redis') | ||
def connect_to_redis(self, redis_host, redis_port=6379, db=0, redis_password=None, ssl=False, ssl_ca_certs=None): | ||
"""Connect to the Redis server. | ||
|
@@ -196,7 +220,7 @@ def redis_key_should_not_be_exist(self, redis_conn, key): | |
| Redis Key Should Not Be Exist | ${redis_conn} | BARCODE|1234567890 | | ||
""" | ||
if redis_conn.exists(key): | ||
logger.error("Key: " + key +" exists in Redis.") | ||
logger.error("Key: " + key + " exists in Redis.") | ||
raise AssertionError | ||
|
||
@keyword('Get Dictionary From Redis Hash') | ||
|
@@ -534,6 +558,3 @@ def delete_item_from_list_redis(self, redis_conn, list_name, index, item=None): | |
raise AssertionError | ||
redis_conn.lset(list_name, index, 'DELETE_ITEM') | ||
redis_conn.lrem(list_name, 1, 'DELETE_ITEM') | ||
|
||
|
||
|