Casey
Casey

Reputation: 2719

Append number to list in Redis

Let's say I have the following result in Redis:

GET YEARS

[2010, 2011, 2012, 2013]

How can I add a another year to this list? I tried RPUSH and SADD but they are not working.

Upvotes: 1

Views: 2589

Answers (1)

sazzad
sazzad

Reputation: 6267

You are able to get the value of YEARS by GET command. This implies that it is saved as String data type. If you want to continue using String, you would have to

  1. get the String value (of YEARS)
  2. concatenate another year, and
  3. save the new String (in YEARS) by SET or similar command

Or, instead of String, you can use

  • List data type, where you would be able to add another year by a single RPUSH/LPUSH command
  • Set data type, where you would be able to add another year by a single SADD command

Upvotes: 1

Related Questions