TDV Adapter for Redis

Build 22.0.8462

Freeform Querying of Redis Keys

The most direct way to work with Redis data with the adapter is to use a Redis key as a table name. Below you will find sample data, queries, and results based on Redis data types.

Note: This page contains redis-cli syntax. Use either your own instance of redis-cli or the RunCommand procedure to send queries from the adapter to the Redis server for direct execution.

Redis Strings

Create a string in Redis:

> set mykey somevalue
OK
If you perform a SELECT query on mykey the adapter will return the following:

SELECT * FROM mykey

RedisKey ValueIndex Value RedisType ValueScore
mykey 1 somevalue String NULL

Redis Lists

Create a list in Redis:

> rpush mylist A B C
(integer) 3
If you perform a SELECT query on mylist the adapter will return the following:

SELECT * FROM mylist

RedisKey ValueIndex Value RedisType ValueScore
mylist 1 A List NULL
mylist 2 B List NULL
mylist 3 C List NULL

Deleting Redis Lists

List type records can also be removed using DELETE statements, though they must be performed by specifying the Value column in the WHERE clause:

DELETE FROM Keys WHERE Value = 'myvalue' AND RedisKey = 'mylist'

Note that using ValueIndex in the WHERE clause of the DELETE statement is not supported.

Redis Sets

Create a set in Redis:

> sadd myset 1 2 3
(integer) 3
If you perform a SELECT query on myset the adapter will return the following (note that Redis can return the elements of a set in any order):

SELECT * FROM myset

RedisKey ValueIndex Value RedisType ValueScore
myset 1 2 Set NULL
myset 2 1 Set NULL
myset 3 3 Set NULL

Redis Sorted Sets

Create a ZSet (sorted set) in Redis:

> zadd hackers 1940 "Alan Kay" 1957 "Sophie Wilson" 1953 "Richard Stallman" 1949 "Anita Borg"
(integer) 9
If you perform a SELECT query on hackers the adapter will return the following:

SELECT * FROM hackers

RedisKey ValueIndex Value RedisType ValueScore
hackers 1 Alan Kay ZSet 1940
hackers 2 Anita Borg ZSet 1949
hackers 3 Richard Stallman ZSet 1953
hackers 4 Sophie Wilson ZSet 1957

Redis Hashes

Create a hash in Redis:

> hmset user:1000 username antirez birthyear 1977 verified 1
OK
If you perform a SELECT query on user:1000 the adapter will return the following:

SELECT * FROM user:1000

RedisKey ValueIndex Value RedisType ValueScore
user:1000 username antirez Hash NULL
user:1000 birthyear 1977 Hash NULL
user:1000 verified 1 Hash NULL

Querying Key Patterns as Tables

You can retrieve multiple Redis keys at once by using a pattern (e.g., "user:*") as a table name. For example, start by adding several keys to Redis that match a pattern:

> hmset user:1000 name "John Smith" email "john.smith@example.com" password "s3cret"
OK
> hmset user:1001 name "Mary Jones" password "hidden" email "mjones@example.com"
OK

If you use user:* as the table name, the adapter will retrieve all Redis key-value pairs whose keys match the pattern. You can see the expected results below:

SELECT * FROM [user:*]

RedisKey ValueIndex Value RedisType ValueScore
user:1000 name John Smith Hash NULL
user:1000 email john.smith@example.com Hash NULL
user:1000 password s3cret Hash NULL
user:1001 name Mary Jones Hash NULL
user:1001 email mjones@example.com Hash NULL
user:1001 password hidden Hash NULL

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462