1.2.1 • Published 6 months ago

ymlr-redis v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

ymlr-redis

ymlr-redis for ymlr plugin

Shares

Tag details

TagsDescription
ymlr-redisDeclare a redis connector
ymlr-redis'jobAdd a new job with input data to do async
ymlr-redis'onJobHandle jobs which is add by ymlr-redis'job
ymlr-redis'pubPublish a message to channels in redis
ymlr-redis'subSubscribe channels in redis

ymlr-redis

Declare a redis connector

Example:

  - name: "[redis] localhost"
    ymlr-redis:
      uri: redis://user:pass                  # redis uri
      runs:                                   # When a message is received then it will runs them
        - echo: redis is connected

Publish a message to channels

  - name: "[redis] localhost"
    ymlr-redis:
      uri: redis://user:pass                  # redis uri
      runs:                                   # When a message is received then it will runs them
        - name: Publish a message
          ymlr-redis'pub:
            channels:
              - test
            data:
              msg: Hello world

ymlr-redis'job

Add a new job with input data to do async

Example:

  - name: Crop image size
    ymlr-redis'job:
      uri: redis://user:pass
      opts:                               # ioredis options
      name: Crop Image                    # Queue name
      queueOpts:                          # Job queue options (https://docs.bullmq.io)
      jobOpts:                            # Job options (https://docs.bullmq.io)
        removeOnComplete: true
      data:                               # Job data
        url: http://...
        type: jpeg
        size:
          width: 10
          height: 10

Declare global then reused by code

  - name: Crop image size
    id: processImageJobsProxy
    detach: false                         # Dont release connection, keep it's used in background
    ymlr-redis'job:
      uri: redis://user:pass
      opts:                               # ioredis options
      name: Crop Image                    # Queue name
      queueOpts:                          # Job queue options (https://docs.bullmq.io)
      jobOpts:                            # Job options (https://docs.bullmq.io)
        removeOnComplete: true

  - js: |
      await $vars.processImageJobsProxy.$.add({
        url: 'http://...',
        type: 'jpeg',
        size: {
          width: 10,
          height: 10
        }
      }, {
        removeOnFail: true
      })

ymlr-redis'onJob

Handle jobs which is add by ymlr-redis'job

Example:

  - name: Handle to crop image size
    ymlr-redis'onJob:
      uri: redis://user:pass
      opts:                                 # ioredis options
        maxRetriesPerRequest:
      name: Crop Image                      # Queue name
      workerOpts:                           # Job worker options (https://docs.bullmq.io)
        concurrency: 1
      runs:
        - echo: A new job has justed added
        - echo: ${ $parentState.job }       # Job information
        - echo: ${ $parentState.job.data }  # Job data

ymlr-redis'pub

Publish a message to channels in redis

Example:

Publish a message to redis

  - name: "[redis] localhost"
    ymlr-redis'pub:
      uri: redis://user:pass
      channel: channel1
      channels:
        - channel2
        - channel3
      data:
        name: thanh

Reuse redis connection to publish multiple times

  - name: "[redis] localhost"
    ymlr-redis:
      uri: redis://user:pass
      runs:
        - ymlr-redis'pub:
            channels:
              - channel1
            data:
              name: thanh
        - ...
        # Other elements

Or reuse by global variable Reuse redis connection to publish multiple times

  - name: "[redis] localhost"
    ymlr-redis:
      uri: redis://user:pass
    vars:
      redis1: ${this}

  - ymlr-redis'pub:
      redis: ${ $vars.redis1 }
      channels:
        - channel1
      data:
        name: thanh

ymlr-redis'sub

Subscribe channels in redis

Example:

  - name: "[redis] localhost"
    ymlr-redis'sub:
      uri: redis://user:pass
      type: buffer                            # Message type is in [text, buffer]. Default is "text"
      channel: channel1
      channels:                               # channels which is subscribed
        - channel1
        - channel2
      runs:                                   # When a message is received then it will runs them
        - ${ $parentState }                   # - Received data in a channel
        - ${ $parentState.channelName }       # - channel name
        - ${ $parentState.channelData }       # - Received message which is cast to object
        - ${ $parentState.channelMsg }        # - Received message which is text

        - ...
        # Other elements

        - stop:

Used in global redis

  - name: Global Redis
    ymlr-redis:
      uri: redis://user:pass
      runs:
        - name: "[redis] localhost"
          ymlr-redis'sub:
            type: buffer                        # Message type is in [text, buffer]. Default is "text"
            channel: channel1
            channels:                           # channels which is subscribed
              - channel1
              - channel2
            runs:                               # When a message is received then it will runs them
              - ${ $parentState }               # - Received data in a channel
              - ${ $parentState.channelName }   # - Channel name
              - ${ $parentState.channelData }   # - Received message which is cast to object
              - ${ $parentState.channelMsg }    # - Received message which is text or buffer

              - ...
              # Other elements

Or reuse by global variable

  - id: redis
    name: Global Redis
    ymlr-redis:
      uri: redis://user:pass

  - name: "[redis] localhost"
    ymlr-redis'sub:
      redis: ${ $vars.redis }
      channel: channel1
      channels:                             # channels which is subscribed
        - channel1
        - channel2
      runs:                                 # When a message is received then it will runs them
        - ${ $parentState }                 # - Received data in a channel
        - ${ $parentState.channelName }     # - channel name
        - ${ $parentState.channelData }     # - Received message which is cast to object
        - ${ $parentState.channelMsg }      # - Received message which is text

        - ...
        # Other elements

        - stop:                             # - Stop subscribing

Have fun :)

1.1.8-alpha.1

6 months ago

1.2.1

6 months ago

1.2.1-alpha.0

6 months ago

1.1.7

8 months ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.0-alpha.0

1 year ago