Skip to content

Script.Run() NOSCRIPT fallback not working in pipeline context #3228

Closed as not planned
@angus-langchain

Description

@angus-langchain

Expected Behavior

When using Script.Run() within a Redis pipeline/transaction, if a script hasn't been loaded (triggering NOSCRIPT), the method should automatically fall back to EVAL as it does in non-pipeline contexts. This is the documented behavior in the Run() method comment: "Run optimistically uses EVALSHA to run the script. If script does not exist it is retried using EVAL."

Current Behavior

When using Script.Run() within a pipeline/transaction, the NOSCRIPT fallback mechanism fails to work. The pipeline execution fails with "NOSCRIPT No matching script. Please use EVAL" instead of automatically falling back to EVAL.

Steps to Reproduce

  1. Create a new Redis client and flush existing scripts
  2. Create a pipeline
  3. Attempt to run a script using Script.Run() within the pipeline
  4. Execute the pipeline

Minimal reproduction:

package main

import (
    "context"
    "testing"
    
    "github.com/redis/go-redis/v9"
    "github.com/stretchr/testify/assert"
)

func TestScriptRunPipelineFallback(t *testing.T) {
	ctx := context.Background()
	client := redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
	})
	defer client.Close()

	err := client.ScriptFlush(ctx).Err()
	assert.NoError(t, err)

	script := redis.NewScript(`
        return ARGV[1]
    `)

	pipe := client.TxPipeline()

	script.Run(ctx, pipe, []string{}, "test_value")

	_, err = pipe.Exec(ctx)
	assert.NoError(t, err) // This fails with NOSCRIPT error
}

Context (Environment)

  • go-redis version: v9
  • Go version: 1.23.2

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