Skip to content

Using RedisTemplate executePipelined, rightPushAll and lRange behavior #3123

Closed as not planned
@gary258796

Description

@gary258796

I'm using rightPushAll inside executePipelined like below to put List data into redis list,


        List<Row> rows = getRows();

        redisTemplate.executePipelined(new SessionCallback<Object>() {

            @Override
            public <K, V> Object execute(RedisOperations<K, V> operations) throws DataAccessException {

                RedisOperations<String, Row> customOps = (RedisOperations<String, Row>) operations;

                customOps.opsForList().rightPushAll(kxy, rows);

                customOps.expire(kxy, taskCacheExpireDuration);

                return null;

            }

        }, redisTemplate.getDefaultSerializer());

And for the code using range to get list data from redis


        RedisSerializer<String> kxySerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer();

        List<Object> rows = redisTemplate.executePipelined((RedisCallback<List<Object>>) connection -> {

            connection.listCommands().lRange(kxySerializer.serialize(kxy), startIndex, endIndex - 1);

            return null;

        });

        if (CollectionUtils.isEmpty(rows)) {
            return Collections.emptyList();
        }

        return (List<DataGridRow>) rows.get(0);

The above code work nicely, but i notice that instead of storing the elements individually as List<Object, Object, Object, ...>, Redis stored the entire list as a single element, resulting in List<List>.

I ran some tests and confirmed that whether I use executePipelined or not, the command rightPushAll(kxy, rows) produces the same result. However, if I use rightPushAll(kxy, rows.toArray()), the result turns out as expected, something like List<Object, Object, Object, ...>.

Additionally, when retrieving data from the list using range without executePipelined, it fails to fetch the data correctly. But with executePipelined, it retrieves the data as expected. Since all the inserted data is stored within a single element, the retrieved data structure is List<List>.

Is the above behavior expected, or did I make a mistake in how I used it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions