0
0
Azurecloud~10 mins

Redis connection and basic commands in Azure - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Redis client connection using Azure SDK.

Azure
from azure.identity import DefaultAzureCredential
from azure.mgmt.redis import RedisManagementClient

credential = DefaultAzureCredential()
client = RedisManagementClient(credential, [1])
Drag options to blanks, or click blank then click option'
Asubscription_id
Bresource_group
Credis_name
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using resource group name instead of subscription ID.
Using Redis instance name instead of subscription ID.
2fill in blank
medium

Complete the code to retrieve the Redis cache keys from Azure.

Azure
keys = client.redis.list_keys([1], 'myRedisCache')
Drag options to blanks, or click blank then click option'
Asubscription_id
Bredis_cache_name
Cresource_group_name
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Passing subscription_id as first argument.
Passing Redis cache name as first argument.
3fill in blank
hard

Fix the error in the Redis command to set a key-value pair using redis-py client.

Azure
import redis

r = redis.Redis(host='myredis.redis.cache.windows.net', port=6380, ssl=True, password='[1]')
r.set('mykey', 'myvalue')
Drag options to blanks, or click blank then click option'
Aprimary_key
Baccess_key
Cconnection_string
Dendpoint
Attempts:
3 left
💡 Hint
Common Mistakes
Using connection string instead of key.
Using endpoint as password.
4fill in blank
hard

Fill both blanks to retrieve and decode a Redis key value.

Azure
value = r.get('mykey')
if value is not None:
    decoded_value = value[1][2]
Drag options to blanks, or click blank then click option'
A.decode
B('utf-8')
C('ascii')
D.encode
Attempts:
3 left
💡 Hint
Common Mistakes
Using encode instead of decode.
Using ascii encoding which may cause errors.
5fill in blank
hard

Fill all three blanks to delete a Redis key and check if deletion was successful.

Azure
deleted_count = r.delete([1])
if deleted_count [2] 1:
    print([3])
Drag options to blanks, or click blank then click option'
A'mykey'
B==
C'Key deleted successfully'
D'myvalue'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value instead of key name to delete.
Using assignment '=' instead of comparison '=='.