Skip to content

A redis lua script to move an item forwards or backwards in a list

Notifications You must be signed in to change notification settings

stereosteve/redis-moveby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

redis-moveby

This is a redis lua script to move an item forwards or backwards in a list.

A sorted set may be a better solution to this problem, so you should consider using a sorted set before using this. I have not used this in production, so beware.

Usage

Call this script with one key and two arguments:

  • The list key
  • The item you wish to move
  • The number of positions you wish to move (positive or negative)

The script returns the index of the item AFTER the move (with zero based indexing). Calling LINDEX with the return value would give you the item.

Examples

test.sh provdes an example usage. Run it with a day name and a number:

./test.sh friday -2 produces:

1) "monday"
2) "tuesday"
3) "friday"
4) "wednesday"
5) "thursday"
6) "saturday"
7) "sunday"

See Also

About

A redis lua script to move an item forwards or backwards in a list

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published