Skip to content
Data > Datasource Adapters

Redis

AMI supports connection to Redis data stores. Use AMI to send commands to and from a Redis data store for easy integration into your AMI dashboard.

This page contains information on connecting to and using Redis.

Setup

Requirements

  • Redis data store and connection details
  • Redis adapter

Please contact us at support@3forge.com to get the Redis adapter assigned to your 3forge account.

Setting up the Adapter

  1. Unzip the Redis files assigned to you from the client portal and add them to your AMI library in amione/lib.

  2. Add the following property to your datasource plugin adapter list in local.properties:

    ami.datasource.plugins=$${ami.datasource.plugins},com.f1.ami.plugins.redis.AmiRedisDatasourcePlugin
    
  3. Restart AMI. Redis should now be available under Dashboard -> Data Modeler -> Attach Datasource.

  4. Give your Redis Datasource a name and configure the URL. The URL should take the following format:

    URL: server_address:port_number
    

Redis Commands in AMI

AMI supports several Redis commands. For a full list of the accepted commands and their return-types in AMI, see the list below.

General Redis Command Format

The general structure of a Redis command is as follows:

COMMAND key [arguments...]

Where data is attributed to a given key and entries for that key are stored in a key-value pair structure. The key pattern naming convention is as follows:

<namespace>:<key> 

Example

To create a Redis hash with the key order:1:

HSET order:1 order_id 1 customer_id 101 status "Pending" amount 100.50
Field Value
order_id 1
customer_id 101
status Pending
amount 100.50

Accepted Redis Commands

Redis data is stored as strings. To ensure correct data processing, please be aware of the following:

  1. Almost every command accepts String as a valid return-type in AMI, but String is not iterable in AMI.
  2. Some return types depend on the inclusion of optional parameters.
  3. If a Redis command’s output is a number, then you may use a numeric data-type in AMI Web (int/float/double/byte/short/long).
  4. String ("OK") or numeric (1/0) means whatever is in the parentheses is the default response if the query executes without error.
  5. AMI redis adapter’s syntax is case insensitive.
  6. Arguments in square braces ([]) are optional.
  7. Arguments delimited by pipes (|) mean either/or option can be chosen.
Command Name Arguments Accepted AMI Return Types Description
APPEND key value
  • Numeric
  • String
  • Appends a string to the value of a key
    AUTH [username] password
  • String
  • Authenticates the connection
    BITCOUNT key [start end [BYTE | BIT]]
  • Numeric
  • String
  • Counts the number of set bits in a string
    BITOP operation destkey key [key ...]
  • Numeric
  • String
  • Performs bitwise operations. Operations are AND OR XOR NOT
    BITPOS key bit [start [end [BYTE | BIT]]]
  • Numeric
  • String
  • Finds the first set or clear bit in a string
    BLMOVE source destination LEFT | RIGHT LEFT | RIGHT timeout
  • String
  • Pops an element from a list, pushes it to another list and returns it
    BLPOP key [key ...] timeout
  • String
  • List
  • Removes and returns the first element in a list
    BRPOP key [key ...] timeout
  • String
  • List
  • Removes and returns the last element in a list
    BZPOPMAX key [key ...] timeout
  • String
  • List
  • Removes and returns the member with the highest score from one or more sorted sets
    BZPOPMIN key [key ...] timeout
  • String
  • List
  • Removes and returns the member with the lowest score from one or more sorted sets
    COPY source destination [DB destination-db] [REPLACE]
  • String (true/false)
  • Copies the value of a key to a new key
    DBSIZE
  • Numeric
  • String
  • Returns the number of keys in the currently-selected database
    DECR key
  • Numeric
  • String
  • Decrements the integer value of a key by one
    DECRBY key decrement
  • Numeric
  • String
  • Decrements the integer value of a key by the supplied decrement
    DEL key [key ...]
  • Numeric
  • String
  • (1/0)
    Deletes one or more keys
    DUMP key
  • String
  • Binary
  • Returns a serialized representation of the value stored at a key (logging will not display content, it will say "x bytes")
    ECHO message
  • String
  • Returns the given string
    EVAL script numkeys [key [key ...]] [arg [arg ...]]
  • Script dependent
  • Executes a server-side Lua script
    EXISTS key [key ...]
  • Numeric
  • String
  • Determines whether one or more keys exist
    EXPIRE key seconds [NX | XX | GT | LT]
  • Numeric
  • String
  • Sets the expiration time of a key in seconds
    EXPIREAT key unix-time-seconds [NX | XX | GT | LT]
  • Numeric
  • String
  • Sets the expiration time of a key to a Unix timestamp
    EXPIRETIME key
  • Numeric
  • String
  • Returns the expiration time of a key as a Unix timestamp
    FLUSHALL
  • String ("OK")
  • Removes all keys from all databases
    FLUSHDB [ASYNC | SYNC]
  • String ("OK")
  • Removes all keys from current database
    GEOADD key [NX | XX] [CH] longitude latitude member [longitude latitude member ...]
  • Numeric
  • String
  • Adds one or more members to a geospatial index
    GEODIST key member1 member2 [M | KM | FT | MI]
  • Numeric
  • String
  • Returns the distance between two members of a geospatial index
    GEOHASH key member [member ...]
  • String
  • List
  • Returns members from from a geospatial index as geohash strings
    GEOPOS key member [member ...]
  • String
  • List
  • Returns the longitude and latitude of members from a geospatial index
    GEOSEARCH key FROMMEMBER member | FROMLONLAT longitude latitude BYRADIUS radius M | KM | FT | MI | BYBOX width height M | KM | FT | MI [ASC | DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST] [WITHHASH]
  • List
  • String
  • Queries a geospatial index for members inside an area of a box or a circle
    GEOSEARCHSTORE destination source FROMMEMBER member | FROMLONLAT longitude latitude BYRADIUS radius M | KM | FT | MI | BYBOX width height M | KM | FT | MI [ASC | DESC] [COUNT count [ANY]] [STOREDIST]
  • Numeric
  • String
  • As geosearch but can optionally store the result
    GET key
  • Numeric (if number)
  • String
  • Returns the string value of a key
    GETDEL key
  • Numeric (if digits only)
  • String
  • Returns the string value of a key after deleting it
    GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST]
  • String
  • Integer
  • null
  • Returns the string value of a key after setting its expiration time
    GETRANGE key start end
  • Numeric (if numbers)
  • String
  • Returns a substring of the string stored at a key
    HDEL key field [field ...]
  • Numeric
  • String
  • Deletes one or more fields and their values from a hash. Deletes the hash if no fields remain
    HEXISTS key field
  • String ("true"/"false")
  • Determines whether a field exists in a hash
    HGET key field
  • Numeric (if digits)
  • String
  • Returns the value of a field in a hash
    HGETALL key
  • String
  • Map
  • Returns all fields and values in a hash
    HINCRBY key field increment
  • Numeric
  • String
  • Increments the integer value of a field in a hash by a number
    HINCRBYFLOAT key field increment
  • Numeric
  • String
  • Increments the floating point value of a field in a hash by a number
    HKEYS key
  • Set
  • String
  • Returns all fields in a hash
    HLEN key
  • Numeric
  • String
  • Returns the number of fields in a hash
    HMGET key field [field ...]
  • String
  • List
  • Returns the values of all fields in a hash
    HMSET key field value [field value ...]
  • String ("OK")
  • Sets the values of multiple fields
    HRANDFIELD key [count [WITHVALUES]]
  • List (if COUNT)
  • String (if no COUNT)
  • Returns one or more random fields from a hash
    HSCAN key cursor [MATCH pattern] [COUNT count]
  • List
  • String
  • Iterates over fields and values of a hash
    HSET key field value [field value ...]
  • Numeric
  • String
  • Creates or modifies the value of a field in a hash
    HSETNX key field value
  • Numeric
  • String
  • Sets the value of a field in a hash only when the field doesn't exist
    HSTRLEN key field
  • Numeric
  • String
  • Returns the length of the value of a field
    HVALS key
  • String
  • List
  • Returns all values in a hash
    INCR key
  • Numeric
  • String
  • Increments the integer value of a key by one
    INCRBY key increment
  • Numeric
  • String
  • Increments the integer value of a key by a number
    INCRBYFLOAT key increment
  • Numeric
  • String
  • Increments the floating point value of a key by a number
    INFO [section [section ...]]
  • String
  • Returns information and statistics about the server
    KEYS pattern
  • Set
  • String
  • Returns all key names that match a pattern
    LASTSAVE
  • Numeric
  • String
  • Returns the Unix timestamp of the last successful save to disk
    LCS key1 key2 [LEN] [IDX] [MINMATCHLEN len] [WITHMATCHLEN]
  • String (if no options)
  • Numeric/String (if LEN)
  • List/String (if IDX or WITHMATCHLEN)
  • Finds the longest common substring
    LINDEX key index
  • Numeric (if number)
  • String
  • Returns an element from a list by its index
    LINSERT key BEFORE | AFTER pivot element
  • String
  • Integer
  • Inserts an element before or after another element in a list
    LLEN key
  • String
  • Integer
  • Returns the length of a list
    LMOVE source destination LEFT | RIGHT LEFT | RIGHT
  • String
  • Numeric
  • Returns an element after popping it from one list and pushing it to another
    LMPOP numkeys key [key ...] LEFT | RIGHT [COUNT count]
  • List
  • String
  • Returns multiple elements from a list after removing them
    LPOP key [count]
  • String (without COUNT)
  • Numeric (if element is number)
  • List/String (with COUNT)
  • Returns the first elements in a list after removing it
    LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len]
  • List/String (with COUNT)
  • Numeric/String (without COUNT)
  • Returns the index of matching elements in a list
    LPUSH key element [element ...]
  • Numeric
  • String
  • Prepends one or more elements to a list
    LPUSHX key element [element ...]
  • Numeric
  • String
  • Prepends one or more elements to a list only when the list exists
    LRANGE key start stop
  • List
  • String
  • Returns a range of elements from a list
    LREM key count element
  • Numeric
  • String
  • Removes an element from a list
    LSET key index element
  • String ("OK")
  • Sets the value of an element in a list by its index
    LTRIM key start stop
  • String ("OK")
  • Removes elements from both ends of a list
    MGET key [key ...]
  • List
  • String
  • Automatically returns the string values of one or more keys
    MSETNX key value [key value ...]
  • Numeric
  • String
  • Automatically modifies the string values of one or more keys only when all keys don't exist
    PERSIST key
  • Numeric
  • String
  • Removes the expiration time of a key
    PEXPIRE key milliseconds [NX | XX | GT | LT]
  • Numeric
  • String
  • Sets the expiration time of a key in milliseconds
    PEXPIREAT key unix-time-milliseconds [NX | XX | GT | LT]
  • Numeric
  • String
  • Sets the expiration time of a key to a Unix milliseconds timestamp
    PEXPIRETIME key
  • Numeric
  • String
  • Returns the expiration time of a key as a Unix milliseconds timestamp
    PING [message]
  • Numeric (if numbers )
  • String
  • Returns the server's liveliness response
    RANDOMKEY
  • String
  • Numeric/String (if numbers)
  • Returns a random key name from the database
    RENAME key newkey
  • String ("OK")
  • Renames a key and overwrites the destination
    RENAMENX key newkey
  • Numeric (1/0)
  • Renames a key only when the target key name doesn't exist
    RESTORE key ttl serialized-value \[REPLACE\] \[ABSTTL\] \[IDLETIME seconds\] \[FREQ frequency\]
  • String ("OK")
  • Creates a key from the serialized representation of the value.
    Serialized values work differently in AMI because we do not have a base 32 binary string. Example usage:
    • execute set a 1;
    • Binary b = execute dump a;
    • string s = execute RESTORE a 16597119999999 "\${binaryToStr16(b)}" replace absttl;
    • string res = execute get a;
    • session.log(res);
    RPOP key [count]
  • Numeric/String (without COUNT)
  • List/String (with COUNT)
  • Returns and removes the last elements of a list
    RPUSH key element [element ...]
  • Numeric
  • String
  • Appends one or more elements to a list
    RPUSHX key element [element ...]
  • Numeric
  • String
  • Appends one or more elements to a list only if the list exists
    SADD key member [member ...]
  • Numeric
  • Adds one or more members to a set
    SAVE
  • String ("OK")
  • Synchronously saves the database(s) to disk
    SCAN cursor [MATCH pattern] [COUNT count] [TYPE type]
  • List
  • String
  • Iterates over the key names in the database
    SCARD key
  • Numeric
  • String
  • Returns the number of members in a set
    SDIFF key [key ...]
  • String
  • List
  • Returns the difference of multiple sets
    SDIFFSTORE destination key [key ...]
  • Numeric
  • String
  • Stores the difference of multiple sets in a key
    SET key value [NX | XX] [GET] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL]
  • String ("OK")
  • Sets the string valeue of a key, ignoring its type
    SETBIT key offset value
  • Numeric
  • String (1/0)
  • Sets or clears the bit at offset of the string value
    SETEX key seconds value
  • String ("OK")
  • Sets the string value and expiration time of a key
    SETNX key value
  • Numeric (0/1)
  • Sets the string value of a key only if the key doesn't already exist
    SETRANGE key offset value
  • Numeric
  • String
  • Overwrites a part of a string value with another by an offset
    SINTER key [key ...]
  • Set
  • String
  • Returns the intersect of multiple sets
    SINTERCARD numkeys key [key ...] [LIMIT limit]
  • Numeric
  • String
  • Returns the number of members of the intersect of multiple sets
    SINTERSTORE destination key [key ...]
  • Numeric
  • String
  • Stores the intersect of multiple sets in a key
    SISMEMBER key member
  • String (true/false)
  • Determines whether a member belongs to a set
    SMEMBERS key
  • Set
  • String
  • Returns all members of a set
    SMISMEMBER key member [member ...]
  • List
  • String
  • Determines whether multiple members belong to a set
    SMOVE source destination member
  • Numeric
  • Moves a member from one set to another
    SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC | DESC] [ALPHA] [STORE destination]
  • List/String (without STORE)
  • Numeric (with STORE)
  • Sorts the elements in a list, set, or sorted set, optionally storing the result
    SORT_RO key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC | DESC] [ALPHA]
  • List
  • String
  • Returns the sorted elements of a list, set, or sorted set
    SPOP key [count]
  • Set/String (with COUNT)
  • Numeric/String (without COUNT)
  • Returns one or more random members from a set after removing them
    SRANDMEMBER key [count]
  • List
  • String
  • Get one or multiple random members from a set
    SREM key member [member ...]
  • Numeric
  • String
  • Removes one or more members from a set
    SSCAN key cursor [MATCH pattern] [COUNT count]
  • List
  • String
  • Iterates over members of a set
    STRLEN key
  • Numeric
  • String
  • Returns the length of a string value
    SUBSTR key start end
  • String
  • Returns a substring from a string value
    SUNION key [key ...]
  • Set
  • String
  • Returns the union of multiple sets
    SUNIONSTORE destination key [key ...]
  • Numeric
  • String
  • Stores the union of multiple sets in a key
    TIME
  • List
  • String
  • Returns the server time
    TOUCH key [key ...]
  • Numeric
  • String
  • Returns the number of existing keys out of those specified after udpating the time they were last accessed
    TTL key
  • Numeric
  • String
  • Returns the expiration time in seconds of a key
    TYPE key
  • String
  • Determines the type of value stored at a key
    UNLINK key
  • Numeric
  • String
  • Asynchronously deletes one or more keys
    ZADD key [NX | XX] [GT | LT] [CH] [INCR] score member [score member ...]
  • Numeric
  • String
  • Adds one or more members to a sorted set or updates their scores
    ZCARD key
  • Numeric
  • String
  • Returns the number of members in a sorted set
    ZCOUNT key min max
  • Numeric
  • String
  • Returns the count of members in a sorted set that have scores within a range
    ZDIFF numkeys key [key ...] [WITHSCORES]
  • Set
  • String
  • Returns the difference between multiple sorted sets
    ZDIFFSTORE destination numkeys key [key ...]
  • Numeric
  • String
  • Stores the difference of multiple sorted sets in a key
    ZINCRBY key increment member
  • Numeric
  • String
  • Increments the score of a member in a sorted set
    ZINTER numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX] [WITHSCORES]
  • List/String (with WITHSCORES)
  • Set/String (without WITHSCORES)
  • Returns the intersect of multiple sorted sets
    ZINTERCARD numkeys key [key ...] [LIMIT limit]
  • Numeric
  • String
  • Returns the number of members of the intersect of multiple sorted sets
    ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX]
  • Numeric
  • String
  • Stores the intersect of multiple sorted sets in a key
    ZLEXCOUNT key min max
  • Numeric
  • Returns the number of members in a sorted set within a lexicographical range
    ZMPOP numkeys key [key ...] MIN | MAX [COUNT count]
  • List
  • String
  • Returns the highest or lowest scoring members from one or more sorted sets after removing them
    ZMSCORE key member [member ...]
  • List
  • String
  • Returns the score of one or more members in a sorted set
    ZPOPMAX key [count]
  • List
  • String
  • Returns the highest scoring members from a sorted set after removing them
    ZPOPMIN key [count]
  • List
  • String
  • Returns the lowest scoring members from a sorted set after removing them
    ZRANDMEMBER key [count [WITHSCORES]]
  • List
  • String
  • Returns one or more random members from a sorted set
    ZRANGE key start stop [BYSCORE | BYLEX] [REV] [LIMIT offset count] [WITHSCORES]
  • Set
  • String
  • Returns members in a sorted set within a range of indexes
    ZRANGESTORE dst src min max [BYSCORE | BYLEX] [REV] [LIMIT offset count]
  • Numeric
  • String
  • Stores a range of members from a sorted set in a key
    ZRANK key member
  • String
  • Null
  • Returns the index of a member in a sorted set ordered by ascending scores
    ZREM key member [member ...]
  • Numeric
  • String
  • Removes one or more members from a sorted set
    ZREMRANGEBYLEX key min max
  • Numeric
  • String
  • Removes members in a sorted set within a lexicographical range
    ZREMRANGEBYRANK key start stop
  • Numeric
  • String
  • Removes members in a sorted set within a range of indexes
    ZREMRANGEBYSCORE key min max
  • Numeric
  • String
  • Removes members in a sorted set within a range of scores
    ZREVRANK key member
  • Numeric
  • String
  • Returns the index of a member in a sorted set ordered by descending scores
    ZSCAN key cursor [MATCH pattern] [COUNT count]
  • List
  • String
  • Iterates over members and scores of a sorted set
    ZSCORE key member
  • Numeric
  • String
  • Returns the score of a member in a sorted set
    ZUNION numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX] [WITHSCORES]
  • List
  • String
  • Returns the union of multiple sorted sets
    ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM | MIN | MAX]
  • Numeric
  • String
  • Stores the union of multiple sorted sets in a key

    For more information on a specific method, see its entry in the Redis commands documentation.

    Example: Building a Table in AMI from Redis Data

    Ensure that you have a Redis adapter configured as shown in the setup steps above.

    In this example, a Redis database is configured in AMI with the following hashed data:

    1
    2
    3
    4
    5
    HSET order:1 order_id 1 customer_id 101 status "Pending" amount 100.50
    HSET order:2 order_id 2 customer_id 102 status "Shipped" amount 59.99
    HSET order:3 order_id 3 customer_id 103 status "Delivered" amount 230.00
    HSET order:4 order_id 4 customer_id 104 status "Cancelled" amount 12.00
    HSET order:5 order_id 5 customer_id 105 status "Pending" amount 75.25
    

    To create a table with this data, navigate to the Data Modeler to create a new datamodel. In the onProcess() tab of the datamodel creation wizard:

    // 1. Create a new table with column names
    create table orders (order_id string, customer_id string, status string, amount string);
    
    // 2. Get all Redis keys matching order:*
    list keys = USE ds="redis" EXECUTE KEYS order:*;
    
    // 3. Loop through keys and build rows
    for (string key: keys) {
        map rowData = USE ds="redis" EXECUTE HGETALL ${key};
        insert into orders values (rowData.get("order_id"), rowData.get("customer_id"), rowData["status"], rowData["amount"]); //both java and python-like syntax work!
    }
    

    This does three things:

    1. creates an empty table with the correct headings corresponding to the Redis data: order_id, customer_id, status, and amount.
    2. retrieves the keys from the Redis database using a supported Redis command and stores it in an AMI-compatible data structure.
    3. populates the table with the Redis data based on the key.