Skip to content

Deprecation warning by using redis.sadd with Redis 4.8.0 #700

Closed

Description

@martingregoire

Describe the bug

When using split with Redis 4.8.0 in our app, we see the following deprecation warning:

Redis#sadd will always return an Integer in Redis 5.0.0. Use Redis#sadd? instead.

Expected behavior

There should be no deprecation warning.

Additional context

Please see https://github.com/redis/redis-rb/blob/4.x/CHANGELOG.md#480

As far as I see in the code, redis.sadd is only called here:

def add_to_set(set_name, value)
redis.sadd(set_name, value)
end

The method add_to_set is only called from:

def persist_experiment_configuration
redis_interface.add_to_set(:experiments, name)
redis_interface.persist_list(name, @alternatives.map { |alt| { alt.name => alt.weight }.to_json })
goals_collection.save

Proposal

As the returned value from redis.sadd is not used, a fix could be to follow the suggestion from the warning and change add_to_set to use redis.sadd? instead of redis.sadd if available:

    def add_to_set(set_name, value)
      return redis.sadd?(set_name, value) if redis.respond_to?(:sadd?)

      redis.sadd(set_name, value)
    end

Activity

  1. andrehjr commented on Jan 12, 2023

    @andrehjr
    Member

    I think that's fair. Do you want to open an PR?

    sadd? is only available after redis 4.8.. and we're still on 4.2.

  2. martingregoire commented on Jan 13, 2023

    @martingregoire
    ContributorAuthor

    Yes, I'll try to take a look at the tests and then create a PR.

    Updating the Redis dependency to 4.8 might be too much, right? That's why I thought about adding the "use sadd? if available" logic.

  3. andrehjr commented on Jan 13, 2023

    @andrehjr
    Member

    For now, checking if sadd? is available is good enough.

    As 4.8 was released in August 22, bumping the dependency might be too soon. But it will happen at some point

  4. martingregoire commented on Jan 13, 2023

    @martingregoire
    ContributorAuthor

    Please have a look at the PR if your time permits. 🔧

  5. andrehjr commented on Jul 25, 2023

    @andrehjr
    Member

    Closed by #701

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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