Skip to content

Commit

Permalink
Merge pull request #27 from pharvinee-noi/feature/get-redis-sentinel-…
Browse files Browse the repository at this point in the history
…master

Update RedisLibraryKeywords.py
  • Loading branch information
Panchorn authored Aug 18, 2021
2 parents b11dccb + a61fd91 commit 0c59cf9
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions RedisLibrary/RedisLibraryKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')



0 comments on commit 0c59cf9

Please sign in to comment.